Skip to content

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Nov 8, 2022

This one comes with a controversial change that I did not have the courage to extract to a separate commit PR/commit (feel free to insist I do so): switching @readonly properties to native readonly. I had to tweak some tests to achieve that, and I've extracted that part in a separate commit, which I can backport if you think it should happen.

@@ -43,6 +43,9 @@
</NullableReturnStatement>
</file>
<file src="lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php">
<InvalidScalarArgument occurrences="1">
<code>$data</code>
</InvalidScalarArgument>
Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't seem to be an issue with Psalm v5: https://psalm.dev/r/6cd352a83c

@greg0ire greg0ire marked this pull request as ready for review November 8, 2022 21:47
Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

This one comes with a controversial change […]: switching @readonly properties to native readonly.

That was then plan after all. Good job. 🙂

I had to tweak some tests to achieve that, and I've extracted that part in a separate commit, which I can backport if you think it should happen.

I think that would be a good idea.

I think, Doctrine\ORM\Cache\CacheKey::$hash can also be declared as readonly. Can you have a look?

@@ -58,7 +58,7 @@ public function get(CacheKey $key): CacheEntry|null
public function getMultiple(CollectionCacheEntry $collection): array|null
{
$keys = array_map(
Closure::fromCallable([$this, 'getCacheEntryKey']),
Closure::fromCallable($this->getCacheEntryKey(...)),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Closure::fromCallable($this->getCacheEntryKey(...)),
$this->getCacheEntryKey(...),

@greg0ire
Copy link
Member Author

greg0ire commented Nov 8, 2022

I think, Doctrine\ORM\Cache\CacheKey::$hash can also be declared as readonly. Can you have a look?

There are a few more I missed, probably got distracted during my grep 😅

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 think, Doctrine\ORM\Cache\CacheKey::$hash can also be declared as readonly. Can you have a look?

I haven't done a deeper look into it, but does it make sense to introduce a constructor for the abstract class?

$generateKeys = static function ($id) use ($assocMetadata): EntityCacheKey {
return new EntityCacheKey($assocMetadata->rootEntityName, $id);
};
$generateKeys = static fn ($id): EntityCacheKey => new EntityCacheKey($assocMetadata->rootEntityName, $id);
Copy link
Member

Choose a reason for hiding this comment

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

The second argument of EntityCacheKey is an array.

Suggested change
$generateKeys = static fn ($id): EntityCacheKey => new EntityCacheKey($assocMetadata->rootEntityName, $id);
$generateKeys = static fn (array $id): EntityCacheKey => new EntityCacheKey($assocMetadata->rootEntityName, $id);

@greg0ire
Copy link
Member Author

greg0ire commented Nov 8, 2022

think, Doctrine\ORM\Cache\CacheKey::$hash can also be declared as readonly.

This causes ~300 errors and failures in the test suite, I don't think it's possible, and if it is, it should happen in another PR IMO.

@greg0ire
Copy link
Member Author

greg0ire commented Nov 8, 2022

I haven't done a deeper look into it, but does it make sense to introduce a constructor for the abstract class?

Ah maybe that's an easy way to fix it, yes 🤔

@greg0ire
Copy link
Member Author

greg0ire commented Nov 8, 2022

@SenseException that was it, thanks! I left out a few more instances of @readonly inside Parser.php, which is in another namespace, and looks a bit more involving.

@derrabus
Copy link
Member

derrabus commented Nov 8, 2022

think, Doctrine\ORM\Cache\CacheKey::$hash can also be declared as readonly.

This causes ~300 errors and failures in the test suite

Awesome. 🙈 Let's do this in a follow-up then.

@greg0ire
Copy link
Member Author

greg0ire commented Nov 8, 2022

Awesome. see_no_evil Let's do this in a follow-up then.

They all stemmed from the same 5 or so lines, after following @SenseException recommendation, they're gone 🙂

SenseException
SenseException previously approved these changes Nov 8, 2022
@derrabus derrabus added this to the 3.0.0 milestone Nov 8, 2022
derrabus
derrabus previously approved these changes Nov 8, 2022
@greg0ire greg0ire merged commit bfb9e16 into doctrine:3.0.x Nov 8, 2022
@greg0ire greg0ire deleted the php8-migration branch November 8, 2022 23:05
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.

3 participants