Skip to content

Commit

Permalink
[TASK] TypeHandlingUtility instead of TypeHandlingService (#1587)
Browse files Browse the repository at this point in the history
Resolves: #50
  • Loading branch information
sabbelasichon authored Nov 11, 2020
1 parent eb5ca7e commit 8d1ae23
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/v7/typo3-70.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use function Rector\SymfonyPhpConfig\inline_value_objects;
use Ssch\TYPO3Rector\Rector\v7\v0\RemoveMethodCallConnectDbRector;
use Ssch\TYPO3Rector\Rector\v7\v0\RemoveMethodCallLoadTcaRector;
use Ssch\TYPO3Rector\Rector\v7\v0\TypeHandlingServiceToTypeHandlingUtilityRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use TYPO3\CMS\Backend\Template\BigDocumentTemplate;
use TYPO3\CMS\Backend\Template\DocumentTemplate;
Expand Down Expand Up @@ -45,4 +46,6 @@
),
]),
]]);

$services->set(TypeHandlingServiceToTypeHandlingUtilityRector::class);
};
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
),
]);
}
}
28 changes: 28 additions & 0 deletions stubs/Extbase/Service/TypeHandlingService.php
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
{
}
}
20 changes: 20 additions & 0 deletions stubs/Extbase/Utility/TypeHandlingUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,24 @@ public static function hex2bin($hexadecimalData): string
{
return 'foo';
}

public static function normalizeType($type): void
{

}

public static function isLiteral($type): void
{

}

public static function isSimpleType($type): void
{

}

public static function parseType($type): void
{

}
}
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');
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;
}
}

0 comments on commit 8d1ae23

Please sign in to comment.