-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
…ative
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs; | ||
|
||
use Nette\Utils\Strings; | ||
use Rector\Core\ValueObject\Application\File; | ||
use Ssch\TYPO3Rector\Contract\FileProcessor\Fluid\Rector\FluidRectorInterface; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
final class ReplaceExtensionPathAbsoluteFluidRector implements FluidRectorInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private const PATTERN_INLINE = '#{(v|vhs):extension\.path\.absolute\(extensionName:(\s?)["\']([a-z0-9_]+)["\']\)}Resources\/Public\/(\S+)\.([a-z0-9]{2,4})#ims'; | ||
/** | ||
* @var string | ||
*/ | ||
private const PATTERN_LEFTOVERS = '#(v|vhs):(extension\.path\.absolute)#ims'; | ||
|
||
public function transform(File $file): void | ||
{ | ||
$content = $file->getFileContent(); | ||
|
||
$content = Strings::replace( | ||
$content, | ||
self::PATTERN_INLINE, | ||
'{f:uri.resource(extensionName:\'\3\',path:\'\4.\5\',absolute:1)}' | ||
); | ||
|
||
if (Strings::matchAll($content, self::PATTERN_LEFTOVERS)) { | ||
$this->rectorOutputStyle->warning('There\'s occurrences of v:extension.path.absolute that couldn\'t be migrated automatically. Migrate them manually!'); | ||
Check failure on line 36 in src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathAbsoluteFluidRector.php GitHub Actions / PHPStan
Check failure on line 36 in src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathAbsoluteFluidRector.php GitHub Actions / PHPStan
Check failure on line 36 in src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathAbsoluteFluidRector.php GitHub Actions / PHPStan
|
||
} | ||
|
||
$file->changeFileContent($content); | ||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return new RuleDefinition('Use <f:uri.resource> instead of <v:extension.path.absolute>', [ | ||
new CodeSample( | ||
<<<'CODE_SAMPLE' | ||
{v:extension.path.absolute(extensionName:'my_extension')}Resources/Public/Css/style.css | ||
CODE_SAMPLE | ||
, | ||
<<<'CODE_SAMPLE' | ||
{f:uri.resource(extensionName:'my_extension',path:'Css/style.css',absolute:1)} | ||
CODE_SAMPLE | ||
), | ||
]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs; | ||
|
||
use Nette\Utils\Strings; | ||
use Rector\Core\ValueObject\Application\File; | ||
use Ssch\TYPO3Rector\Contract\FileProcessor\Fluid\Rector\FluidRectorInterface; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
final class ReplaceExtensionPathRelativeFluidRector implements FluidRectorInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private const PATTERN_INLINE = '#{(v|vhs):extension\.path\.relative\(extensionName:(\s?)["\']([a-z0-9_]+)["\']\)}Resources\/Public\/(\S+)\.([a-z0-9]{2,4})#ims'; | ||
/** | ||
* @var string | ||
*/ | ||
private const PATTERN_LEFTOVERS = '#(v|vhs):(extension\.path\.relative)#ims'; | ||
|
||
public function transform(File $file): void | ||
{ | ||
$content = $file->getFileContent(); | ||
|
||
$content = Strings::replace( | ||
$content, | ||
self::PATTERN_INLINE, | ||
'{f:uri.resource(extensionName:\'\3\',path:\'\4.\5\')}' | ||
); | ||
|
||
if (Strings::matchAll($content, self::PATTERN_LEFTOVERS)) { | ||
$this->rectorOutputStyle->warning('There\'s occurrences of v:extension.path.relative that couldn\'t be migrated automatically. Migrate them manually!'); | ||
Check failure on line 36 in src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathRelativeFluidRector.php GitHub Actions / PHPStan
Check failure on line 36 in src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathRelativeFluidRector.php GitHub Actions / PHPStan
Check failure on line 36 in src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathRelativeFluidRector.php GitHub Actions / PHPStan
|
||
} | ||
|
||
$file->changeFileContent($content); | ||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return new RuleDefinition('Use <f:uri.resource> instead of <v:extension.path.relative>', [ | ||
new CodeSample( | ||
<<<'CODE_SAMPLE' | ||
{v:extension.path.relative(extensionName:'my_extension')}Resources/Public/Css/style.css | ||
CODE_SAMPLE | ||
, | ||
<<<'CODE_SAMPLE' | ||
{f:uri.resource(extensionName:'my_extension',path:'Css/style.css')} | ||
CODE_SAMPLE | ||
), | ||
]); | ||
} | ||
} |