-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Make implicit type casts explicit #8836
Conversation
465e19c
to
e88d261
Compare
@@ -614,7 +614,7 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void | |||
|
|||
$sequenceGenerator = new SequenceGenerator( | |||
$this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->getTargetPlatform()), | |||
$definition['allocationSize'] | |||
(int) $definition['allocationSize'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the +
operator is used here, this must be fine:
$this->_maxValue = $this->_nextValue + $this->_allocationSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how the psalm and phpstan config became smaller 👍
if (! isset($definition['allocationSize']) || trim((string) $definition['allocationSize']) === '') { | ||
$definition['allocationSize'] = '1'; | ||
} | ||
|
||
if (! isset($definition['initialValue']) || trim($definition['initialValue']) === '') { | ||
if (! isset($definition['initialValue']) || trim((string) $definition['initialValue']) === '') { | ||
$definition['initialValue'] = '1'; | ||
} | ||
|
||
$definition['allocationSize'] = (string) $definition['allocationSize']; | ||
$definition['initialValue'] = (string) $definition['initialValue']; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make sense to use a variable here now so you need to cast only one time. It increases readability after the type casts were introduced or when changes are going to be introduced where the type casts are forgotten.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please show me how you would do it? It tried, and it's a bit too tricky IMO, since $definition['allocationSize']
might not be defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I confused keys during my review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries :)
if (! isset($definition['allocationSize']) || trim((string) $definition['allocationSize']) === '') { | ||
$definition['allocationSize'] = '1'; | ||
} | ||
|
||
if (! isset($definition['initialValue']) || trim($definition['initialValue']) === '') { | ||
if (! isset($definition['initialValue']) || trim((string) $definition['initialValue']) === '') { | ||
$definition['initialValue'] = '1'; | ||
} | ||
|
||
$definition['allocationSize'] = (string) $definition['allocationSize']; | ||
$definition['initialValue'] = (string) $definition['initialValue']; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I confused keys during my review.
Before we discuss what target branch the
strict_types
PR should use, here is a PR that makes 2.10.x compatible with strict types.Everything was pretty straightforward except the sequence generator which is full of casts from int to string and vice versa. After reading #6683 , it seems to me that we want to be compatible with sequences greater than PHP_INT_MAX, but I doubt we are in practice.
Note how this reduces the baseline.