-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Set] FOSRest annotation to attribute (#273)
- Loading branch information
Showing
6 changed files
with
389 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector; | ||
use Rector\Php80\ValueObject\AnnotationToAttribute; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->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'), | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Symfony\Set; | ||
|
||
use Rector\Set\Contract\SetListInterface; | ||
|
||
final class FOSRestSetList implements SetListInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
final public const ANNOTATIONS_TO_ATTRIBUTES = __DIR__ . '/../../config/sets/fosrest/annotations-to-attributes.php'; | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/Set/FOSRestAnnotationsToAttributes/FOSRestAnnotationsToAttributesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Symfony\Tests\Set\FOSRestAnnotationsToAttributes; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class FOSRestAnnotationsToAttributesTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/fosrestAnnotationsToAttributes.php'; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
tests/Set/FOSRestAnnotationsToAttributes/Fixture/param_fixture.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
use FOS\RestBundle\Controller\Annotations\FileParam; | ||
use FOS\RestBundle\Controller\Annotations\QueryParam; | ||
use FOS\RestBundle\Controller\Annotations\RequestParam; | ||
|
||
class BarController | ||
{ | ||
/** | ||
* @QueryParam(name="fooId", nullable=false, requirements="\d+") | ||
* @QueryParam(name="name", nullable=true, description="Foo Name") | ||
*/ | ||
public function foo() | ||
{ | ||
} | ||
|
||
/** | ||
* @RequestParam(name="name", requirements="[a-z]+", description="Foo Name") | ||
* @FileParam(name="avatar", requirements={"mimeTypes"="image/jpeg", "minWidth"="500"}, image=true) | ||
*/ | ||
public function create() | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use FOS\RestBundle\Controller\Annotations\FileParam; | ||
use FOS\RestBundle\Controller\Annotations\QueryParam; | ||
use FOS\RestBundle\Controller\Annotations\RequestParam; | ||
|
||
class BarController | ||
{ | ||
#[QueryParam(name: 'fooId', nullable: false, requirements: '\d+')] | ||
#[QueryParam(name: 'name', nullable: true, description: 'Foo Name')] | ||
public function foo() | ||
{ | ||
} | ||
|
||
#[RequestParam(name: 'name', requirements: '[a-z]+', description: 'Foo Name')] | ||
#[FileParam(name: 'avatar', requirements: ['mimeTypes' => 'image/jpeg', 'minWidth' => 500], image: true)] | ||
public function create() | ||
{ | ||
} | ||
} | ||
|
||
?> |
249 changes: 249 additions & 0 deletions
249
tests/Set/FOSRestAnnotationsToAttributes/Fixture/route_fixture.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,249 @@ | ||
<?php | ||
|
||
use FOS\RestBundle\Controller\Annotations\Copy; | ||
use FOS\RestBundle\Controller\Annotations\Delete; | ||
use FOS\RestBundle\Controller\Annotations\Get; | ||
use FOS\RestBundle\Controller\Annotations\Head; | ||
use FOS\RestBundle\Controller\Annotations\Link; | ||
use FOS\RestBundle\Controller\Annotations\Lock; | ||
use FOS\RestBundle\Controller\Annotations\Mkcol; | ||
use FOS\RestBundle\Controller\Annotations\Move; | ||
use FOS\RestBundle\Controller\Annotations\Options; | ||
use FOS\RestBundle\Controller\Annotations\Patch; | ||
use FOS\RestBundle\Controller\Annotations\Post; | ||
use FOS\RestBundle\Controller\Annotations\PropFind; | ||
use FOS\RestBundle\Controller\Annotations\PropPatch; | ||
use FOS\RestBundle\Controller\Annotations\Put; | ||
use FOS\RestBundle\Controller\Annotations\Route; | ||
use FOS\RestBundle\Controller\Annotations\Unlink; | ||
use FOS\RestBundle\Controller\Annotations\Unlock; | ||
use FOS\RestBundle\Controller\Annotations\View; | ||
|
||
/** | ||
* @Route("/api/foo") | ||
*/ | ||
class BarController | ||
{ | ||
/** | ||
* @Copy | ||
*/ | ||
public function copy() | ||
{ | ||
} | ||
|
||
/** | ||
* @Delete("/delete", name="foo_delete") | ||
*/ | ||
public function delete() | ||
{ | ||
} | ||
|
||
/** | ||
* @Get("/list", name="foo_list") | ||
* @View(serializerEnableMaxDepthChecks=false) | ||
*/ | ||
public function list() | ||
{ | ||
} | ||
|
||
/** | ||
* @Head | ||
*/ | ||
public function foo() | ||
{ | ||
} | ||
|
||
/** | ||
* @Link | ||
*/ | ||
public function addFriend() | ||
{ | ||
} | ||
|
||
/** | ||
* @Lock | ||
*/ | ||
public function pessimisticLock() | ||
{ | ||
} | ||
|
||
/** | ||
* @Mkcol | ||
*/ | ||
public function createList() | ||
{ | ||
} | ||
|
||
/** | ||
* @Move | ||
*/ | ||
public function move() | ||
{ | ||
} | ||
|
||
/** | ||
* @Options | ||
*/ | ||
public function options() | ||
{ | ||
} | ||
|
||
/** | ||
* @Patch("/update", name="foo_update") | ||
*/ | ||
public function update() | ||
{ | ||
} | ||
|
||
/** | ||
* @Post("/create", name="foo_create") | ||
*/ | ||
public function create() | ||
{ | ||
} | ||
|
||
/** | ||
* @PropFind | ||
*/ | ||
public function propFind() | ||
{ | ||
} | ||
|
||
/** | ||
* @PropPatch | ||
*/ | ||
public function propPatch() | ||
{ | ||
} | ||
|
||
/** | ||
* @Put("/replace", name="foo_replace") | ||
*/ | ||
public function replace() | ||
{ | ||
} | ||
|
||
/** | ||
* @Unlink | ||
*/ | ||
public function removeFriend() | ||
{ | ||
} | ||
|
||
/** | ||
* @Unlock | ||
*/ | ||
public function unlock() | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use FOS\RestBundle\Controller\Annotations\Copy; | ||
use FOS\RestBundle\Controller\Annotations\Delete; | ||
use FOS\RestBundle\Controller\Annotations\Get; | ||
use FOS\RestBundle\Controller\Annotations\Head; | ||
use FOS\RestBundle\Controller\Annotations\Link; | ||
use FOS\RestBundle\Controller\Annotations\Lock; | ||
use FOS\RestBundle\Controller\Annotations\Mkcol; | ||
use FOS\RestBundle\Controller\Annotations\Move; | ||
use FOS\RestBundle\Controller\Annotations\Options; | ||
use FOS\RestBundle\Controller\Annotations\Patch; | ||
use FOS\RestBundle\Controller\Annotations\Post; | ||
use FOS\RestBundle\Controller\Annotations\PropFind; | ||
use FOS\RestBundle\Controller\Annotations\PropPatch; | ||
use FOS\RestBundle\Controller\Annotations\Put; | ||
use FOS\RestBundle\Controller\Annotations\Route; | ||
use FOS\RestBundle\Controller\Annotations\Unlink; | ||
use FOS\RestBundle\Controller\Annotations\Unlock; | ||
use FOS\RestBundle\Controller\Annotations\View; | ||
|
||
#[Route('/api/foo')] | ||
class BarController | ||
{ | ||
#[Copy] | ||
public function copy() | ||
{ | ||
} | ||
|
||
#[Delete('/delete', name: 'foo_delete')] | ||
public function delete() | ||
{ | ||
} | ||
|
||
#[Get('/list', name: 'foo_list')] | ||
#[View(serializerEnableMaxDepthChecks: false)] | ||
public function list() | ||
{ | ||
} | ||
|
||
#[Head] | ||
public function foo() | ||
{ | ||
} | ||
|
||
#[Link] | ||
public function addFriend() | ||
{ | ||
} | ||
|
||
#[Lock] | ||
public function pessimisticLock() | ||
{ | ||
} | ||
|
||
#[Mkcol] | ||
public function createList() | ||
{ | ||
} | ||
|
||
#[Move] | ||
public function move() | ||
{ | ||
} | ||
|
||
#[Options] | ||
public function options() | ||
{ | ||
} | ||
|
||
#[Patch('/update', name: 'foo_update')] | ||
public function update() | ||
{ | ||
} | ||
|
||
#[Post('/create', name: 'foo_create')] | ||
public function create() | ||
{ | ||
} | ||
|
||
#[PropFind] | ||
public function propFind() | ||
{ | ||
} | ||
|
||
#[PropPatch] | ||
public function propPatch() | ||
{ | ||
} | ||
|
||
#[Put('/replace', name: 'foo_replace')] | ||
public function replace() | ||
{ | ||
} | ||
|
||
#[Unlink] | ||
public function removeFriend() | ||
{ | ||
} | ||
|
||
#[Unlock] | ||
public function unlock() | ||
{ | ||
} | ||
} | ||
|
||
?> |
11 changes: 11 additions & 0 deletions
11
tests/Set/FOSRestAnnotationsToAttributes/config/fosrestAnnotationsToAttributes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Symfony\Set\FOSRestSetList; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->import(__DIR__ . '/../../../../config/config.php'); | ||
$rectorConfig->sets([FOSRestSetList::ANNOTATIONS_TO_ATTRIBUTES]); | ||
}; |