Skip to content

Commit 30cee97

Browse files
committed
[TASK] Add RemoveUseCacheHashFromTypolink fractor
1 parent 98e891e commit 30cee97

File tree

6 files changed

+114
-0
lines changed

6 files changed

+114
-0
lines changed

packages/typo3-fractor/composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"a9f/fractor-doc-generator": "^0.2",
1818
"a9f/fractor-extension-installer": "^0.2",
1919
"a9f/fractor-fluid": "^0.2",
20+
"a9f/fractor-typoscript": "^0.2",
2021
"a9f/fractor-xml": "^0.2",
2122
"a9f/fractor-yaml": "^0.2"
2223
},

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

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use a9f\Typo3Fractor\TYPO3v10\Fluid\RemoveNoCacheHashAndUseCacheHashAttributeFractor;
6+
use a9f\Typo3Fractor\TYPO3v10\TypoScript\RemoveUseCacheHashFromTypolink;
67
use a9f\Typo3Fractor\TYPO3v10\Yaml\EmailFinisherFractor;
78
use a9f\Typo3Fractor\TYPO3v10\Yaml\TranslationFileFractor;
89
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@@ -16,4 +17,5 @@
1617
$services->set(EmailFinisherFractor::class);
1718
$services->set(TranslationFileFractor::class);
1819
$services->set(RemoveNoCacheHashAndUseCacheHashAttributeFractor::class);
20+
$services->set(RemoveUseCacheHashFromTypolink::class);
1921
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
page = PAGE
2+
page.10 = TEXT
3+
page.10.value = Link to page 23
4+
page.10.typolink {
5+
parameter = 23
6+
useCacheHash = 1
7+
}
8+
9+
page.20 = TEXT
10+
page.20.value = Link to page 42
11+
page.20.typolink.parameter = 42
12+
page.20.typolink.useCacheHash = 1
13+
-----
14+
page = PAGE
15+
page.10 = TEXT
16+
page.10.value = Link to page 23
17+
page.10.typolink {
18+
parameter = 23
19+
}
20+
21+
page.20 = TEXT
22+
page.20.value = Link to page 42
23+
page.20.typolink.parameter = 42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace a9f\Typo3Fractor\Tests\TYPO3v10\Fluid;
6+
7+
use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase;
8+
use Iterator;
9+
use PHPUnit\Framework\Attributes\DataProvider;
10+
11+
final class RemoveUseCacheHashFromTypolinkTest extends AbstractFractorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixtures', '*.typoscript');
22+
}
23+
24+
public function provideConfigFilePath(): ?string
25+
{
26+
return __DIR__ . '/config/fractor.php';
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use a9f\Fractor\Configuration\FractorConfiguration;
6+
use a9f\Typo3Fractor\TYPO3v10\TypoScript\RemoveUseCacheHashFromTypolink;
7+
8+
return FractorConfiguration::configure()
9+
->withRules([RemoveUseCacheHashFromTypolink::class]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace a9f\Typo3Fractor\TYPO3v10\TypoScript;
6+
7+
use a9f\FractorTypoScript\AbstractTypoScriptFractor;
8+
use a9f\FractorTypoScript\TypoScriptStatementsIterator;
9+
use Helmich\TypoScriptParser\Parser\AST\Operator\Assignment;
10+
use Helmich\TypoScriptParser\Parser\AST\Statement;
11+
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
12+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
13+
14+
/**
15+
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.0/Deprecation-88406-SetCacheHashnoCacheHashOptionsInViewHelpersAndUriBuilder.html
16+
*/
17+
final class RemoveUseCacheHashFromTypolink extends AbstractTypoScriptFractor
18+
{
19+
public function refactor(Statement $statement): null|Statement|int
20+
{
21+
if (! $statement instanceof Assignment) {
22+
return $statement;
23+
}
24+
25+
// for some weird reason, "foo.bar.baz = 1" leads to "relativeName" being "foo.bar.baz"
26+
if (! str_ends_with($statement->object->absoluteName, '.typolink.useCacheHash')) {
27+
return $statement;
28+
}
29+
30+
$this->hasChanged = true;
31+
return TypoScriptStatementsIterator::REMOVE_NODE;
32+
}
33+
34+
public function getRuleDefinition(): RuleDefinition
35+
{
36+
return new RuleDefinition('Remove useCacheHash TypoScript setting', [new CodeSample(
37+
<<<'CODE_SAMPLE'
38+
typolink {
39+
parameter = 3
40+
useCacheHash = 1
41+
}
42+
CODE_SAMPLE
43+
,
44+
<<<'CODE_SAMPLE'
45+
typolink {
46+
parameter = 3
47+
}
48+
CODE_SAMPLE
49+
)]);
50+
}
51+
}

0 commit comments

Comments
 (0)