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

Add PHPStan extensions, for Translatable/Translation interfaces #520

Merged
merged 8 commits into from
Feb 19, 2020

Conversation

Kocal
Copy link
Contributor

@Kocal Kocal commented Feb 12, 2020

This PR is a proposal for #516, and aim to replace #517.

Before: at b8a4b01 with 69 errors:

➜  DoctrineBehaviors git:(d) vendor/bin/phpstan analyze
Note: Using configuration file /home/kocal/Dev/DoctrineBehaviors/phpstan.neon.
 95/95 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ ----------------------------------------------------------------------------------------------------- 
  Line   tests/ORM/SluggableWithTranslatableEntityAndUniquenessTest.php                                       
 ------ ----------------------------------------------------------------------------------------------------- 
  29     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().  
  30     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().  
  47     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().  
  48     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getSlug().   
  49     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().  
  50     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getSlug().   
  56     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().  
  57     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().  
  66     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getSlug().   
  67     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getSlug().   
  68     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().  
  69     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().  
  71     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getSlug().   
  72     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getSlug().   
 ------ ----------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------- 
  Line   tests/ORM/TranslatableInheritanceTest.php                                                                    
 ------ ------------------------------------------------------------------------------------------------------------- 
  29     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().          
  30     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setExtendedTitle().  
  32     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().          
  33     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setExtendedTitle().  
  35     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().          
  36     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setExtendedTitle().  
  49     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().          
  50     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getExtendedTitle().  
  52     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().          
  53     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getExtendedTitle().  
  55     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().          
  56     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getExtendedTitle().  
 ------ ------------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/ORM/TranslatableTest.php                                                                                                  
 ------ -------------------------------------------------------------------------------------------------------------------------------- 
  33     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  34     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  35     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  47     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  48     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  49     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  55     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  56     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  57     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  69     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  70     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  71     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  77     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  78     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  90     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  91     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  93     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  94     Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  104    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  105    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  106    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  121    Call to an undefined method Knp\DoctrineBehaviors\Tests\Fixtures\Entity\TranslatableEntity::setTitle().                         
  134    Call to an undefined method Knp\DoctrineBehaviors\Tests\Fixtures\Entity\TranslatableEntity::getTitle().                         
  135    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  141    Call to an undefined method Knp\DoctrineBehaviors\Tests\Fixtures\Entity\TranslatableEntity::setTitle().                         
  154    Call to an undefined method Knp\DoctrineBehaviors\Tests\Fixtures\Entity\TranslatableEntity::getTitle().                         
  156    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  157    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  177    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  178    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  179    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  181    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  188    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  189    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  199    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::getTitle().                             
  207    Parameter #1 $translations of method Knp\DoctrineBehaviors\Tests\Fixtures\Entity\TranslatableEntity::setTranslations() expects  
         Doctrine\Common\Collections\Collection&iterable<Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface>, array<int,         
         Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface> given.                                                              
  215    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  216    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  217    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  239    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  240    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  241    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
  247    Call to an undefined method Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface::setTitle().                             
 ------ -------------------------------------------------------------------------------------------------------------------------------- 

                                                                                                                        
 [ERROR] Found 69 errors                                                                                                
                                                                                                                        

💡 Tip of the Day:
One or more properties in your code do not have a phpDoc with a type
but it could be inferred from the constructor to find more bugs.
Use inferPrivatePropertyTypeFromConstructor: true in your phpstan.neon to try it out!

Now: at last commit, with 0 errors

➜  DoctrineBehaviors git:(phpstan-extension) ✗ vendor/bin/phpstan analyze
Note: Using configuration file /home/kocal/Dev/DoctrineBehaviors/phpstan.neon.
 99/99 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%


                                                                                                                        
 [OK] No errors                                                                                                         
                                                                                                                        

💡 Tip of the Day:
One or more properties in your code do not have a phpDoc with a type
but it could be inferred from the constructor to find more bugs.
Use inferPrivatePropertyTypeFromConstructor: true in your phpstan.neon to try it out!

phpstan.neon Show resolved Hide resolved
To get ride of:
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   TranslatableInheritanceTest.php                                                                                                                  
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------- 
  30     Call to an undefined method Knp\DoctrineBehaviors\Tests\Fixtures\Entity\Translatable\AbstractTranslatableEntityTranslation::setExtendedTitle().  
  33     Call to an undefined method Knp\DoctrineBehaviors\Tests\Fixtures\Entity\Translatable\AbstractTranslatableEntityTranslation::setExtendedTitle().  
  36     Call to an undefined method Knp\DoctrineBehaviors\Tests\Fixtures\Entity\Translatable\AbstractTranslatableEntityTranslation::setExtendedTitle().  
  50     Call to an undefined method Knp\DoctrineBehaviors\Tests\Fixtures\Entity\Translatable\AbstractTranslatableEntityTranslation::getExtendedTitle().  
  53     Call to an undefined method Knp\DoctrineBehaviors\Tests\Fixtures\Entity\Translatable\AbstractTranslatableEntityTranslation::getExtendedTitle().  
  56     Call to an undefined method Knp\DoctrineBehaviors\Tests\Fixtures\Entity\Translatable\AbstractTranslatableEntityTranslation::getExtendedTitle().  
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------- 

`$entity` was seen as an AbstractTranslatableEntity and not as an ExtendedTranslatableEntity :(
@Kocal Kocal force-pushed the phpstan-extension branch from 3fa7a87 to 16a9c4e Compare February 12, 2020 22:20
@Kocal Kocal marked this pull request as ready for review February 12, 2020 22:23
@Kocal Kocal requested a review from TomasVotruba February 19, 2020 13:49
@TomasVotruba TomasVotruba merged commit 3810047 into KnpLabs:master Feb 19, 2020
@TomasVotruba
Copy link
Contributor

Great job! Thank you

@Kocal Kocal deleted the phpstan-extension branch February 19, 2020 14:08
@TomasVotruba
Copy link
Contributor

Could you look at #537 ?
Bug caused by this

@Kocal
Copy link
Contributor Author

Kocal commented Mar 24, 2020

Should be fixed by #537

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 this pull request may close these issues.

2 participants