Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: Remove dead condition in FlowAnnotationDriver #3263

Draft
wants to merge 1 commit into
base: 9.0
Choose a base branch
from

Conversation

mhsdesign
Copy link
Member

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 012f0e7, 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

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 neos@012f0e7, but it could never have worked as intended.

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

```php
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.
@kdambekalns
Copy link
Member

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 kdambekalns self-requested a review January 17, 2024 13:44
@bwaidelich bwaidelich removed their request for review January 17, 2024 14:41
@mhsdesign mhsdesign marked this pull request as draft April 2, 2024 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants