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

How to create schema using Schema tool in v2.9.x? #8642

Closed
simPod opened this issue Apr 19, 2021 · 3 comments · Fixed by #8644
Closed

How to create schema using Schema tool in v2.9.x? #8642

simPod opened this issue Apr 19, 2021 · 3 comments · Fixed by #8644
Assignees
Milestone

Comments

@simPod
Copy link
Contributor

simPod commented Apr 19, 2021

SchemaTool::createSchema() expects list<Doctrine\ORM\Mapping\ClassMetadata>.

I used to pass in metadata created as $entityManager->getMetadataFactory()->getAllMetadata() that returns array<Doctrine\Persistence\Mapping> so it's incompatible now.

I checked this I but seems to have the same issue

$metadatas = $em->getMetadataFactory()->getAllMetadata();
if (empty($metadatas)) {
$ui->success('No Metadata Classes to process.');
return 0;
}
return $this->executeSchemaCommand($input, $output, new SchemaTool($em), $metadatas, $ui);

@greg0ire
Copy link
Member

greg0ire commented Apr 19, 2021

That was me in 7104489 , right? But the class metadata factory of the entity manager can only return Doctrine\ORM\Mapping\ClassMetadata, right?

I think something similar to

* @method Mapping\ClassMetadata getClassMetadata($className)
* @method Mapping\ClassMetadataFactory getMetadataFactory()
could be contributed to Doctrine\ORM\Mapping\ClassMetadataFactory to declare that getAllMetadata() in fact returns a list<Doctrine\ORM\Mapping\ClassMetadata>.

Can you try adding such a comment in that class to confirm that it does solve the issue?

UPD: the above has been contributed to 2.8.x, but is not yet merged up, so you would have to copy that too.

it's incompatible now.

According to PHP or PHPStan? I'm trying to determine if there is a BC-break here , e.g. is there a reasonable scenario where we would really pass non-instances Doctrine\ORM\Mapping\ClassMetadata.

@greg0ire greg0ire self-assigned this Apr 19, 2021
@greg0ire greg0ire added this to the 2.9.0 milestone Apr 19, 2021
@beberlei
Copy link
Member

Wouldn't AbstractClassMetadataFactory need to implement Psalm generics/template to make this possible?

@greg0ire
Copy link
Member

greg0ire commented Apr 19, 2021

