Skip to content

Remove dead code and simplify redundant constructs#7709

Merged
javiereguiluz merged 1 commit into
EasyCorp:5.xfrom
guillaume-sainthillier:remove-dead-code-and-simplify
Jul 21, 2026
Merged

Remove dead code and simplify redundant constructs#7709
javiereguiluz merged 1 commit into
EasyCorp:5.xfrom
guillaume-sainthillier:remove-dead-code-and-simplify

Conversation

@guillaume-sainthillier

Copy link
Copy Markdown
Contributor
  • 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

- 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
@guillaume-sainthillier
guillaume-sainthillier force-pushed the remove-dead-code-and-simplify branch from 1265d05 to f39621f Compare July 13, 2026 07:33
@javiereguiluz
javiereguiluz merged commit e3300f1 into EasyCorp:5.x Jul 21, 2026
16 checks passed

@javiereguiluz javiereguiluz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Guillaume! Very nice changes 🙌

I reverted two minor changes, but loved the rest.

Comment thread src/Dto/SearchDto.php
$terms = array_map(static fn ($match) => trim($match, '" '), $matches[0]);

return $terms;
return array_map(static fn ($match) => trim($match, '" '), $matches[0]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted this change. In general, I dislike the "replace redundant local variable with a return" suggestions made by IDEs, etc.

It's true that the original $term variable is unneeded, but putting the entire expression in the return statement means that you can't easily know what are we returning here. You have to "compile the expression in your head" every time you read this code.

In some cases where the expressions are trivial, I'm OK with returning it directly without a local variable.

'type' => 'numeric',
'choices' => static function (Options $options) {
$choices = match ($options['type']) {
return match ($options['type']) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted this change too. The returned expression is simple ... but the code is so long, that it's hard to track where the return ends. That's why I think that the code is simpler to understand if we add the local variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants