From 8b6330201a4254dbc222075637d145b2475a1079 Mon Sep 17 00:00:00 2001 From: wkania Date: Sat, 12 Nov 2022 18:52:04 +0100 Subject: [PATCH] [Set] FOSRest annotation to attribute (#273) --- .../fosrest/annotations-to-attributes.php | 36 +++ src/Set/FOSRestSetList.php | 15 ++ .../FOSRestAnnotationsToAttributesTest.php | 29 ++ .../Fixture/param_fixture.php.inc | 49 ++++ .../Fixture/route_fixture.php.inc | 249 ++++++++++++++++++ .../config/fosrestAnnotationsToAttributes.php | 11 + 6 files changed, 389 insertions(+) create mode 100644 config/sets/fosrest/annotations-to-attributes.php create mode 100644 src/Set/FOSRestSetList.php create mode 100644 tests/Set/FOSRestAnnotationsToAttributes/FOSRestAnnotationsToAttributesTest.php create mode 100644 tests/Set/FOSRestAnnotationsToAttributes/Fixture/param_fixture.php.inc create mode 100644 tests/Set/FOSRestAnnotationsToAttributes/Fixture/route_fixture.php.inc create mode 100644 tests/Set/FOSRestAnnotationsToAttributes/config/fosrestAnnotationsToAttributes.php diff --git a/config/sets/fosrest/annotations-to-attributes.php b/config/sets/fosrest/annotations-to-attributes.php new file mode 100644 index 00000000..67bd3a9b --- /dev/null +++ b/config/sets/fosrest/annotations-to-attributes.php @@ -0,0 +1,36 @@ +ruleWithConfiguration(AnnotationToAttributeRector::class, [ + // @see https://github.com/FriendsOfSymfony/FOSRestBundle/pull/2325 + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Copy'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Delete'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Get'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Head'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Link'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Lock'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Mkcol'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Move'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Options'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Patch'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Post'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\PropFind'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\PropPatch'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Put'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Route'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Unlink'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\Unlock'), + // @see https://github.com/FriendsOfSymfony/FOSRestBundle/pull/2326 + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\View'), + // @see https://github.com/FriendsOfSymfony/FOSRestBundle/pull/2327 + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\FileParam'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\QueryParam'), + new AnnotationToAttribute('FOS\RestBundle\Controller\Annotations\RequestParam'), + ]); +}; diff --git a/src/Set/FOSRestSetList.php b/src/Set/FOSRestSetList.php new file mode 100644 index 00000000..28b23501 --- /dev/null +++ b/src/Set/FOSRestSetList.php @@ -0,0 +1,15 @@ +doTestFile($filePath); + } + + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/fosrestAnnotationsToAttributes.php'; + } +} diff --git a/tests/Set/FOSRestAnnotationsToAttributes/Fixture/param_fixture.php.inc b/tests/Set/FOSRestAnnotationsToAttributes/Fixture/param_fixture.php.inc new file mode 100644 index 00000000..d17851b3 --- /dev/null +++ b/tests/Set/FOSRestAnnotationsToAttributes/Fixture/param_fixture.php.inc @@ -0,0 +1,49 @@ + +----- + 'image/jpeg', 'minWidth' => 500], image: true)] + public function create() + { + } +} + +?> diff --git a/tests/Set/FOSRestAnnotationsToAttributes/Fixture/route_fixture.php.inc b/tests/Set/FOSRestAnnotationsToAttributes/Fixture/route_fixture.php.inc new file mode 100644 index 00000000..7a8ccd6a --- /dev/null +++ b/tests/Set/FOSRestAnnotationsToAttributes/Fixture/route_fixture.php.inc @@ -0,0 +1,249 @@ + +----- + diff --git a/tests/Set/FOSRestAnnotationsToAttributes/config/fosrestAnnotationsToAttributes.php b/tests/Set/FOSRestAnnotationsToAttributes/config/fosrestAnnotationsToAttributes.php new file mode 100644 index 00000000..adb799b1 --- /dev/null +++ b/tests/Set/FOSRestAnnotationsToAttributes/config/fosrestAnnotationsToAttributes.php @@ -0,0 +1,11 @@ +import(__DIR__ . '/../../../../config/config.php'); + $rectorConfig->sets([FOSRestSetList::ANNOTATIONS_TO_ATTRIBUTES]); +};