Skip to content

Commit

Permalink
type guessing
Browse files Browse the repository at this point in the history
  • Loading branch information
prgTW committed Feb 16, 2024
1 parent b035900 commit 2239da8
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Builder/DatagridBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function addFilter(DatagridInterface $datagrid, $type = null, FieldDescri
if ($type == null) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());

$type = $guessType->getType();
$type = (null === $guessType) ? null : $guessType->getType();

$fieldDescription->setType($type);

Expand Down
2 changes: 1 addition & 1 deletion Builder/ListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function buildField($type = null, FieldDescriptionInterface $fieldDescrip
{
if ($type == null) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
$fieldDescription->setType($guessType->getType());
$fieldDescription->setType((null === $guessType) ? null : $guessType->getType());
} else {
$fieldDescription->setType($type);
}
Expand Down
2 changes: 1 addition & 1 deletion Builder/ShowBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function addField(FieldDescriptionCollection $list, $type = null, FieldDe
{
if ($type == null) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
$fieldDescription->setType($guessType->getType());
$fieldDescription->setType((null === $guessType) ? null : $guessType->getType());
} else {
$fieldDescription->setType($type);
}
Expand Down
4 changes: 4 additions & 0 deletions Guesser/AbstractTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function guessType($class, $property, ModelManagerInterface $modelManager
$guesser = new TypeGuesser();
$guessedType = $guesser->guessType($class, $property);

if (null === $guessedType) {
return null;
}

if ($guessedType->getType() === 'checkbox') {
return new TypeGuess('boolean', $guessedType->getOptions(), $guessedType->getConfidence());
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Builder/ListBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function testAddListActionField(): void
public function testCorrectFixedActionsFieldType(): void
{
$this->typeGuesser->expects($this->once())->method('guessType')
->willReturn(new TypeGuess(null, array(), Guess::LOW_CONFIDENCE));
->willReturn(null);
$this->admin->expects($this->atLeastOnce())->method('getModelManager')
->willReturn($this->modelManager);

Expand Down
2 changes: 1 addition & 1 deletion Tests/Builder/ShowBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testCantAddFieldWithoutType(): void
$this->typeGuesser
->expects($this->once())
->method('guessType')
->willReturn(new TypeGuess(null, [], TypeGuess::HIGH_CONFIDENCE));
->willReturn(null);

$builder = new ShowBuilder($this->typeGuesser);
$field = new FieldDescription();
Expand Down

0 comments on commit 2239da8

Please sign in to comment.