Skip to content

Commit

Permalink
[FEATURE] Introduce capabilities bit set (#4162)
Browse files Browse the repository at this point in the history
Resolves: #3661
  • Loading branch information
dev-rke authored Mar 8, 2024
1 parent b8904fd commit ee6bc41
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 0 deletions.
28 changes: 28 additions & 0 deletions config/v13/introduce-capabilities-bit-set.php
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);
};
2 changes: 2 additions & 0 deletions config/v13/typo3-130.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$rectorConfig->import(__DIR__ . '/../config.php');
$rectorConfig->import(__DIR__ . '/extbase-strict-types-persistence-manager.php');
$rectorConfig->import(__DIR__ . '/extbase-strict-types.php');
$rectorConfig->import(__DIR__ . '/introduce-capabilities-bit-set.php');

$rectorConfig->import(__DIR__ . '/typo3-130-extbase-hash-service-core-hash-service.php');
$rectorConfig->ruleWithConfiguration(ConstantsToBackedEnumValueRector::class, [
Expand Down Expand Up @@ -105,4 +106,5 @@
$rectorConfig->rule(\Ssch\TYPO3Rector\TYPO313\v0\MigrateExtbaseHashServiceToUseCoreHashServiceRector::class);
$rectorConfig->singleton(\Ssch\TYPO3Rector\TYPO313\v0\StrictTypesPersistenceManagerRector::class);
$rectorConfig->singleton(\Ssch\TYPO3Rector\TYPO313\v0\UseStrictTypesInExtbaseActionControllerRector::class);
$rectorConfig->rule(\Ssch\TYPO3Rector\TYPO313\v0\IntroduceCapabilitiesBitSetRector::class);
};
51 changes: 51 additions & 0 deletions rules/TYPO313/v0/IntroduceCapabilitiesBitSetRector.php
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;
}
}
13 changes: 13 additions & 0 deletions stubs/TYPO3/CMS/Core/Resource/Capabilities.php
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 stubs/TYPO3/CMS/Core/Resource/ResourceStorageInterface.php
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';

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

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

0 comments on commit ee6bc41

Please sign in to comment.