-
-
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.
- Loading branch information
1 parent
85a72f9
commit 5948a1b
Showing
5 changed files
with
136 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
71 changes: 71 additions & 0 deletions
71
src/Rector/v9/v4/GeneralUtilityGetHostNameToGetIndpEnvRector.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,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Rector\v9\v4; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\StaticCall; | ||
use PHPStan\Type\ObjectType; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @changelog https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/9.4/Deprecation-85759-GeneralUtilitygetHostName.html | ||
* @see \Ssch\TYPO3Rector\Tests\Rector\v9\v4\GeneralUtilityGetHostNameToGetIndpEnvRector\GeneralUtilityGetHostNameToGetIndpEnvRectorTest | ||
*/ | ||
final class GeneralUtilityGetHostNameToGetIndpEnvRector extends AbstractRector | ||
{ | ||
/** | ||
* @return array<class-string<Node>> | ||
*/ | ||
public function getNodeTypes(): array | ||
{ | ||
return [StaticCall::class]; | ||
} | ||
|
||
/** | ||
* @param StaticCall $node | ||
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
if (! $this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType( | ||
$node, | ||
new ObjectType('TYPO3\CMS\Core\Utility\GeneralUtility') | ||
)) { | ||
return null; | ||
} | ||
|
||
if (! $this->isName($node->name, 'getHostname')) { | ||
return null; | ||
} | ||
|
||
$node->name = new Node\Identifier('getIndpEnv'); | ||
$node->args = $this->nodeFactory->createArgs(['HTTP_HOST']); | ||
|
||
return $node; | ||
} | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return new RuleDefinition( | ||
'Migrating method call GeneralUtility::getHostname() to GeneralUtility::getIndpEnv(\'HTTP_HOST\')', | ||
[ | ||
new CodeSample( | ||
<<<'CODE_SAMPLE' | ||
\TYPO3\CMS\Core\Utility\GeneralUtility::getHostname(); | ||
CODE_SAMPLE | ||
, | ||
<<<'CODE_SAMPLE' | ||
\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST') | ||
CODE_SAMPLE | ||
), | ||
|
||
] | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...GeneralUtilityGetHostNameToGetIndpEnvRector/Fixture/get_host_name_to_get_indp_env.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,19 @@ | ||
<?php | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v9\v4\GeneralUtilityGetHostNameToGetIndpEnvRector\Fixture; | ||
|
||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
GeneralUtility::getHostName(); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v9\v4\GeneralUtilityGetHostNameToGetIndpEnvRector\Fixture; | ||
|
||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
GeneralUtility::getIndpEnv('HTTP_HOST'); | ||
|
||
?> |
33 changes: 33 additions & 0 deletions
33
...lUtilityGetHostNameToGetIndpEnvRector/GeneralUtilityGetHostNameToGetIndpEnvRectorTest.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v9\v4\GeneralUtilityGetHostNameToGetIndpEnvRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class GeneralUtilityGetHostNameToGetIndpEnvRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Rector/v9/v4/GeneralUtilityGetHostNameToGetIndpEnvRector/config/configured_rule.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$containerConfigurator->import(__DIR__ . '/../../../../../../config/config_test.php'); | ||
|
||
$services = $containerConfigurator->services(); | ||
$services->set(\Ssch\TYPO3Rector\Rector\v9\v4\GeneralUtilityGetHostNameToGetIndpEnvRector::class); | ||
}; |