Skip to content

Commit 1a13175

Browse files
committed
[WIP][TASK] Add PHP 8.4 support via Rector
1 parent 7e25f2a commit 1a13175

28 files changed

+151
-252
lines changed

.github/workflows/Test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
typo3: [ '^12.4.0', '^13.4.0' ]
22-
php: [ '8.2', '8.3' ]
22+
php: [ '8.2', '8.3', '8.4' ]
2323
dependency-version: [ lowest, stable ]
2424
experimental: [ false ]
2525

res/php/autoload-include.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
declare(strict_types=1);
3+
4+
use Helhum\TYPO3\ConfigHandling\Xclass\ConfigurationManager;
5+
use TYPO3\CMS\Core\Configuration\ConfigurationManager as CoreConfigurationManager;
6+
27
if (!isset($_ENV['TYPO3_TESTING']) && getenv('TYPO3_TESTING') === false) {
3-
class_alias(\Helhum\TYPO3\ConfigHandling\Xclass\ConfigurationManager::class, \TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
8+
class_alias(ConfigurationManager::class, CoreConfigurationManager::class);
49
}

src/Command/EncryptSettingsCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protected function configure()
3737
->setDescription('Encrypts values in a given config file');
3838
}
3939

40+
#[\Override]
4041
public function isEnabled(): bool
4142
{
4243
return class_exists(Key::class);

src/Command/ExtractSettingsCommand.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,14 @@
3535

3636
class ExtractSettingsCommand extends Command
3737
{
38-
/**
39-
* @var ConfigurationManager
40-
*/
41-
private $configurationManager;
38+
private readonly ConfigurationManager $configurationManager;
4239

43-
/**
44-
* @var ConfigExtractor
45-
*/
46-
private $configExtractor;
40+
private readonly ConfigExtractor $configExtractor;
4741

4842
public function __construct(
49-
$name = null,
50-
ConfigurationManager $configurationManager = null,
51-
ConfigExtractor $configExtractor = null
43+
?string $name = null,
44+
?ConfigurationManager $configurationManager = null,
45+
?ConfigExtractor $configExtractor = null
5246
) {
5347
parent::__construct($name);
5448
$this->configurationManager = $configurationManager ?: new ConfigurationManager();
@@ -81,7 +75,7 @@ protected function configure()
8175
protected function execute(InputInterface $input, OutputInterface $output): int
8276
{
8377
$systemSettingsFile = $this->configurationManager->getSystemConfigurationFileLocation();
84-
if ((new Typo3Version())->getMajorVersion() < 12) {
78+
if (new Typo3Version()->getMajorVersion() < 12) {
8579
$systemSettingsFile = $this->configurationManager->getLocalConfigurationFileLocation();
8680
}
8781
if ($this->isAutoGenerated($systemSettingsFile)) {
@@ -94,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9488
foreach ($input->getOption('ignore-path') as $path) {
9589
try {
9690
$configuration = Config::removeValue($configuration, $path);
97-
} catch (PathDoesNotExistException $e) {
91+
} catch (PathDoesNotExistException) {
9892
// We ignore it, when the path does not exist
9993
}
10094
}
@@ -116,6 +110,6 @@ private function isAutoGenerated(string $file): bool
116110
return false;
117111
}
118112

119-
return strpos(file_get_contents($file), 'Auto generated by helhum/typo3-config-handling') !== false;
113+
return str_contains(file_get_contents($file), 'Auto generated by helhum/typo3-config-handling');
120114
}
121115
}

src/Composer/InstallerScript/DumpSettings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ private function allowGeneration(string $file): bool
9797
return true;
9898
}
9999

100-
return strpos(file_get_contents($file), 'Auto generated by helhum/typo3-config-handling') !== false;
100+
return str_contains(file_get_contents($file), 'Auto generated by helhum/typo3-config-handling');
101101
}
102102
}

