flow-development-collection icon indicating copy to clipboard operation
flow-development-collection copied to clipboard

TASK: Remove dead condition in `FlowAnnotationDriver`

Open mhsdesign opened this issue 1 year ago • 1 comments

phpStan rightfully complains in the FlowAnnotationDriver about this dead code.

We foreach over the $tableAnnotation->uniqueConstraints as $uniqueConstraint. But in Line 251 we reassign the variable $uniqueConstraint to ['columns' => $uniqueConstraint->columns]; and thus the check if (!empty($uniqueConstraint->options)) will always fail.

The code was introduced as fix via https://github.com/neos/flow-development-collection/commit/012f0e76a3169ed9b30b2dd23698718c4d550782, but it could never have worked as intended.

One can only guess but this might be the actual intention of the code.

foreach ($tableAnnotation->uniqueConstraints as $uniqueConstraint) {
    $someOtherVariableName = ['columns' => $uniqueConstraint->columns];
    if (!empty($uniqueConstraint->options)) {
        $someOtherVariableName['options'] = $uniqueConstraint->options;
    }
    if (!empty($uniqueConstraint->name)) {
        $primaryTable['uniqueConstraints'][$uniqueConstraint->name] = $someOtherVariableName;
    } else {
        $primaryTable['uniqueConstraints'][] = $someOtherVariableName;
    }
}

But as this behaviour is now untouched since Flow 2, it might be already functioning correctly - and thus the dead conditions were removed.

Upgrade instructions

Review instructions

Checklist

  • [ ] Code follows the PSR-2 coding style
  • [ ] Tests have been created, run and adjusted as needed
  • [ ] The PR is created against the lowest maintained branch
  • [ ] Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • [ ] Reviewer - The first section explains the change briefly for change-logs
  • [ ] Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

mhsdesign avatar Jan 17 '24 09:01 mhsdesign

I think it was not intended back then. The loop in line 150 uses as $indexAnnotation, but the loop in line 161 uses as $uniqueConstraint – if it had used …Annotation as well, it would have worked as intended, instead of overwriting itself, so to speak.

So, maybe fix it, instead of drop it?

kdambekalns avatar Jan 17 '24 13:01 kdambekalns