-
-
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] Use method getTSConfig instead of property userTS (#1593)
Resolves: #1054
- Loading branch information
1 parent
bcb3fe1
commit 6b07c66
Showing
8 changed files
with
214 additions
and
14 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
78 changes: 78 additions & 0 deletions
78
src/Rector/v9/v3/PropertyUserTsToMethodGetTsConfigOfBackendUserAuthenticationRector.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,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Rector\v9\v3; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\PropertyFetch; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Rector\Core\RectorDefinition\CodeSample; | ||
use Rector\Core\RectorDefinition\RectorDefinition; | ||
use Ssch\TYPO3Rector\Helper\Typo3NodeResolver; | ||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; | ||
|
||
/** | ||
* @see https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/9.3/Deprecation-84984-ProtectedUserTSconfigPropertiesInBackendUserAuthentication.html | ||
*/ | ||
final class PropertyUserTsToMethodGetTsConfigOfBackendUserAuthenticationRector extends AbstractRector | ||
{ | ||
/** | ||
* @var Typo3NodeResolver | ||
*/ | ||
private $typo3NodeResolver; | ||
|
||
public function __construct(Typo3NodeResolver $typo3NodeResolver) | ||
{ | ||
$this->typo3NodeResolver = $typo3NodeResolver; | ||
} | ||
|
||
public function getNodeTypes(): array | ||
{ | ||
return [PropertyFetch::class]; | ||
} | ||
|
||
/** | ||
* @param PropertyFetch $node | ||
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
if ($this->shouldSkip($node)) { | ||
return null; | ||
} | ||
|
||
if (! $this->isName($node->name, 'userTS')) { | ||
return null; | ||
} | ||
|
||
return $this->createMethodCall($node->var, 'getTSConfig'); | ||
} | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
public function getDefinition(): RectorDefinition | ||
{ | ||
return new RectorDefinition('Use method getTSConfig instead of property userTS', [ | ||
new CodeSample(<<<'PHP' | ||
if(is_array($GLOBALS['BE_USER']->userTS['tx_news.']) && $GLOBALS['BE_USER']->userTS['tx_news.']['singleCategoryAcl'] === '1') { | ||
return true; | ||
} | ||
PHP | ||
, <<<'PHP' | ||
if(is_array($GLOBALS['BE_USER']->getTSConfig()['tx_news.']) && $GLOBALS['BE_USER']->getTSConfig()['tx_news.']['singleCategoryAcl'] === '1') { | ||
return true; | ||
} | ||
PHP | ||
), | ||
]); | ||
} | ||
|
||
private function shouldSkip(PropertyFetch $node): bool | ||
{ | ||
if ($this->typo3NodeResolver->isPropertyFetchOnAnyPropertyOfGlobals($node, Typo3NodeResolver::BACKEND_USER)) { | ||
return false; | ||
} | ||
return ! $this->isObjectType($node->var, BackendUserAuthentication::class); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace TYPO3\CMS\Core\Authentication; | ||
|
||
if (class_exists(BackendUserAuthentication::class)) { | ||
return; | ||
} | ||
|
||
|
||
final class BackendUserAuthentication | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
public $userTS = [ | ||
'tx_news.' => [ | ||
'singleCategoryAcl' => 1 | ||
] | ||
]; | ||
|
||
public function getTSConfig($objectString = null, $config = null): array | ||
{ | ||
return []; | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
...oMethodGetTsConfigOfBackendUserAuthentication/Fixture/backend_user_user_ts_config.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,15 @@ | ||
<?php | ||
|
||
if(is_array($GLOBALS['BE_USER']->userTS['tx_news.']) && $GLOBALS['BE_USER']->userTS['tx_news.']['singleCategoryAcl'] === '1') { | ||
return true; | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
if(is_array($GLOBALS['BE_USER']->getTSConfig()['tx_news.']) && $GLOBALS['BE_USER']->getTSConfig()['tx_news.']['singleCategoryAcl'] === '1') { | ||
return true; | ||
} | ||
|
||
?> |
51 changes: 51 additions & 0 deletions
51
...tTsConfigOfBackendUserAuthentication/Fixture/backend_user_user_ts_config_in_class.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,51 @@ | ||
<?php | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v9\v3\PropertyUserTsToMethodGetTsConfigOfBackendUserAuthentication\Fixture; | ||
|
||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; | ||
|
||
class MyClass | ||
{ | ||
/** | ||
* @var BackendUserAuthentication | ||
*/ | ||
private $backendUserAuthentication; | ||
|
||
public function __construct() | ||
{ | ||
$this->backendUserAuthentication = $GLOBALS['BE_USER']; | ||
} | ||
|
||
public function getUserTsConfig(): array | ||
{ | ||
return $this->backendUserAuthentication->userTS; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v9\v3\PropertyUserTsToMethodGetTsConfigOfBackendUserAuthentication\Fixture; | ||
|
||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; | ||
|
||
class MyClass | ||
{ | ||
/** | ||
* @var BackendUserAuthentication | ||
*/ | ||
private $backendUserAuthentication; | ||
|
||
public function __construct() | ||
{ | ||
$this->backendUserAuthentication = $GLOBALS['BE_USER']; | ||
} | ||
|
||
public function getUserTsConfig(): array | ||
{ | ||
return $this->backendUserAuthentication->getTSConfig(); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...Authentication/PropertyUserTsToMethodGetTsConfigOfBackendUserAuthenticationRectorTest.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\v9\v3\PropertyUserTsToMethodGetTsConfigOfBackendUserAuthentication; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Ssch\TYPO3Rector\Rector\v9\v3\PropertyUserTsToMethodGetTsConfigOfBackendUserAuthenticationRector; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class PropertyUserTsToMethodGetTsConfigOfBackendUserAuthenticationRectorTest 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 PropertyUserTsToMethodGetTsConfigOfBackendUserAuthenticationRector::class; | ||
} | ||
} |
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