Skip to content

Commit

Permalink
Change JsonResponse::class to JsonApiResponse::class
Browse files Browse the repository at this point in the history
Our custom rector rule `ApiHandlerJsonResponseRector` fixes most of the
`Crm\ApiModule\Api\JsonResponse` instances (eg. `new JsonResponse()`)
to `Tomaj\NetteApi\Response\JsonApiResponse` (together with moving http
code from `->setCode()` directly into JsonApiResponse initialization.

But it doesn't refactor all instances. Eg. `JsonResponse::class` (used
in tests) and PHPdoc annotations like `/** @var JsonResponse */` were
left unchanged. Using `RenameClassRector` fixes that.

remp/crm#2330 & remp/crm#2342
  • Loading branch information
markoph committed Mar 29, 2022
1 parent 1acd03f commit 3785213
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions config/sets/crm-1-0-without-nette.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@
return static function (\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $containerConfigurator) : void {
$services = $containerConfigurator->services();

/*
* Change params of ApiHandlerInterface::handle() and IdempotentHandlerInterface::idempotentHandle() methods
* - https://github.com/remp2020/crm-api-module/commit/d03536184b3dbd568c23c886032df9cd87dddb46
*/
$services->set(\Crm\Utils\Rector\UpgradeToCrm1\ApiHandlerParametersRector::class);

/*
* Change JsonResponse($result) with setHttpCode($code) to new Tomaj\NetteApi\Response\JsonApiResponse($code, $result)
*/
$services->set(\Crm\Utils\Rector\UpgradeToCrm1\ApiHandlerJsonResponseRector::class);

/*
* Add return types to ApiHandlerInterface::params() and ApiHandlerInterface::handle() methods
*/
Expand All @@ -41,22 +30,53 @@
),
]);

/*
* Move $paramsProcessor->isError() to $paramsProcessor->hasError()
* Check Crm\ApiModule\Params\ParamsProcessor for details.
* This was moved as quick fix of legacy code but it is deprecated. You should manually refactor it.
*
* https://github.com/remp2020/crm-api-module/commit/01ac6685456282eccc95ed439e00fbb13c7c5f36
*/
$services->set(\Rector\Renaming\Rector\MethodCall\RenameMethodRector::class)
->configure([
/*
* Move $paramsProcessor->isError() to $paramsProcessor->hasError()
* Check Crm\ApiModule\Params\ParamsProcessor for details.
* This was moved as quick fix of legacy code but it is deprecated. You should manually refactor it.
*
* https://github.com/remp2020/crm-api-module/commit/01ac6685456282eccc95ed439e00fbb13c7c5f36
*/
new \Rector\Renaming\ValueObject\MethodCallRename(
'Crm\\ApiModule\\Params\\ParamsProcessor',
'isError',
'hasError'
),
// https://github.com/remp2020/crm-api-module/commit/b6950e37984d736490a7e9c10105cb752e365d8b
new \Rector\Renaming\ValueObject\MethodCallRename(
'Crm\\ApiModule\\Response\\ApiResponseInterface',
'setHttpCode',
'setCode'
),
// https://github.com/remp2020/crm-api-module/commit/b6950e37984d736490a7e9c10105cb752e365d8b
new \Rector\Renaming\ValueObject\MethodCallRename(
'Crm\\ApiModule\\Response\\ApiResponseInterface',
'getHttpCode',
'getCode'
),
]);

/*
* Change params of ApiHandlerInterface::handle() and IdempotentHandlerInterface::idempotentHandle() methods
* - https://github.com/remp2020/crm-api-module/commit/d03536184b3dbd568c23c886032df9cd87dddb46
*/
$services->set(\Crm\Utils\Rector\UpgradeToCrm1\ApiHandlerParametersRector::class);

/*
* Change JsonResponse($result) with setHttpCode($code)/setCode($code) to new Tomaj\NetteApi\Response\JsonApiResponse($code, $result)
*/
$services->set(\Crm\Utils\Rector\UpgradeToCrm1\ApiHandlerJsonResponseRector::class);

$services->set(\Rector\Renaming\Rector\Name\RenameClassRector::class)->configure([
/*
* JsonResponse is marked as deprecated by https://github.com/remp2020/crm-api-module/commit/1e1c97ac88b95346ee62f804a31120d1af08c664
* - this has to be refactored after rector rule `ApiHandlerJsonResponseRector` (otherwise that rule fails)
*/
'Crm\\ApiModule\\Api\\JsonResponse' => 'Tomaj\\NetteApi\\Response\\JsonApiResponse',
]);

/*
* Update composer packages
*/
Expand Down

0 comments on commit 3785213

Please sign in to comment.