Skip to content

Commit 7411acf

Browse files
authored
[FEATURE] Add MigrateTypoScriptGetDataPathFractor (#369)
Resolves: sabbelasichon/typo3-rector#327
1 parent 85dfae5 commit 7411acf

File tree

7 files changed

+132
-1
lines changed

7 files changed

+132
-1
lines changed

packages/typo3-fractor/config/typo3-14.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use a9f\Typo3Fractor\TYPO3v14\Fluid\ChangeLogoutHandlingInFeLoginFractor;
66
use a9f\Typo3Fractor\TYPO3v14\Htaccess\RemoveUploadsFromDefaultHtaccessFractor;
77
use a9f\Typo3Fractor\TYPO3v14\TypoScript\MigrateTypoScriptConditionGetTSFEFractor;
8+
use a9f\Typo3Fractor\TYPO3v14\TypoScript\MigrateTypoScriptGetDataPathFractor;
89
use a9f\Typo3Fractor\TYPO3v14\TypoScript\RemoveExposeNonexistentUserInForgotPasswordDialogSettingInFeLoginFractor;
910
use a9f\Typo3Fractor\TYPO3v14\TypoScript\RemoveFrontendAssetConcatenationAndCompressionFractor;
1011
use a9f\Typo3Fractor\TYPO3v14\TypoScript\RemoveModWebLayoutDefLangBindingFractor;
@@ -22,4 +23,5 @@
2223
$services->set(RemoveUploadsFromDefaultHtaccessFractor::class);
2324
$services->set(MigrateTypoScriptConditionGetTSFEFractor::class);
2425
$services->set(RemoveFrontendAssetConcatenationAndCompressionFractor::class);
26+
$services->set(MigrateTypoScriptGetDataPathFractor::class);
2527
};

packages/typo3-fractor/docs/typo3-fractor-rules.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 36 Rules Overview
1+
# 37 Rules Overview
22

33
## AbstractMessageGetSeverityFluidFractor
44

@@ -433,6 +433,22 @@ Migrate TypoScript condition function `getTSFE()`
433433

434434
<br>
435435

436+
## MigrateTypoScriptGetDataPathFractor
437+
438+
Migrate TypoScript getData \"path\"
439+
440+
- class: [`a9f\Typo3Fractor\TYPO3v14\TypoScript\MigrateTypoScriptGetDataPathFractor`](../rules/TYPO3v14/TypoScript/MigrateTypoScriptGetDataPathFractor.php)
441+
442+
```diff
443+
page.20 = TEXT
444+
page.20 {
445+
- data = path : EXT:core/Resources/Public/Icons/Extension.svg
446+
+ data = asset : EXT:core/Resources/Public/Icons/Extension.svg
447+
}
448+
```
449+
450+
<br>
451+
436452
## RemoveConfigDisablePageExternalUrlFractor
437453

438454
Remove config.disablePageExternalUrl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
page.20 = TEXT
2+
page.20 {
3+
data = path : EXT:core/Resources/Public/Icons/Extension.svg
4+
}
5+
-----
6+
page.20 = TEXT
7+
page.20 {
8+
data = asset : EXT:core/Resources/Public/Icons/Extension.svg
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
page.20 = TEXT
2+
page.20.data = path:EXT:core/Resources/Public/Icons/Extension.svg
3+
-----
4+
page.20 = TEXT
5+
page.20.data = asset:EXT:core/Resources/Public/Icons/Extension.svg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace a9f\Typo3Fractor\Tests\TYPO3v14\TypoScript\MigrateTypoScriptGetDataPathFractor;
6+
7+
use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
10+
final class MigrateTypoScriptGetDataPathFractorTest extends AbstractFractorTestCase
11+
{
12+
#[DataProvider('provideData')]
13+
public function test(string $filePath): void
14+
{
15+
$this->doTestFile($filePath);
16+
}
17+
18+
public static function provideData(): \Iterator
19+
{
20+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixtures', '*.typoscript.fixture');
21+
}
22+
23+
public function provideConfigFilePath(): string
24+
{
25+
return __DIR__ . '/config/fractor.php';
26+
}
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use a9f\Fractor\Configuration\FractorConfiguration;
6+
use a9f\Fractor\ValueObject\Indent;
7+
use a9f\FractorXml\Configuration\XmlProcessorOption;
8+
use a9f\Typo3Fractor\TYPO3v14\TypoScript\MigrateTypoScriptGetDataPathFractor;
9+
10+
return FractorConfiguration::configure()
11+
->withOptions([
12+
XmlProcessorOption::INDENT_CHARACTER => Indent::STYLE_TAB,
13+
XmlProcessorOption::INDENT_SIZE => 1,
14+
])
15+
->withRules([MigrateTypoScriptGetDataPathFractor::class]);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace a9f\Typo3Fractor\TYPO3v14\TypoScript;
6+
7+
use a9f\FractorTypoScript\AbstractTypoScriptFractor;
8+
use Helmich\TypoScriptParser\Parser\AST\Operator\Assignment;
9+
use Helmich\TypoScriptParser\Parser\AST\Statement;
10+
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
11+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
12+
13+
/**
14+
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/14.0/Deprecation-107537-GetDataPath.html
15+
* @see \a9f\Typo3Fractor\Tests\TYPO3v14\TypoScript\MigrateTypoScriptGetDataPathFractor\MigrateTypoScriptGetDataPathFractorTest
16+
*/
17+
final class MigrateTypoScriptGetDataPathFractor extends AbstractTypoScriptFractor
18+
{
19+
public function getRuleDefinition(): RuleDefinition
20+
{
21+
return new RuleDefinition('Migrate TypoScript getData \"path\"', [new CodeSample(
22+
<<<'CODE_SAMPLE'
23+
page.20 = TEXT
24+
page.20 {
25+
data = path : EXT:core/Resources/Public/Icons/Extension.svg
26+
}
27+
CODE_SAMPLE
28+
,
29+
<<<'CODE_SAMPLE'
30+
page.20 = TEXT
31+
page.20 {
32+
data = asset : EXT:core/Resources/Public/Icons/Extension.svg
33+
}
34+
CODE_SAMPLE
35+
)]);
36+
}
37+
38+
public function refactor(Statement $statement): ?Statement
39+
{
40+
if (! $statement instanceof Assignment) {
41+
return null;
42+
}
43+
44+
if (! str_ends_with($statement->object->relativeName, 'data')) {
45+
return null;
46+
}
47+
48+
$scalar = $statement->value;
49+
50+
if (preg_match('/^\s*path\s*:/i', $scalar->value)) {
51+
$scalar->value = (string) preg_replace('/^(\s*)path(\s*:)/i', '$1asset$2', $scalar->value);
52+
return $statement;
53+
}
54+
55+
return null;
56+
}
57+
}

0 commit comments

Comments
 (0)