Skip to content

Commit ee08e09

Browse files
authored
Upgrade codebase to PHP 8.1 (#697)
1 parent 6357682 commit ee08e09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+350
-494
lines changed

rector.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Set\ValueObject\LevelSetList;
7+
8+
return static function (RectorConfig $rectorConfig): void {
9+
$rectorConfig->paths([
10+
__DIR__ . '/bin/check-composer-root-version.php',
11+
__DIR__ . '/bin/dump-composer-root-version.php',
12+
__DIR__ . '/bin/php-scoper',
13+
__DIR__ . '/bin/root-version.php',
14+
__DIR__ . '/src',
15+
__DIR__ . '/tests',
16+
]);
17+
18+
$rectorConfig->autoloadPaths([
19+
__DIR__ . '/vendor/autoload.php',
20+
__DIR__ . '/vendor-bin/rector/vendor/autoload.php',
21+
]);
22+
23+
$rectorConfig->importNames();
24+
25+
$rectorConfig->sets([
26+
LevelSetList::UP_TO_PHP_81,
27+
]);
28+
29+
$rectorConfig->skip([
30+
'NullToStrictStringFuncCallArgRector'
31+
]);
32+
};

src/Autoload/ScoperAutoloadGenerator.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,9 @@ final class ScoperAutoloadGenerator
4343
/** @var non-empty-string */
4444
private static string $eol;
4545

46-
private SymbolsRegistry $registry;
47-
48-
public function __construct(SymbolsRegistry $registry)
46+
public function __construct(private readonly SymbolsRegistry $registry)
4947
{
5048
self::$eol = chr(10);
51-
52-
$this->registry = $registry;
5349
}
5450

5551
public function dump(): string

src/Configuration/Configuration.php

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,10 @@ final class Configuration
2323
{
2424
private const PREFIX_PATTERN = '/^[\p{L}\d_\\\\]+$/u';
2525

26-
/**
27-
* @var non-empty-string|null
28-
*/
29-
private ?string $path;
30-
3126
/**
3227
* @var non-empty-string
3328
*/
34-
private string $prefix;
35-
36-
private array $filesWithContents;
37-
private array $excludedFilesWithContents;
38-
private Patcher $patcher;
39-
private SymbolsConfiguration $symbolsConfiguration;
29+
private readonly string $prefix;
4030

4131
/**
4232
* @param non-empty-string|null $path Absolute path to the configuration file loaded.
@@ -49,21 +39,15 @@ final class Configuration
4939
* the second its contents
5040
*/
5141
public function __construct(
52-
?string $path,
42+
private ?string $path,
5343
string $prefix,
54-
array $filesWithContents,
55-
array $excludedFilesWithContents,
56-
Patcher $patcher,
57-
SymbolsConfiguration $symbolsConfiguration
44+
private array $filesWithContents,
45+
private array $excludedFilesWithContents,
46+
private Patcher $patcher,
47+
private SymbolsConfiguration $symbolsConfiguration
5848
) {
5949
self::validatePrefix($prefix);
60-
61-
$this->path = $path;
6250
$this->prefix = $prefix;
63-
$this->filesWithContents = $filesWithContents;
64-
$this->excludedFilesWithContents = $excludedFilesWithContents;
65-
$this->patcher = $patcher;
66-
$this->symbolsConfiguration = $symbolsConfiguration;
6751
}
6852

6953
/**

src/Configuration/ConfigurationFactory.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use function array_key_exists;
2828
use function array_keys;
2929
use function array_map;
30-
use function array_merge;
3130
use function array_unique;
3231
use function array_unshift;
3332
use function bin2hex;
@@ -56,15 +55,10 @@ final class ConfigurationFactory
5655
{
5756
public const DEFAULT_FILE_NAME = 'scoper.inc.php';
5857

59-
private Filesystem $fileSystem;
60-
private SymbolsConfigurationFactory $configurationWhitelistFactory;
61-
6258
public function __construct(
63-
Filesystem $fileSystem,
64-
SymbolsConfigurationFactory $configurationWhitelistFactory
59+
private readonly Filesystem $fileSystem,
60+
private readonly SymbolsConfigurationFactory $configurationWhitelistFactory,
6561
) {
66-
$this->fileSystem = $fileSystem;
67-
$this->configurationWhitelistFactory = $configurationWhitelistFactory;
6862
}
6963

7064
/**
@@ -127,10 +121,10 @@ public function createWithPaths(Configuration $config, array $paths): Configurat
127121
return new Configuration(
128122
$config->getPath(),
129123
$config->getPrefix(),
130-
array_merge(
131-
$config->getFilesWithContents(),
132-
$filesWithContents,
133-
),
124+
[
125+
...$config->getFilesWithContents(),
126+
...$filesWithContents,
127+
],
134128
$config->getExcludedFilesWithContents(),
135129
$config->getPatcher(),
136130
$config->getSymbolsConfiguration(),

src/Configuration/SymbolsConfiguration.php

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,6 @@
1919

2020
final class SymbolsConfiguration
2121
{
22-
private bool $exposeGlobalConstants;
23-
private bool $exposeGlobalClasses;
24-
private bool $exposeGlobalFunctions;
25-
26-
private NamespaceRegistry $excludedNamespaces;
27-
private NamespaceRegistry $exposedNamespaces;
28-
29-
private SymbolRegistry $exposedClasses;
30-
private SymbolRegistry $exposedFunctions;
31-
private SymbolRegistry $exposedConstants;
32-
33-
private SymbolRegistry $excludedClasses;
34-
private SymbolRegistry $excludedFunctions;
35-
private SymbolRegistry $excludedConstants;
36-
3722
public static function create(
3823
bool $exposeGlobalConstants = false,
3924
bool $exposeGlobalClasses = false,
@@ -47,7 +32,7 @@ public static function create(
4732
?SymbolRegistry $exposedConstants = null,
4833
?SymbolRegistry $excludedClasses = null,
4934
?SymbolRegistry $excludedFunctions = null,
50-
?SymbolRegistry $excludedConstants = null
35+
?SymbolRegistry $excludedConstants = null,
5136
): self {
5237
return new self(
5338
$exposeGlobalConstants,
@@ -65,29 +50,18 @@ public static function create(
6550
}
6651

6752
private function __construct(
68-
bool $exposeGlobalConstants,
69-
bool $exposeGlobalClasses,
70-
bool $exposeGlobalFunctions,
71-
NamespaceRegistry $excludedNamespaces,
72-
NamespaceRegistry $exposedNamespaces,
73-
SymbolRegistry $exposedClasses,
74-
SymbolRegistry $exposedFunctions,
75-
SymbolRegistry $exposedConstants,
76-
SymbolRegistry $excludedClasses,
77-
SymbolRegistry $excludedFunctions,
78-
SymbolRegistry $excludedConstants
53+
private bool $exposeGlobalConstants,
54+
private bool $exposeGlobalClasses,
55+
private bool $exposeGlobalFunctions,
56+
private NamespaceRegistry $excludedNamespaces,
57+
private NamespaceRegistry $exposedNamespaces,
58+
private SymbolRegistry $exposedClasses,
59+
private SymbolRegistry $exposedFunctions,
60+
private SymbolRegistry $exposedConstants,
61+
private SymbolRegistry $excludedClasses,
62+
private SymbolRegistry $excludedFunctions,
63+
private SymbolRegistry $excludedConstants,
7964
) {
80-
$this->exposeGlobalConstants = $exposeGlobalConstants;
81-
$this->exposeGlobalClasses = $exposeGlobalClasses;
82-
$this->exposeGlobalFunctions = $exposeGlobalFunctions;
83-
$this->excludedNamespaces = $excludedNamespaces;
84-
$this->exposedNamespaces = $exposedNamespaces;
85-
$this->exposedClasses = $exposedClasses;
86-
$this->exposedFunctions = $exposedFunctions;
87-
$this->exposedConstants = $exposedConstants;
88-
$this->excludedClasses = $excludedClasses;
89-
$this->excludedFunctions = $excludedFunctions;
90-
$this->excludedConstants = $excludedConstants;
9165
}
9266

9367
public function shouldExposeGlobalConstants(): bool

src/Configuration/SymbolsConfigurationFactory.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,16 @@
3434
use function Safe\preg_match as native_preg_match;
3535
use function sprintf;
3636
use function str_contains;
37+
use function str_ends_with;
3738
use function str_replace;
3839
use function strtolower;
3940
use function substr;
4041
use function trim;
4142

4243
final class SymbolsConfigurationFactory
4344
{
44-
private RegexChecker $regexChecker;
45-
46-
public function __construct(RegexChecker $regexChecker)
45+
public function __construct(private readonly RegexChecker $regexChecker)
4746
{
48-
$this->regexChecker = $regexChecker;
4947
}
5048

5149
public function createSymbolsConfiguration(array $config): SymbolsConfiguration
@@ -304,7 +302,7 @@ private static function parseLegacyExposedElements(array $elements, array $exclu
304302

305303
self::assertValidElement($element);
306304

307-
if ('\*' === substr($element, -2)) {
305+
if (str_ends_with($element, '\*')) {
308306
$excludedNamespaceNames[] = strtolower(substr($element, 0, -2));
309307
} elseif ('*' === $element) {
310308
$excludedNamespaceNames[] = '';

src/Console/Application.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ final class Application implements FidryApplication
4545

4646
private const RELEASE_DATE_PLACEHOLDER = '@release-date@';
4747

48-
private Container $container;
49-
private string $version;
50-
private string $releaseDate;
51-
private bool $isAutoExitEnabled;
52-
private bool $areExceptionsCaught;
53-
5448
public static function create(): self
5549
{
5650
return new self(
@@ -65,17 +59,12 @@ public static function create(): self
6559
}
6660

6761
public function __construct(
68-
Container $container,
69-
string $version,
70-
string $releaseDate,
71-
bool $isAutoExitEnabled,
72-
bool $areExceptionsCaught
62+
private readonly Container $container,
63+
private readonly string $version,
64+
private readonly string $releaseDate,
65+
private readonly bool $isAutoExitEnabled,
66+
private readonly bool $areExceptionsCaught,
7367
) {
74-
$this->container = $container;
75-
$this->version = $version;
76-
$this->releaseDate = $releaseDate;
77-
$this->isAutoExitEnabled = $isAutoExitEnabled;
78-
$this->areExceptionsCaught = $areExceptionsCaught;
7968
}
8069

8170
public function getName(): string

src/Console/Command/AddPrefixCommand.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,14 @@ final class AddPrefixCommand implements Command, CommandAware
5353
private const STOP_ON_FAILURE_OPT = 'stop-on-failure';
5454
private const CONFIG_FILE_OPT = 'config';
5555
private const NO_CONFIG_OPT = 'no-config';
56-
57-
private Filesystem $fileSystem;
58-
private ScoperFactory $scoperFactory;
5956
private bool $init = false;
60-
private Application $application;
61-
private ConfigurationFactory $configFactory;
6257

6358
public function __construct(
64-
Filesystem $fileSystem,
65-
ScoperFactory $scoperFactory,
66-
Application $application,
67-
ConfigurationFactory $configFactory
59+
private readonly Filesystem $fileSystem,
60+
private readonly ScoperFactory $scoperFactory,
61+
private readonly Application $application,
62+
private readonly ConfigurationFactory $configFactory,
6863
) {
69-
$this->fileSystem = $fileSystem;
70-
$this->scoperFactory = $scoperFactory;
71-
$this->application = $application;
72-
$this->configFactory = $configFactory;
7364
}
7465

7566
public function getConfiguration(): CommandConfiguration

src/Console/Command/InitCommand.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,10 @@ final class InitCommand implements Command
3636
private const CONFIG_FILE_TEMPLATE = __DIR__.'/../../scoper.inc.php.tpl';
3737
private const CONFIG_FILE_DEFAULT = 'scoper.inc.php';
3838

39-
private Filesystem $fileSystem;
40-
private FormatterHelper $formatterHelper;
41-
4239
public function __construct(
43-
Filesystem $fileSystem,
44-
FormatterHelper $formatterHelper
40+
private readonly Filesystem $fileSystem,
41+
private readonly FormatterHelper $formatterHelper,
4542
) {
46-
$this->fileSystem = $fileSystem;
47-
$this->formatterHelper = $formatterHelper;
4843
}
4944

5045
public function getConfiguration(): CommandConfiguration

0 commit comments

Comments
 (0)