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

Make implicit type casts explicit #8836

Merged
merged 1 commit into from
Jul 13, 2021

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Jul 10, 2021

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.

@@ -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']
Copy link
Member Author

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;

Copy link
Member

@SenseException SenseException left a 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 👍

Comment on lines +3309 to +3319
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'];

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

No worries :)

lib/Doctrine/ORM/Query/Parser.php Show resolved Hide resolved
Comment on lines +3309 to +3319
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'];

Copy link
Member

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.

@greg0ire greg0ire added this to the 2.10.0 milestone Jul 13, 2021
@greg0ire greg0ire merged commit 5b6a1d7 into doctrine:2.10.x Jul 13, 2021
@greg0ire greg0ire deleted the explicit-type-casts branch July 13, 2021 21:53
@greg0ire greg0ire mentioned this pull request Jul 14, 2021
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.

2 participants