src/Composer/InstallerScripts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
class InstallerScripts implements InstallerScriptsRegistration
3232
{
33-
public static function register(Event $event, ScriptDispatcher $scriptDispatcher)
33+
public static function register(Event $event, ScriptDispatcher $scriptDispatcher): void
3434
{
3535
self::exposeInstallSettingsFile();
3636
$scriptDispatcher->addInstallerScript(

src/ConfigCleaner.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ private function removeIdenticalValues(array $baseConfig, array $referenceConfig
5858

5959
return array_filter(
6060
$cleanedBaseConfig,
61-
function ($value) {
62-
return !(is_array($value) && empty($value));
63-
}
61+
fn($value): bool => !(is_array($value) && empty($value))
6462
);
6563
}
6664

src/ConfigDumper.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ private function generateCommentBlock(string $comment, string $commentChar = '//
7575

7676
return implode(
7777
chr(10),
78-
array_map(function ($line) use ($commentChar) {
79-
return $commentChar . ' ' . $line;
80-
}, explode(chr(10), $comment))
78+
array_map(
79+
fn(string $line): string => $commentChar . ' ' . $line,
80+
explode(chr(10), $comment))
8181
) . chr(10);
8282
}
8383

@@ -129,9 +129,9 @@ public function getPhpCode($value, array $referenceConfig = [], array $path = []
129129
return $code;
130130
}
131131

132-
private function isPlaceHolder($value): bool
132+
private function isPlaceHolder(string $value): bool
133133
{
134-
return is_string($value) && preg_match(PlaceholderValue::PLACEHOLDER_PATTERN, $value);
134+
return preg_match(PlaceholderValue::PLACEHOLDER_PATTERN, $value);
135135
}
136136

137137
private function getPhpCodeForPlaceholder(string $value, array $referenceConfig, array $path = [], bool $forKey = false): string
@@ -156,7 +156,7 @@ private function getPhpCodeForPlaceholder(string $value, array $referenceConfig,
156156
$phpCode = $this->getPhpCode($subConfig, $referenceConfig, $path);
157157
break;
158158
case 'global':
159-
$globalPath = str_getcsv($placeholderInfo['accessor'], '.');
159+
$globalPath = str_getcsv($placeholderInfo['accessor'], '.', escape: '\\');
160160
$phpCode = '$GLOBALS[\'' . implode('\'][\'', array_map([$this, 'escapePhpValue'], $globalPath)) . '\']';
161161
break;
162162
}
@@ -172,7 +172,7 @@ private function escapePhpValue(string $value): string
172172
return addcslashes($value, '\\\'');
173173
}
174174

175-
private function extractPlaceHolder($value, array $types = null): array
175+
private function extractPlaceHolder(string $value, ?array $types = null): array
176176
{
177177
if (!$this->isPlaceHolder($value)) {
178178
return [];

src/ConfigExtractor.php

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,31 @@
2727

2828
class ConfigExtractor
2929
{
30-
/**
31-
* @var ConfigDumper
32-
*/
33-
private $configDumper;
30+
private readonly ConfigDumper $configDumper;
3431

35-
/**
36-
* @var ConfigCleaner
37-
*/
38-
private $configCleaner;
32+
private readonly ConfigCleaner $configCleaner;
3933

40-
/**
41-
* @var ConfigLoader
42-
*/
43-
private $configLoader;
34+
private readonly ConfigLoader $configLoader;
4435

45-
/**
46-
* @var ConfigurationReaderFactory
47-
*/
48-
private $readerFactory;
36+
private readonly ConfigurationReaderFactory $readerFactory;
4937

50-
/**
51-
* @var string
52-
*/
53-
private $overrideConfigFile;
38+
private readonly string $overrideConfigFile;
5439

5540
public function __construct(
56-
ConfigDumper $configDumper = null,
57-
ConfigCleaner $configCleaner = null,
58-
ConfigLoader $configLoader = null,
59-
ConfigurationReaderFactory $readerFactory = null,
60-
string $overrideConfigFile = null
41+
?ConfigDumper $configDumper = null,
42+
?ConfigCleaner $configCleaner = null,
43+
?ConfigLoader $configLoader = null,
44+
?ConfigurationReaderFactory $readerFactory = null,
45+
?string $overrideConfigFile = null
6146
) {
62-
$this->configDumper = $configDumper ?: new ConfigDumper();
63-
$this->configCleaner = $configCleaner ?: new ConfigCleaner();
64-
$this->configLoader = $configLoader ?: new ConfigLoader(Environment::getContext()->isProduction());
65-
$this->readerFactory = $readerFactory ?: new ConfigurationReaderFactory();
47+
$this->configDumper = $configDumper ?? new ConfigDumper();
48+
$this->configCleaner = $configCleaner ?? new ConfigCleaner();
49+
$this->configLoader = $configLoader ?? new ConfigLoader(Environment::getContext()->isProduction());
50+
$this->readerFactory = $readerFactory ?? new ConfigurationReaderFactory();
6651
$this->overrideConfigFile = $overrideConfigFile ?: SettingsFiles::getOverrideSettingsFile();
6752
}
6853

69-
public function extractConfig(array $config, array $defaultConfig, string $configFile = null): bool
54+
public function extractConfig(array $config, array $defaultConfig, ?string $configFile = null): bool
7055
{
7156
$configFile = $configFile ?: $this->overrideConfigFile;
7257
$extractedConfig = false;

src/ConfigLoader.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,16 @@
3434

3535
class ConfigLoader
3636
{
37-
/**
38-
* @var bool
39-
*/
40-
private $isProduction;
41-
42-
/**
43-
* @var string
44-
*/
45-
private $settingsFile;
37+
private readonly string $settingsFile;
4638

47-
public function __construct(bool $isProduction, string $settingsFile = null)
48-
{
49-
$this->isProduction = $isProduction;
39+
public function __construct(
40+
private readonly bool $isProduction,
41+
?string $settingsFile = null
42+
) {
5043
$this->settingsFile = $settingsFile ?? SettingsFiles::getSettingsFile($this->isProduction);
5144
}
5245

53-
public function populate()
46+
public function populate(): void
5447
{
5548
$shouldCache = $this->shouldCache();
5649
$hasCache = $shouldCache ? file_exists($cacheFile = $this->getCacheFile()) : false;
@@ -108,7 +101,7 @@ public function load(): array
108101
*/
109102
public function loadBase(): array
110103
{
111-
return (new Typo3Config($this->settingsFile))->readBaseConfig();
104+
return new Typo3Config($this->settingsFile)->readBaseConfig();
112105
}
113106

114107
/**
@@ -118,7 +111,7 @@ public function loadBase(): array
118111
*/
119112
public function loadOwn(): array
120113
{
121-
return (new Typo3Config($this->settingsFile))->readOwnConfig();
114+
return new Typo3Config($this->settingsFile)->readOwnConfig();
122115
}
123116

124117
/**
@@ -128,7 +121,7 @@ public function loadOwn(): array
128121
*/
129122
public function loadOverrides(): array
130123
{
131-
return (new Typo3Config($this->settingsFile))->readOverridesConfig();
124+
return new Typo3Config($this->settingsFile)->readOverridesConfig();
132125
}
133126

134127
public function flushCache(): void

0 commit comments

Comments
 (0)