I think it would be one way to do it, but there is I think another way to do this by using @method. And that one does not involve changing doctrine/persistence. A PR is on the way, and I think doing this @method trick will greatly reduce the baseline too :)

 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   Doctrine/ORM/Cache/DefaultCache.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$associationMappings\.$# in path
         /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Cache/DefaultCache.php was not matched in reported errors.
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$rootEntityName\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Cache/DefaultCache.php
         was not matched in reported errors.
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Ignored error pattern #^Parameter \#1 \$metadata of method Doctrine\\ORM\\Cache\\EntityHydrator\:\:buildCacheEntry\(\) expects Doctrine\\ORM\\Mapping\\ClassMetadata,
         Doctrine\\Persistence\\Mapping\\ClassMetadata given\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php was not matched in reported
         errors.
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$rootEntityName\.$# in path
         /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php was not matched in reported errors.
         Ignored error pattern #^Parameter \#1 \$metadata of method Doctrine\\ORM\\Cache\\EntityHydrator\:\:buildCacheEntry\(\) expects Doctrine\\ORM\\Mapping\\ClassMetadata,
         Doctrine\\Persistence\\Mapping\\ClassMetadata given\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php was not matched in reported errors.
         Ignored error pattern #^Parameter \#1 \$metadata of method Doctrine\\ORM\\Cache\\EntityHydrator\:\:loadCacheEntry\(\) expects Doctrine\\ORM\\Mapping\\ClassMetadata,
         Doctrine\\Persistence\\Mapping\\ClassMetadata given\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php was not matched in reported errors.
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$rootEntityName\.$# in path
         /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php was not matched in reported errors.
         Ignored error pattern #^Parameter \#1 \$metadata of method Doctrine\\ORM\\Cache\\EntityHydrator\:\:buildCacheEntry\(\) expects Doctrine\\ORM\\Mapping\\ClassMetadata,
         Doctrine\\Persistence\\Mapping\\ClassMetadata given\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php was not matched in
         reported errors.
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   Doctrine/ORM/EntityManager.php
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$identifier\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/EntityManager.php was not
         matched in reported errors.
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$isIdentifierComposite\.$# in path
         /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/EntityManager.php was not matched in reported errors.
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$name\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/EntityManager.php was not
         matched in reported errors.
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$rootEntityName\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/EntityManager.php was
         not matched in reported errors.
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$subClasses\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/EntityManager.php was not
         matched in reported errors.
         Ignored error pattern #^Call to an undefined method Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:newInstance\(\)\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/EntityManager.php was not
         matched in reported errors.
         Ignored error pattern #^Call to an undefined method Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:setIdentifierValues\(\)\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/EntityManager.php
         was not matched in reported errors.
         Ignored error pattern #^Method Doctrine\\ORM\\EntityManager\:\:getClassMetadata\(\) should return Doctrine\\ORM\\Mapping\\ClassMetadata but returns Doctrine\\Persistence\\Mapping\\ClassMetadata\.$# in
         path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/EntityManager.php was not matched in reported errors.
         Ignored error pattern #^Parameter \#2 \$class of method Doctrine\\ORM\\EntityManager\:\:checkLockRequirements\(\) expects Doctrine\\ORM\\Mapping\\ClassMetadata,
         Doctrine\\Persistence\\Mapping\\ClassMetadata given\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/EntityManager.php was not matched in reported errors.
 ------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   Doctrine/ORM/Mapping/ClassMetadataFactory.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$isEmbeddedClass\.$# in path
         /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php was not matched in reported errors.
         Ignored error pattern #^Parameter \#1 \$subClass of method Doctrine\\ORM\\Mapping\\ClassMetadataFactory\:\:addNestedEmbeddedClasses\(\) expects Doctrine\\ORM\\Mapping\\ClassMetadata,
         Doctrine\\Persistence\\Mapping\\ClassMetadata given\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php was not matched in reported errors.
  161    Ignored error pattern #^Parameter \#2 \$parent of method Doctrine\\ORM\\Mapping\\ClassMetadataFactory\:\:inheritIdGeneratorMapping\(\) expects Doctrine\\ORM\\Mapping\\ClassMetadataInfo,
         Doctrine\\Persistence\\Mapping\\ClassMetadata given\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php is expected to occur 2 times, but occurred only 1 time.
  177    Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$name\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
         is expected to occur 4 times, but occurred only 3 times.
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   Doctrine/ORM/Tools/SchemaValidator.php
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$associationMappings\.$# in path
         /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Tools/SchemaValidator.php was not matched in reported errors.
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$containsForeignIdentifier\.$# in path
         /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Tools/SchemaValidator.php was not matched in reported errors.
         Ignored error pattern #^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$name\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Tools/SchemaValidator.php was
         not matched in reported errors.
         Ignored error pattern #^Call to an undefined method Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:getIdentifierColumnNames\(\)\.$# in path
         /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Tools/SchemaValidator.php was not matched in reported errors.
         Ignored error pattern #^Parameter \#1 \$class of method Doctrine\\ORM\\Tools\\SchemaValidator\:\:validateClass\(\) expects Doctrine\\ORM\\Mapping\\ClassMetadataInfo,
         Doctrine\\Persistence\\Mapping\\ClassMetadata given\.$# in path /home/greg/dev/doctrine-orm/lib/Doctrine/ORM/Tools/SchemaValidator.php was not matched in reported errors.
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

greg0ire added a commit to greg0ire/doctrine-orm that referenced this issue Apr 19, 2021
This fixes an SA regression introduced when using stricter types in
SchemaTool.

Fixes doctrine#8642
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants