Skip to content

Commit f39621f

Browse files
Remove dead code and simplify redundant constructs
- remove the unused Doctrine FieldMapping imports left over from the DBAL 3/4 compatibility work - remove AdminContextFactory's duplicated getUser() call and the unused $request parameter of getDashboardDto() - remove the unused $entityDto parameter of CommonPreConfigurator::buildTemplatePathOption() - return expressions directly instead of assigning them to a variable used only once (SearchDto, MenuFactory, MenuItemMatcher, ComparisonType) - flatten the nested null/Stringable checks in CrudDto::getDefaultPageTitle() and use the nullsafe operator in AdminContextFactory
1 parent dab940d commit f39621f

12 files changed

Lines changed: 12 additions & 25 deletions

File tree

src/Dto/CrudDto.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,11 @@ public function setCustomPageTitle(string $pageName, TranslatableInterface|strin
231231
*/
232232
public function getDefaultPageTitle(?string $pageName = null, ?object $entityInstance = null, array $translationParameters = []): ?TranslatableInterface
233233
{
234-
if (null !== $entityInstance) {
235-
if ($entityInstance instanceof \Stringable) {
236-
$entityAsString = (string) $entityInstance;
234+
if ($entityInstance instanceof \Stringable) {
235+
$entityAsString = (string) $entityInstance;
237236

238-
if ('' !== $entityAsString) {
239-
return t($entityAsString, $translationParameters, 'EasyAdminBundle');
240-
}
237+
if ('' !== $entityAsString) {
238+
return t($entityAsString, $translationParameters, 'EasyAdminBundle');
241239
}
242240
}
243241

src/Dto/SearchDto.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ public function getQuery(): string
112112
public function getQueryTerms(): array
113113
{
114114
preg_match_all('/"(?:\\\\.|[^\\\\"])*"|\S+/', $this->query, $matches);
115-
$terms = array_map(static fn ($match) => trim($match, '" '), $matches[0]);
116115

117-
return $terms;
116+
return array_map(static fn ($match) => trim($match, '" '), $matches[0]);
118117
}
119118

120119
/**

src/Factory/AdminContextFactory.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ public function create(Request $request, DashboardControllerInterface $dashboard
5858
$validPageNames = [Crud::PAGE_INDEX, Crud::PAGE_DETAIL, Crud::PAGE_EDIT, Crud::PAGE_NEW];
5959
$pageName = \in_array($crudAction, $validPageNames, true) ? $crudAction : null;
6060

61-
$dashboardDto = $this->getDashboardDto($request, $dashboardController);
61+
$dashboardDto = $this->getDashboardDto($dashboardController);
6262
$assetDto = $this->getAssetDto($dashboardController, $crudController, $pageName);
6363
$filters = $this->getFilters($dashboardController, $crudController);
64-
$user = $this->getUser($this->tokenStorage);
6564

6665
// build a first version of CrudDto without actions so we can create AdminContext, which is
6766
// needed for action extensions; later, we'll update the CrudDto object with the full action config
@@ -105,7 +104,7 @@ public function create(Request $request, DashboardControllerInterface $dashboard
105104
return $adminContext;
106105
}
107106

108-
private function getDashboardDto(Request $request, DashboardControllerInterface $dashboardControllerInstance): DashboardDto
107+
private function getDashboardDto(DashboardControllerInterface $dashboardControllerInstance): DashboardDto
109108
{
110109
$dashboardRoutes = $this->adminRouteGenerator->getDashboardRoutes();
111110
$dashboardFqcn = $dashboardControllerInstance::class;
@@ -196,7 +195,7 @@ private function getI18nDto(Request $request, DashboardDto $dashboardDto, ?CrudD
196195
$translationParameters['%entity_id%'] = $entityId = EntityIdReader::fromRequest($request);
197196
$translationParameters['%entity_short_id%'] = null === $entityId ? null : u($entityId)->truncate(7)->toString();
198197

199-
$entityInstance = null === $entityDto ? null : $entityDto->getInstance();
198+
$entityInstance = $entityDto?->getInstance();
200199
$pageName = $crudDto->getCurrentPage();
201200

202201
$singularLabel = $crudDto->getEntityLabelInSingular($entityInstance, $pageName)

src/Factory/FieldFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace EasyCorp\Bundle\EasyAdminBundle\Factory;
44

55
use Doctrine\DBAL\Types\Types;
6-
use Doctrine\ORM\Mapping\FieldMapping;
76
use EasyCorp\Bundle\EasyAdminBundle\Collection\EntityCollection;
87
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
98
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;

src/Factory/FilterFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace EasyCorp\Bundle\EasyAdminBundle\Factory;
44

55
use Doctrine\DBAL\Types\Types;
6-
use Doctrine\ORM\Mapping\FieldMapping;
76
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
87
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
98
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Filter\FilterConfiguratorInterface;

src/Field/Configurator/CommonPreConfigurator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace EasyCorp\Bundle\EasyAdminBundle\Field\Configurator;
44

55
use Doctrine\DBAL\Types\Types;
6-
use Doctrine\ORM\Mapping\FieldMapping;
76
use Doctrine\ORM\Mapping\JoinColumnMapping;
87
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
98
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
@@ -73,7 +72,7 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
7372
$isVirtual = $this->buildVirtualOption($field, $entityDto);
7473
$field->setVirtual($isVirtual);
7574

76-
$templatePath = $this->buildTemplatePathOption($context, $field, $entityDto, $isReadable);
75+
$templatePath = $this->buildTemplatePathOption($context, $field, $isReadable);
7776
$field->setTemplatePath($templatePath);
7877

7978
$doctrineMetadata = [];
@@ -173,7 +172,7 @@ private function buildVirtualOption(FieldDto $field, EntityDto $entityDto): bool
173172
&& !$entityDto->getClassMetadata()->hasAssociation($field->getProperty());
174173
}
175174

176-
private function buildTemplatePathOption(AdminContext $adminContext, FieldDto $field, EntityDto $entityDto, bool $isReadable): string
175+
private function buildTemplatePathOption(AdminContext $adminContext, FieldDto $field, bool $isReadable): string
177176
{
178177
if (null !== $templatePath = $field->getTemplatePath()) {
179178
return $templatePath;

src/Field/Configurator/DateTimeConfigurator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace EasyCorp\Bundle\EasyAdminBundle\Field\Configurator;
44

55
use Doctrine\DBAL\Types\Types;
6-
use Doctrine\ORM\Mapping\FieldMapping;
76
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
87
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldConfiguratorInterface;
98
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Intl\IntlFormatterInterface;

src/Filter/Configurator/TextConfigurator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace EasyCorp\Bundle\EasyAdminBundle\Filter\Configurator;
44

55
use Doctrine\DBAL\Types\Types;
6-
use Doctrine\ORM\Mapping\FieldMapping;
76
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
87
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Filter\FilterConfiguratorInterface;
98
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;

src/Form/Type/ComparisonType.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function configureOptions(OptionsResolver $resolver): void
3131
'label' => false,
3232
'type' => 'numeric',
3333
'choices' => static function (Options $options) {
34-
$choices = match ($options['type']) {
34+
return match ($options['type']) {
3535
'numeric' => [
3636
'filter.label.is_equal_to' => self::EQ,
3737
'filter.label.is_not_equal_to' => self::NEQ,
@@ -69,8 +69,6 @@ public function configureOptions(OptionsResolver $resolver): void
6969
],
7070
default => [],
7171
};
72-
73-
return $choices;
7472
},
7573
'translation_domain' => 'EasyAdminBundle',
7674
]);

src/Orm/EntityRepository.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
66
use Doctrine\ORM\EntityManagerInterface;
77
use Doctrine\ORM\Mapping\ClassMetadata;
8-
use Doctrine\ORM\Mapping\FieldMapping;
98
use Doctrine\ORM\Query\Expr\Orx;
109
use Doctrine\ORM\QueryBuilder;
1110
use Doctrine\Persistence\ManagerRegistry;

0 commit comments

Comments
 (0)