From 2162175cef6b6e094a132b8a846ab795012824ae Mon Sep 17 00:00:00 2001 From: Sascha Nowak Date: Fri, 6 Jan 2023 17:06:56 +0100 Subject: [PATCH 1/3] FEATURE: Add flow annotations to attribute set With this set your flow code can easily migrated to a modern php8 codebase. --- config/{set => sets}/contentrepository-90.php | 0 .../sets/flow-annotations-to-attributes.php | 39 +++++++++ src/NeosRectorSets.php | 4 +- .../AnnotationToAttributeTest.php | 31 +++++++ .../Fixture/aspect.php.inc | 87 +++++++++++++++++++ .../Fixture/autowiring.php.inc | 33 +++++++ .../Fixture/compilestatic.php.inc | 29 +++++++ .../Fixture/entity.php.inc | 23 +++++ .../Fixture/entitywithrepository.php.inc | 23 +++++ .../Fixture/flushescaches.php.inc | 29 +++++++ .../Fixture/identity.php.inc | 25 ++++++ .../Fixture/ignorevalidation.php.inc | 39 +++++++++ .../Fixture/inject.php.inc | 27 ++++++ .../Fixture/injectconfiguration.php.inc | 25 ++++++ .../Fixture/internal.php.inc | 29 +++++++ .../Fixture/lazy.php.inc | 29 +++++++ .../Fixture/maprequestbody.php.inc | 29 +++++++ .../Fixture/proxy.php.inc | 23 +++++ .../Fixture/scope.php.inc | 23 +++++ .../Fixture/session.php.inc | 29 +++++++ .../Fixture/signal.php.inc | 29 +++++++ .../Fixture/skipcsrfprotection.php.inc | 29 +++++++ .../Fixture/transient.php.inc | 25 ++++++ .../Fixture/validate.php.inc | 39 +++++++++ .../Fixture/value_object.php.inc | 23 +++++ .../config/configured_rule.php | 11 +++ 26 files changed, 731 insertions(+), 1 deletion(-) rename config/{set => sets}/contentrepository-90.php (100%) create mode 100644 config/sets/flow-annotations-to-attributes.php create mode 100644 tests/Rules/AnnotationToAttribute/AnnotationToAttributeTest.php create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/aspect.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/autowiring.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/compilestatic.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/entity.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/entitywithrepository.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/flushescaches.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/identity.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/ignorevalidation.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/inject.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/injectconfiguration.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/internal.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/lazy.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/maprequestbody.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/proxy.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/scope.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/session.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/signal.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/skipcsrfprotection.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/transient.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/validate.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/Fixture/value_object.php.inc create mode 100644 tests/Rules/AnnotationToAttribute/config/configured_rule.php diff --git a/config/set/contentrepository-90.php b/config/sets/contentrepository-90.php similarity index 100% rename from config/set/contentrepository-90.php rename to config/sets/contentrepository-90.php diff --git a/config/sets/flow-annotations-to-attributes.php b/config/sets/flow-annotations-to-attributes.php new file mode 100644 index 0000000..63c2f7b --- /dev/null +++ b/config/sets/flow-annotations-to-attributes.php @@ -0,0 +1,39 @@ +ruleWithConfiguration(AnnotationToAttributeRector::class, [ + new AnnotationToAttribute('Neos\\Flow\\Annotations\\After'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\AfterReturning'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\AfterThrowing'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Around'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Aspect'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Autowiring'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Before'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\CompileStatic'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Entity'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\FlushesCaches'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Identity'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\IgnoreValidation'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Inject'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\InjectConfiguration'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Internal'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Introduce'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Lazy'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\MapRequestBody'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Pointcut'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Proxy'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Scope'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Session'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Signal'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\SkipCsrfProtection'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Transient'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\Validate'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\ValidationGroups'), + new AnnotationToAttribute('Neos\\Flow\\Annotations\\ValueObject'), + ]); +}; diff --git a/src/NeosRectorSets.php b/src/NeosRectorSets.php index f1f8e3c..8499a9d 100644 --- a/src/NeosRectorSets.php +++ b/src/NeosRectorSets.php @@ -7,5 +7,7 @@ class NeosRectorSets implements SetListInterface { - public const CONTENTREPOSITORY_9_0 = __DIR__ . '/../config/set/contentrepository-90.php'; + public const CONTENTREPOSITORY_9_0 = __DIR__ . '/../config/sets/contentrepository-90.php'; + + public const ANNOTATIONS_TO_ATTRIBUTES = __DIR__ . '/../config/sets/flow-annotations-to-attributes.php'; } diff --git a/tests/Rules/AnnotationToAttribute/AnnotationToAttributeTest.php b/tests/Rules/AnnotationToAttribute/AnnotationToAttributeTest.php new file mode 100644 index 0000000..4c0cec1 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/AnnotationToAttributeTest.php @@ -0,0 +1,31 @@ +doTestFile($fileInfo); + } + + /** + * @return \Iterator + */ + public function provideData(): \Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Rules/AnnotationToAttribute/Fixture/aspect.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/aspect.php.inc new file mode 100644 index 0000000..8f0b5a4 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/aspect.php.inc @@ -0,0 +1,87 @@ +getPublicPackageResourceUri())") + */ + public function around(JoinPointInterface $joinPoint) + { + } + /** + * @Flow\Before("method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())") + */ + public function before(JoinPointInterface $joinPoint) + { + } + /** + * @Flow\AfterReturning("method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())") + */ + public function afterReturning(JoinPointInterface $joinPoint) + { + } + /** + * @Flow\AfterThrowing("method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())") + */ + public function afterThrowing(JoinPointInterface $joinPoint) + { + } + /** + * @Flow\After("method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())") + */ + public function after(JoinPointInterface $joinPoint) + { + } + /** + * @Flow\Pointcut("method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())") + */ + public function pointcut(PointcutFilterInterface $joinPoint) + { + } +} + +?> +----- +getPublicPackageResourceUri())')] + public function around(JoinPointInterface $joinPoint) + { + } + #[Flow\Before('method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())')] + public function before(JoinPointInterface $joinPoint) + { + } + #[Flow\AfterReturning('method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())')] + public function afterReturning(JoinPointInterface $joinPoint) + { + } + #[Flow\AfterThrowing('method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())')] + public function afterThrowing(JoinPointInterface $joinPoint) + { + } + #[Flow\After('method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())')] + public function after(JoinPointInterface $joinPoint) + { + } + #[Flow\Pointcut('method(Neos\Flow\ResourceManagement\ResourceManager->getPublicPackageResourceUri())')] + public function pointcut(PointcutFilterInterface $joinPoint) + { + } +} + +?> diff --git a/tests/Rules/AnnotationToAttribute/Fixture/autowiring.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/autowiring.php.inc new file mode 100644 index 0000000..6b2e5d3 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/autowiring.php.inc @@ -0,0 +1,33 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/compilestatic.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/compilestatic.php.inc new file mode 100644 index 0000000..5a42940 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/compilestatic.php.inc @@ -0,0 +1,29 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/entity.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/entity.php.inc new file mode 100644 index 0000000..c5dc239 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/entity.php.inc @@ -0,0 +1,23 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/entitywithrepository.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/entitywithrepository.php.inc new file mode 100644 index 0000000..23d1d4d --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/entitywithrepository.php.inc @@ -0,0 +1,23 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/flushescaches.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/flushescaches.php.inc new file mode 100644 index 0000000..7fd8a44 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/flushescaches.php.inc @@ -0,0 +1,29 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/identity.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/identity.php.inc new file mode 100644 index 0000000..3aa9598 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/identity.php.inc @@ -0,0 +1,25 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/ignorevalidation.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/ignorevalidation.php.inc new file mode 100644 index 0000000..d3c34ca --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/ignorevalidation.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/inject.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/inject.php.inc new file mode 100644 index 0000000..7f8cdee --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/inject.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/injectconfiguration.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/injectconfiguration.php.inc new file mode 100644 index 0000000..ca375e0 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/injectconfiguration.php.inc @@ -0,0 +1,25 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/internal.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/internal.php.inc new file mode 100644 index 0000000..09a2784 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/internal.php.inc @@ -0,0 +1,29 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/lazy.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/lazy.php.inc new file mode 100644 index 0000000..7ed6414 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/lazy.php.inc @@ -0,0 +1,29 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/maprequestbody.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/maprequestbody.php.inc new file mode 100644 index 0000000..77d7d6b --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/maprequestbody.php.inc @@ -0,0 +1,29 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/proxy.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/proxy.php.inc new file mode 100644 index 0000000..7bd5402 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/proxy.php.inc @@ -0,0 +1,23 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/scope.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/scope.php.inc new file mode 100644 index 0000000..c1b62fc --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/scope.php.inc @@ -0,0 +1,23 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/session.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/session.php.inc new file mode 100644 index 0000000..4590a5d --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/session.php.inc @@ -0,0 +1,29 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/signal.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/signal.php.inc new file mode 100644 index 0000000..e15d869 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/signal.php.inc @@ -0,0 +1,29 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/skipcsrfprotection.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/skipcsrfprotection.php.inc new file mode 100644 index 0000000..a0f23e1 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/skipcsrfprotection.php.inc @@ -0,0 +1,29 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/transient.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/transient.php.inc new file mode 100644 index 0000000..741908f --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/transient.php.inc @@ -0,0 +1,25 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/Fixture/validate.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/validate.php.inc new file mode 100644 index 0000000..82cafe1 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/validate.php.inc @@ -0,0 +1,39 @@ + +----- + 0, 'maximum' => 40])] + protected $foo; + + #[Flow\Validate(type: 'StringLength', options: ['minimum' => 0, 'maximum' => 40])] + #[Flow\Validate(argumentName: 'resource', type: 'NotEmpty')] + public function someAction(Resource $resource, string $resourceType = ''): void + { + } +} + +?> diff --git a/tests/Rules/AnnotationToAttribute/Fixture/value_object.php.inc b/tests/Rules/AnnotationToAttribute/Fixture/value_object.php.inc new file mode 100644 index 0000000..2d87361 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/Fixture/value_object.php.inc @@ -0,0 +1,23 @@ + +----- + diff --git a/tests/Rules/AnnotationToAttribute/config/configured_rule.php b/tests/Rules/AnnotationToAttribute/config/configured_rule.php new file mode 100644 index 0000000..5a6f864 --- /dev/null +++ b/tests/Rules/AnnotationToAttribute/config/configured_rule.php @@ -0,0 +1,11 @@ +sets([ + \Neos\Rector\NeosRectorSets::ANNOTATIONS_TO_ATTRIBUTES + ]); +}; From 50b6296085a2cb8dc7249f5c6cb73c42cf626862 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Sat, 30 Sep 2023 09:48:31 +0200 Subject: [PATCH 2/3] TASK: Change config path back to set --- config/{sets => set}/contentrepository-90.php | 0 config/{sets => set}/flow-annotations-to-attributes.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename config/{sets => set}/contentrepository-90.php (100%) rename config/{sets => set}/flow-annotations-to-attributes.php (100%) diff --git a/config/sets/contentrepository-90.php b/config/set/contentrepository-90.php similarity index 100% rename from config/sets/contentrepository-90.php rename to config/set/contentrepository-90.php diff --git a/config/sets/flow-annotations-to-attributes.php b/config/set/flow-annotations-to-attributes.php similarity index 100% rename from config/sets/flow-annotations-to-attributes.php rename to config/set/flow-annotations-to-attributes.php From cfe0e074cd322425269a6c1152785eaedfb93ef1 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Sat, 30 Sep 2023 09:51:12 +0200 Subject: [PATCH 3/3] TASK: Change config path back to set --- src/NeosRectorSets.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NeosRectorSets.php b/src/NeosRectorSets.php index 8499a9d..8db4038 100644 --- a/src/NeosRectorSets.php +++ b/src/NeosRectorSets.php @@ -7,7 +7,7 @@ class NeosRectorSets implements SetListInterface { - public const CONTENTREPOSITORY_9_0 = __DIR__ . '/../config/sets/contentrepository-90.php'; + public const CONTENTREPOSITORY_9_0 = __DIR__ . '/../config/set/contentrepository-90.php'; - public const ANNOTATIONS_TO_ATTRIBUTES = __DIR__ . '/../config/sets/flow-annotations-to-attributes.php'; + public const ANNOTATIONS_TO_ATTRIBUTES = __DIR__ . '/../config/set/flow-annotations-to-attributes.php'; }