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
[shopsys] automated fixes and additions of annotations for extended classes #1344
Conversation
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.
So far reviewed first three commits
...ork/src/DependencyInjection/Compiler/RegisterProjectFrameworkClassExtensionsCompilerPass.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
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.
Hi @vitek-rostislav, I finished the review.
First of all, I'm really thrilled about this new functionality! I really think it helps a lot.
I made some suggestions and comments to the code, please check them out.
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
a299fe1
to
2866ba5
Compare
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
9cae3fe
to
a6c0c6b
Compare
76f040e
to
e8d18c2
Compare
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.
Hi, awesome job with refactoring!
I reviewed the changes excluding the tests and have few things to consider.
In the end, don't forget to add changes generated with this command (but it will be better after the command itself is reviewed and tested – another PR maybe?)
And PHPStan fails on dummy classes for tests, these could be excluded from analysis (maybe renamed like ChildClass3.php.test
but I'm not sure if it will work.
I take a look at tests tomorrow
packages/framework/src/Component/ClassExtension/AnnotationsAdder.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Component/ClassExtension/AnnotationsAdder.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Component/ClassExtension/AnnotationsReplacementsMap.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Component/ClassExtension/ClassExtensionRegistry.php
Show resolved
Hide resolved
packages/framework/src/Component/ClassExtension/MethodAnnotationsFactory.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Component/ClassExtension/MethodAnnotationsFactory.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Component/ClassExtension/PropertyAnnotationsFactory.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Component/ClassExtension/PropertyAnnotationsFactory.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Component/ClassExtension/PropertyAnnotationsFactory.php
Outdated
Show resolved
Hide resolved
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.
finished the review. just last thing about phpstan ignored rule
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.
Summary of business validation discussion:
- there should be two separate upgrade notes - one for using annotation fix and second for lvl4 PHP stan because these are two separate issues
- the annotation-fix should be part of coding standards (or something like this) and should behave the same way (no fixes without confirmation)
aceb253
to
6802951
Compare
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.
Hi, I will go to hell for more and more requested changes
project-base/tests/ShopBundle/Functional/Controller/ProductRenameRedirectPreviousUrlTest.php
Show resolved
Hide resolved
project-base/src/Shopsys/ShopBundle/DataFixtures/Performance/ProductDataFixture.php
Outdated
Show resolved
Hide resolved
project-base/src/Shopsys/ShopBundle/DataFixtures/Demo/SettingValueDataFixture.php
Outdated
Show resolved
Hide resolved
project-base/src/Shopsys/ShopBundle/DataFixtures/Demo/ProductAccessoriesDataFixture.php
Outdated
Show resolved
Hide resolved
project-base/src/Shopsys/ShopBundle/DataFixtures/Demo/MultidomainSettingValueDataFixture.php
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Command/FixExtendedClassesAnnotationsCommand.php
Outdated
Show resolved
Hide resolved
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.
Reviewed last two commits
packages/framework/src/Component/ClassExtension/MethodAnnotationsFactory.php
Show resolved
Hide resolved
packages/framework/src/Component/ClassExtension/MethodAnnotationsFactory.php
Outdated
Show resolved
Hide resolved
packages/framework/src/Component/ClassExtension/MethodAnnotationsFactory.php
Show resolved
Hide resolved
…ject classes that extend the classes (or implement interfaces) from framework - the registry will be used for automated annotations fixes and additions in project classes - this will make PHPStan and PHPStorm understand the code of Shopsys Framework based project properly - the extensions information is not collected in production environment as it is not necessary there
- the class is unit tested - AnnotationsReplacementsMap was extracted as well because the mappings are used on multiple places in the command
… replaceInPropertyType() extracted to AnnotationsReplacer - added unit tests for the methods
…r annotations replacements - getRelevantFrameworkAnnotationsPattern() was broken by rewritting the history of the original commit - the functionality extracted to AnnotationsReplacementsMap::getPatternForAny
- AnnotationsReplacementsMap is an autowired DIC service as well - it's constructor's argument $classExtensionMap is injected using expression language - see https://symfony.com/doc/3.4/service_container/expression_language.html
…etter reflection class
…and @method annotation extracted to separate classes - MethodAnnotationsFactory - responsible for providing @method annotation lines, unit tested - PropertyAnnotationsFactory - responsible for providing @Property annotation lines, unit tested - AnnotationsAdder - respnsible for adding the annotations to classes, unit tested - FileContentsReplacer - a simple helper class wrapping file_get_contents, str_replace, and file_put_contents calls sequence
- all the automated fixes and additions of annotations are applied - the standards are failing intentionally on this commit as there are several phpstan rules violations that need to be fixed manually yet
…matically using "php phing fix-annotations" - sometimes, there is an extended entity returned directly by calling a framework service thanks to EntityNameResolver magic that phpstan does not understand - there is a workaround for this - a project developer can create an empty service extending the framework one (e.g. ShopBundle\ProductFacade extends FrameworkBundle\BaseProductFacade) - in such a case the developer can generate annotations for his extended class using "php phing fix-annotations" that will wix the phpstan rules violations as well
afa2571
to
5ce5f88
Compare
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.
Reviewed changes from testing.
One thing and you have typo in the commit message
- ClassExtensionRegistry: extended ontrollers are now registered as well
+ ClassExtensionRegistry: extended controllers are now registered as well
packages/framework/src/Component/ClassExtension/ClassExtensionRegistry.php
Outdated
Show resolved
Hide resolved
bb02ba9
to
c9d6429
Compare
…rbose output - FixExtendedClassesAnnotationsCommand renamed to ExtendedClassesAnnotationsCommand - filenames that were fixed (or need to be fixed when using "dry-run" mode) are reported
…hing targets "standards", "standards-diff", "standards-fix", and "standards-fix-diff" - there is a new build property "check-and-fix-annotations" that allows project developers to skip the checks and fixes of annotations when they do not want to include them in their "standards-*" targets - done in such a way to avoid possible BC breaks
- parameter types are now taken into account as well
…the annotations fixer - proper format is "/** @var Type $variableName */" above the variable - the annotations were malformatted before so we fixed what we noticed :)
…nnotations-fix" and "annotations-check" - in accordance with our standards - https://github.com/shopsys/shopsys/blob/master/docs/contributing/guidelines-for-phing-targets.md#naming-conventions
…tions-*" targets moved to "Coding Standards section"
189f9db
to
64a1bf2
Compare
All the objections were addressed, approved personally 😁
🚀 |
framework
fromproject-base
, static analysis tools are not able to understand the extensions, which makes the DX worse and PHPStan inspections fail. We want to use the higher level of PHPStan even inproject-base
and do not force the project developers to do the boring things manually so we created the automated tool that makes the static analysis understand the extended code properly.TODO