-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] TypeHandlingUtility instead of TypeHandlingService (#1587)
Resolves: #50
- Loading branch information
1 parent
eb5ca7e
commit 8d1ae23
Showing
6 changed files
with
167 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
61 changes: 61 additions & 0 deletions
61
src/Rector/v7/v0/TypeHandlingServiceToTypeHandlingUtilityRector.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,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Rector\v7\v0; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\MethodCall; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Rector\Core\RectorDefinition\CodeSample; | ||
use Rector\Core\RectorDefinition\RectorDefinition; | ||
use TYPO3\CMS\Extbase\Service\TypeHandlingService; | ||
use TYPO3\CMS\Extbase\Utility\TypeHandlingUtility; | ||
|
||
/** | ||
* @see https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/7.0/Breaking-61786-ExtbaseDeprecatedTypeHandlingServiceRemoved.html | ||
*/ | ||
final class TypeHandlingServiceToTypeHandlingUtilityRector extends AbstractRector | ||
{ | ||
public function getNodeTypes(): array | ||
{ | ||
return [MethodCall::class]; | ||
} | ||
|
||
/** | ||
* @param MethodCall $node | ||
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
if (! $this->isMethodStaticCallOrClassMethodObjectType($node, TypeHandlingService::class)) { | ||
return null; | ||
} | ||
|
||
$methodCall = $this->getName($node->name); | ||
|
||
if (null === $methodCall) { | ||
return null; | ||
} | ||
|
||
return $this->createStaticCall(TypeHandlingUtility::class, $methodCall, $node->args); | ||
} | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
public function getDefinition(): RectorDefinition | ||
{ | ||
return new RectorDefinition('Use TypeHandlingUtility instead of TypeHandlingService', [ | ||
new CodeSample(<<<'PHP' | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Service\TypeHandlingService; | ||
GeneralUtility::makeInstance(TypeHandlingService::class)->isSimpleType('string'); | ||
PHP | ||
, <<<'PHP' | ||
use TYPO3\CMS\Extbase\Utility\TypeHandlingUtility; | ||
TypeHandlingUtility::isSimpleType('string'); | ||
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,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
|
||
namespace TYPO3\CMS\Extbase\Service; | ||
|
||
if (class_exists(TypeHandlingService::class)) { | ||
return; | ||
} | ||
|
||
final class TypeHandlingService | ||
{ | ||
public function parseType($type): void | ||
{ | ||
} | ||
|
||
public function normalizeType($type): void | ||
{ | ||
} | ||
|
||
public function isLiteral($type): void | ||
{ | ||
} | ||
|
||
public function isSimpleType($type): void | ||
{ | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
...ctor/v7/v0/TypeHandlingServiceToTypeHandlingUtility/Fixture/type_handling_utility.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,24 @@ | ||
<?php | ||
|
||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Service\TypeHandlingService; | ||
|
||
$typeHandlingService = GeneralUtility::makeInstance(TypeHandlingService::class); | ||
$typeHandlingService->parseType('string'); | ||
$typeHandlingService->normalizeType('string'); | ||
$typeHandlingService->isLiteral('string'); | ||
$typeHandlingService->isSimpleType('string'); | ||
|
||
|
||
?> | ||
----- | ||
<?php | ||
|
||
use TYPO3\CMS\Extbase\Utility\TypeHandlingUtility; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Service\TypeHandlingService; | ||
$typeHandlingService = GeneralUtility::makeInstance(TypeHandlingService::class); | ||
TypeHandlingUtility::parseType('string'); | ||
TypeHandlingUtility::normalizeType('string'); | ||
TypeHandlingUtility::isLiteral('string'); | ||
TypeHandlingUtility::isSimpleType('string'); |
31 changes: 31 additions & 0 deletions
31
...ndlingServiceToTypeHandlingUtility/TypeHandlingServiceToTypeHandlingUtilityRectorTest.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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v7\v0\TypeHandlingServiceToTypeHandlingUtility; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Ssch\TYPO3Rector\Rector\v7\v0\TypeHandlingServiceToTypeHandlingUtilityRector; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class TypeHandlingServiceToTypeHandlingUtilityRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideDataForTest() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
public function provideDataForTest(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
protected function getRectorClass(): string | ||
{ | ||
return TypeHandlingServiceToTypeHandlingUtilityRector::class; | ||
} | ||
} |