-
-
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.
[FEATURE] Introduce capabilities bit set (#4162)
Resolves: #3661
- Loading branch information
Showing
8 changed files
with
187 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector; | ||
use Rector\Renaming\ValueObject\RenameClassAndConstFetch; | ||
use TYPO3\CMS\Core\Resource\Capabilities; | ||
use TYPO3\CMS\Core\Resource\ResourceStorageInterface; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
// constants only have been moved into new Capabilities class | ||
$capabilities = [ | ||
'CAPABILITY_BROWSABLE', | ||
'CAPABILITY_PUBLIC', | ||
'CAPABILITY_WRITABLE', | ||
'CAPABILITY_HIERARCHICAL_IDENTIFIERS', | ||
]; | ||
|
||
$configuration = array_map(static fn ($capability) => new RenameClassAndConstFetch( | ||
ResourceStorageInterface::class, | ||
$capability, | ||
Capabilities::class, | ||
$capability | ||
), $capabilities); | ||
|
||
$rectorConfig->ruleWithConfiguration(RenameClassConstFetchRector::class, $configuration); | ||
}; |
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
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\TYPO313\v0; | ||
|
||
use PhpParser\Node; | ||
use Rector\Rector\AbstractRector; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-101291-IntroduceCapabilitiesBitSet.html | ||
* @see \Ssch\TYPO3Rector\Tests\Rector\v13\v0\IntroduceCapabilitiesBitSetRector\IntroduceCapabilitiesBitSetRectorTest | ||
*/ | ||
final class IntroduceCapabilitiesBitSetRector extends AbstractRector | ||
{ | ||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return new RuleDefinition('Introduce capabilities bit set', [new CodeSample( | ||
<<<'CODE_SAMPLE' | ||
use TYPO3\CMS\Core\Resource\ResourceStorageInterface; | ||
echo ResourceStorageInterface::CAPABILITY_BROWSABLE; | ||
echo ResourceStorageInterface::CAPABILITY_PUBLIC; | ||
echo ResourceStorageInterface::CAPABILITY_WRITABLE; | ||
echo ResourceStorageInterface::CAPABILITY_HIERARCHICAL_IDENTIFIERS; | ||
CODE_SAMPLE | ||
, | ||
<<<'CODE_SAMPLE' | ||
use TYPO3\CMS\Core\Resource\Capabilities; | ||
use TYPO3\CMS\Core\Resource\ResourceStorageInterface; | ||
echo Capabilities::CAPABILITY_BROWSABLE; | ||
echo Capabilities::CAPABILITY_PUBLIC; | ||
echo Capabilities::CAPABILITY_WRITABLE; | ||
echo Capabilities::CAPABILITY_HIERARCHICAL_IDENTIFIERS; | ||
CODE_SAMPLE | ||
)]); | ||
} | ||
|
||
public function getNodeTypes(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function refactor(Node $node) | ||
{ | ||
return null; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace TYPO3\CMS\Core\Resource; | ||
|
||
interface Capabilities | ||
{ | ||
|
||
public const CAPABILITY_BROWSABLE = 'CAPABILITY_BROWSABLE'; | ||
public const CAPABILITY_PUBLIC = 'CAPABILITY_PUBLIC'; | ||
public const CAPABILITY_WRITABLE = 'CAPABILITY_WRITABLE'; | ||
public const CAPABILITY_HIERARCHICAL_IDENTIFIERS = 'CAPABILITY_HIERARCHICAL_IDENTIFIERS'; | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
stubs/TYPO3/CMS/Core/Resource/ResourceStorageInterface.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,13 @@ | ||
<?php | ||
|
||
namespace TYPO3\CMS\Core\Resource; | ||
|
||
interface ResourceStorageInterface | ||
{ | ||
|
||
public const CAPABILITY_BROWSABLE = 'CAPABILITY_BROWSABLE'; | ||
public const CAPABILITY_PUBLIC = 'CAPABILITY_PUBLIC'; | ||
public const CAPABILITY_WRITABLE = 'CAPABILITY_WRITABLE'; | ||
public const CAPABILITY_HIERARCHICAL_IDENTIFIERS = 'CAPABILITY_HIERARCHICAL_IDENTIFIERS'; | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
tests/Rector/v13/v0/IntroduceCapabilitiesBitSetRector/Fixture/fixture.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,38 @@ | ||
<?php | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v13\v0\IntroduceCapabilitiesBitSetRector\Fixture; | ||
|
||
use TYPO3\CMS\Core\Resource\ResourceStorageInterface; | ||
|
||
echo ResourceStorageInterface::CAPABILITY_BROWSABLE; | ||
echo ResourceStorageInterface::CAPABILITY_PUBLIC; | ||
echo ResourceStorageInterface::CAPABILITY_WRITABLE; | ||
echo ResourceStorageInterface::CAPABILITY_HIERARCHICAL_IDENTIFIERS; | ||
|
||
function doSomething($cap) { | ||
echo $cap; | ||
} | ||
|
||
doSomething(\TYPO3\CMS\Core\Resource\ResourceStorageInterface::CAPABILITY_BROWSABLE); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v13\v0\IntroduceCapabilitiesBitSetRector\Fixture; | ||
|
||
use TYPO3\CMS\Core\Resource\Capabilities; | ||
use TYPO3\CMS\Core\Resource\ResourceStorageInterface; | ||
|
||
echo Capabilities::CAPABILITY_BROWSABLE; | ||
echo Capabilities::CAPABILITY_PUBLIC; | ||
echo Capabilities::CAPABILITY_WRITABLE; | ||
echo Capabilities::CAPABILITY_HIERARCHICAL_IDENTIFIERS; | ||
|
||
function doSomething($cap) { | ||
echo $cap; | ||
} | ||
|
||
doSomething(Capabilities::CAPABILITY_BROWSABLE); | ||
|
||
?> |
32 changes: 32 additions & 0 deletions
32
...Rector/v13/v0/IntroduceCapabilitiesBitSetRector/IntroduceCapabilitiesBitSetRectorTest.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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v13\v0\IntroduceCapabilitiesBitSetRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class IntroduceCapabilitiesBitSetRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
/** | ||
* @return Iterator<array<string>> | ||
*/ | ||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/Rector/v13/v0/IntroduceCapabilitiesBitSetRector/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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->import(__DIR__ . '/../../../../../../config/config.php'); | ||
$rectorConfig->import(__DIR__ . '/../../../../../../config/v13/introduce-capabilities-bit-set.php'); | ||
}; |