diff --git a/.gitignore b/.gitignore index b8b62a56c..d14abc9e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,10 @@ +!/bin/infection.sh +!/bin/php-scoper /.box_dump/ /.php-cs-fixer.cache /.phpcs-cache /.phpunit* /bin/* -!/bin/infection.sh -!/bin/php-scoper /box.json /clover.xml /fixtures/*/.box_dump/ diff --git a/src/Autoload/ComposerFileHasher.php b/src/Autoload/ComposerFileHasher.php index ea8a24b67..c44940672 100644 --- a/src/Autoload/ComposerFileHasher.php +++ b/src/Autoload/ComposerFileHasher.php @@ -20,7 +20,7 @@ use function preg_match; use function sprintf; -final class ComposerFileHasher +final readonly class ComposerFileHasher { private const ROOT_PACKAGE_NAME = '__root__'; private const PACKAGE_PATH_REGEX = '~^%s/(?[^/]+?/[^/]+?)/(?.+?)$~'; diff --git a/src/Configuration/ConfigurationFactory.php b/src/Configuration/ConfigurationFactory.php index 38ffcdf39..5a0da2fb3 100644 --- a/src/Configuration/ConfigurationFactory.php +++ b/src/Configuration/ConfigurationFactory.php @@ -51,13 +51,13 @@ use function trim; use const DIRECTORY_SEPARATOR; -final class ConfigurationFactory +final readonly class ConfigurationFactory { public const DEFAULT_FILE_NAME = 'scoper.inc.php'; public function __construct( - private readonly Filesystem $fileSystem, - private readonly SymbolsConfigurationFactory $symbolsConfigurationFactory, + private Filesystem $fileSystem, + private SymbolsConfigurationFactory $symbolsConfigurationFactory, ) { } diff --git a/src/Configuration/SymbolsConfiguration.php b/src/Configuration/SymbolsConfiguration.php index dec9e8540..7d63f2bb8 100644 --- a/src/Configuration/SymbolsConfiguration.php +++ b/src/Configuration/SymbolsConfiguration.php @@ -18,7 +18,7 @@ use Humbug\PhpScoper\Symbol\NamespaceRegistry; use Humbug\PhpScoper\Symbol\SymbolRegistry; -final class SymbolsConfiguration +final readonly class SymbolsConfiguration { use NotInstantiable; diff --git a/src/Configuration/SymbolsConfigurationFactory.php b/src/Configuration/SymbolsConfigurationFactory.php index 7ef3040ee..0a9e33807 100644 --- a/src/Configuration/SymbolsConfigurationFactory.php +++ b/src/Configuration/SymbolsConfigurationFactory.php @@ -29,9 +29,9 @@ use function strrpos; use function substr; -final class SymbolsConfigurationFactory +final readonly class SymbolsConfigurationFactory { - public function __construct(private readonly RegexChecker $regexChecker) + public function __construct(private RegexChecker $regexChecker) { } diff --git a/src/Console/Application.php b/src/Console/Application.php index f652c6f20..91251057d 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -30,7 +30,7 @@ * @private * @codeCoverageIgnore */ -final class Application implements FidryApplication +final readonly class Application implements FidryApplication { private const LOGO = <<<'ASCII' @@ -60,11 +60,11 @@ public static function create(): self } public function __construct( - private readonly Container $container, - private readonly string $version, - private readonly string $releaseDate, - private readonly bool $isAutoExitEnabled, - private readonly bool $areExceptionsCaught, + private Container $container, + private string $version, + private string $releaseDate, + private bool $isAutoExitEnabled, + private bool $areExceptionsCaught, ) { } diff --git a/src/Console/Command/InitCommand.php b/src/Console/Command/InitCommand.php index f82434a6b..cc759fcbb 100644 --- a/src/Console/Command/InitCommand.php +++ b/src/Console/Command/InitCommand.php @@ -15,7 +15,6 @@ namespace Humbug\PhpScoper\Console\Command; use Fidry\Console\Command\Command; -use Fidry\Console\Command\Configuration; use Fidry\Console\Command\Configuration as CommandConfiguration; use Fidry\Console\Input\IO; use Symfony\Component\Console\Helper\FormatterHelper; @@ -30,21 +29,21 @@ * @private * @codeCoverageIgnore */ -final class InitCommand implements Command +final readonly class InitCommand implements Command { private const CONFIG_FILE_OPT = 'config'; private const CONFIG_FILE_TEMPLATE = __DIR__.'/../../scoper.inc.php.tpl'; private const CONFIG_FILE_DEFAULT = 'scoper.inc.php'; public function __construct( - private readonly Filesystem $fileSystem, - private readonly FormatterHelper $formatterHelper, + private Filesystem $fileSystem, + private FormatterHelper $formatterHelper, ) { } public function getConfiguration(): CommandConfiguration { - return new Configuration( + return new CommandConfiguration( 'init', 'Generates a configuration file.', '', diff --git a/src/Console/Command/InspectSymbolCommand.php b/src/Console/Command/InspectSymbolCommand.php index f46172807..5c3e16eb9 100644 --- a/src/Console/Command/InspectSymbolCommand.php +++ b/src/Console/Command/InspectSymbolCommand.php @@ -41,7 +41,7 @@ /** * @private */ -final class InspectSymbolCommand implements Command +final readonly class InspectSymbolCommand implements Command { private const SYMBOL_ARG = 'symbol'; private const SYMBOL_TYPE_ARG = 'type'; @@ -49,9 +49,9 @@ final class InspectSymbolCommand implements Command private const NO_CONFIG_OPT = 'no-config'; public function __construct( - private readonly Filesystem $fileSystem, - private readonly ConfigurationFactory $configFactory, - private readonly EnrichedReflectorFactory $enrichedReflectorFactory, + private Filesystem $fileSystem, + private ConfigurationFactory $configFactory, + private EnrichedReflectorFactory $enrichedReflectorFactory, ) { } diff --git a/src/Console/ConfigLoader.php b/src/Console/ConfigLoader.php index ff3c7883d..7fc14d5a0 100644 --- a/src/Console/ConfigLoader.php +++ b/src/Console/ConfigLoader.php @@ -33,12 +33,12 @@ /** * @private */ -final class ConfigLoader +final readonly class ConfigLoader { public function __construct( - private readonly CommandRegistry $commandRegistry, - private readonly Filesystem $fileSystem, - private readonly ConfigurationFactory $configFactory, + private CommandRegistry $commandRegistry, + private Filesystem $fileSystem, + private ConfigurationFactory $configFactory, ) { } diff --git a/src/Console/ConsoleScoper.php b/src/Console/ConsoleScoper.php index bdc8d922f..5e484a05e 100644 --- a/src/Console/ConsoleScoper.php +++ b/src/Console/ConsoleScoper.php @@ -43,14 +43,14 @@ /** * @private */ -final class ConsoleScoper +final readonly class ConsoleScoper { private const VENDOR_DIR_PATTERN = '~((?:.*)\\'.DIRECTORY_SEPARATOR.'vendor)\\'.DIRECTORY_SEPARATOR.'.*~'; public function __construct( - private readonly Filesystem $fileSystem, - private readonly Application $application, - private readonly ScoperFactory $scoperFactory, + private Filesystem $fileSystem, + private Application $application, + private ScoperFactory $scoperFactory, ) { } diff --git a/src/Patcher/PatcherChain.php b/src/Patcher/PatcherChain.php index 4d7f99a9a..27806bae4 100644 --- a/src/Patcher/PatcherChain.php +++ b/src/Patcher/PatcherChain.php @@ -16,7 +16,7 @@ use function array_reduce; -final class PatcherChain implements Patcher +final readonly class PatcherChain implements Patcher { /** * @param array<(callable(string, string, string): string)|Patcher> $patchers diff --git a/src/PhpParser/NodeTraverser.php b/src/PhpParser/NodeTraverser.php index 0e7efdd4b..666e58072 100644 --- a/src/PhpParser/NodeTraverser.php +++ b/src/PhpParser/NodeTraverser.php @@ -35,9 +35,9 @@ /** * @private */ -final class NodeTraverser implements NodeTraverserInterface +final readonly class NodeTraverser implements NodeTraverserInterface { - public function __construct(private readonly NodeTraverserInterface $decoratedTraverser) + public function __construct(private NodeTraverserInterface $decoratedTraverser) { } diff --git a/src/PhpParser/NodeVisitor/Resolver/IdentifierResolver.php b/src/PhpParser/NodeVisitor/Resolver/IdentifierResolver.php index 9547769f3..e5c912c33 100644 --- a/src/PhpParser/NodeVisitor/Resolver/IdentifierResolver.php +++ b/src/PhpParser/NodeVisitor/Resolver/IdentifierResolver.php @@ -32,9 +32,9 @@ * * @private */ -final class IdentifierResolver +final readonly class IdentifierResolver { - public function __construct(private readonly NameResolver $nameResolver) + public function __construct(private NameResolver $nameResolver) { } diff --git a/src/PhpParser/Printer/StandardPrinter.php b/src/PhpParser/Printer/StandardPrinter.php index d0d6aae66..07e3b6cd4 100644 --- a/src/PhpParser/Printer/StandardPrinter.php +++ b/src/PhpParser/Printer/StandardPrinter.php @@ -16,9 +16,9 @@ use PhpParser\PrettyPrinterAbstract; -final class StandardPrinter implements Printer +final readonly class StandardPrinter implements Printer { - public function __construct(private readonly PrettyPrinterAbstract $decoratedPrinter) + public function __construct(private PrettyPrinterAbstract $decoratedPrinter) { } diff --git a/src/PhpParser/StringNodePrefixer.php b/src/PhpParser/StringNodePrefixer.php index c2c68084c..d70cda0ab 100644 --- a/src/PhpParser/StringNodePrefixer.php +++ b/src/PhpParser/StringNodePrefixer.php @@ -22,9 +22,9 @@ /** * @private */ -final class StringNodePrefixer +final readonly class StringNodePrefixer { - public function __construct(private readonly PhpScoper $scoper) + public function __construct(private PhpScoper $scoper) { } @@ -40,7 +40,7 @@ public function prefixStringValue(String_ $node): void } $node->value = $newValue; - } catch (PhpParserError $error) { + } catch (PhpParserError) { // Continue without scoping the heredoc which for some reasons contains invalid PHP code } } diff --git a/src/PhpParser/UseStmtName.php b/src/PhpParser/UseStmtName.php index 6739c8703..fab0b1ca9 100644 --- a/src/PhpParser/UseStmtName.php +++ b/src/PhpParser/UseStmtName.php @@ -21,9 +21,9 @@ use function count; use function sprintf; -final class UseStmtName +final readonly class UseStmtName { - public function __construct(private readonly Name $name) + public function __construct(private Name $name) { } diff --git a/src/Scoper/Composer/AutoloadPrefixer.php b/src/Scoper/Composer/AutoloadPrefixer.php index 74afc85b6..a5e57a841 100644 --- a/src/Scoper/Composer/AutoloadPrefixer.php +++ b/src/Scoper/Composer/AutoloadPrefixer.php @@ -29,11 +29,11 @@ /** * @private */ -final class AutoloadPrefixer +final readonly class AutoloadPrefixer { public function __construct( - private readonly string $prefix, - private readonly EnrichedReflector $enrichedReflector, + private string $prefix, + private EnrichedReflector $enrichedReflector, ) { } diff --git a/src/Scoper/Composer/InstalledPackagesScoper.php b/src/Scoper/Composer/InstalledPackagesScoper.php index 2ec8160e1..17b8f3ad2 100644 --- a/src/Scoper/Composer/InstalledPackagesScoper.php +++ b/src/Scoper/Composer/InstalledPackagesScoper.php @@ -27,13 +27,13 @@ use const JSON_PRETTY_PRINT; use const JSON_THROW_ON_ERROR; -final class InstalledPackagesScoper implements Scoper +final readonly class InstalledPackagesScoper implements Scoper { private const COMPOSER_INSTALLED_FILE_PATTERN = '/composer(\/|\\\\)installed\.json$/'; public function __construct( - private readonly Scoper $decoratedScoper, - private readonly AutoloadPrefixer $autoloadPrefixer, + private Scoper $decoratedScoper, + private AutoloadPrefixer $autoloadPrefixer, ) { } diff --git a/src/Scoper/Composer/JsonFileScoper.php b/src/Scoper/Composer/JsonFileScoper.php index ba6023587..13081cbfc 100644 --- a/src/Scoper/Composer/JsonFileScoper.php +++ b/src/Scoper/Composer/JsonFileScoper.php @@ -25,11 +25,11 @@ use const JSON_PRETTY_PRINT; use const JSON_THROW_ON_ERROR; -final class JsonFileScoper implements Scoper +final readonly class JsonFileScoper implements Scoper { public function __construct( - private readonly Scoper $decoratedScoper, - private readonly AutoloadPrefixer $autoloadPrefixer, + private Scoper $decoratedScoper, + private AutoloadPrefixer $autoloadPrefixer, ) { } diff --git a/src/Scoper/PatchScoper.php b/src/Scoper/PatchScoper.php index c0fad5af3..9ccd9d045 100644 --- a/src/Scoper/PatchScoper.php +++ b/src/Scoper/PatchScoper.php @@ -17,12 +17,12 @@ use Humbug\PhpScoper\Patcher\Patcher; use function func_get_args; -final class PatchScoper implements Scoper +final readonly class PatchScoper implements Scoper { public function __construct( - private readonly Scoper $decoratedScoper, - private readonly string $prefix, - private readonly Patcher $patcher, + private Scoper $decoratedScoper, + private string $prefix, + private Patcher $patcher, ) { } diff --git a/src/Scoper/PhpScoper.php b/src/Scoper/PhpScoper.php index 3d5b48d13..c7366202e 100644 --- a/src/Scoper/PhpScoper.php +++ b/src/Scoper/PhpScoper.php @@ -25,7 +25,7 @@ use function ltrim; use function preg_match as native_preg_match; -final class PhpScoper implements Scoper +final readonly class PhpScoper implements Scoper { private const FILE_PATH_PATTERN = '/\.php$/'; private const NOT_FILE_BINARY = '/\..+?$/'; @@ -33,11 +33,11 @@ final class PhpScoper implements Scoper private const PHP_BINARY = '/^#!.+?php.*\n{1,}<\?php/'; public function __construct( - private readonly Parser $parser, - private readonly Scoper $decoratedScoper, - private readonly TraverserFactory $traverserFactory, - private readonly Printer $printer, - private readonly Lexer $lexer, + private Parser $parser, + private Scoper $decoratedScoper, + private TraverserFactory $traverserFactory, + private Printer $printer, + private Lexer $lexer, ) { } diff --git a/src/Scoper/Symfony/XmlScoper.php b/src/Scoper/Symfony/XmlScoper.php index ba836e0fe..e15dd2fdc 100644 --- a/src/Scoper/Symfony/XmlScoper.php +++ b/src/Scoper/Symfony/XmlScoper.php @@ -31,17 +31,17 @@ /** * Scopes the Symfony XML configuration files. */ -final class XmlScoper implements Scoper +final readonly class XmlScoper implements Scoper { private const XML_EXTENSION_REGEX = '/\.xml$/i'; private const NAMESPACE_PATTERN = '/(?:[^\\\\]+(?\\\\(?:\\\\)?))))"/'; private const SINGLE_CLASS_PATTERN = '/(?:(?(?:[\p{L}_\d]+(?\\\\(?:\\\\)?))):)|(?(?:[\p{L}_\d]+(?\\\\(?:\\\\)?)+)+[\p{L}_\d]+)/u'; public function __construct( - private readonly Scoper $decoratedScoper, - private readonly string $prefix, - private readonly EnrichedReflector $enrichedReflector, - private readonly SymbolsRegistry $symbolsRegistry, + private Scoper $decoratedScoper, + private string $prefix, + private EnrichedReflector $enrichedReflector, + private SymbolsRegistry $symbolsRegistry, ) { } diff --git a/src/Scoper/Symfony/YamlScoper.php b/src/Scoper/Symfony/YamlScoper.php index d9d0e898c..8d703bacc 100644 --- a/src/Scoper/Symfony/YamlScoper.php +++ b/src/Scoper/Symfony/YamlScoper.php @@ -31,16 +31,16 @@ /** * Scopes the Symfony YAML configuration files. */ -final class YamlScoper implements Scoper +final readonly class YamlScoper implements Scoper { private const YAML_EXTENSION_REGEX = '/\.ya?ml$/i'; private const CLASS_PATTERN = '/(?:(?(?:[\p{L}_\d]+(?\\\\(?:\\\\)?))):)|(?(?:[\p{L}_\d]+(?\\\\(?:\\\\)?)+)+[\p{L}_\d]+)/u'; public function __construct( - private readonly Scoper $decoratedScoper, - private readonly string $prefix, - private readonly EnrichedReflector $enrichedReflector, - private readonly SymbolsRegistry $symbolsRegistry, + private Scoper $decoratedScoper, + private string $prefix, + private EnrichedReflector $enrichedReflector, + private SymbolsRegistry $symbolsRegistry, ) { } diff --git a/src/Symbol/EnrichedReflector.php b/src/Symbol/EnrichedReflector.php index 96eb7b096..815b34887 100644 --- a/src/Symbol/EnrichedReflector.php +++ b/src/Symbol/EnrichedReflector.php @@ -29,7 +29,7 @@ * - exposed symbols * - whether symbols from the global namespace should be exposed or not */ -final class EnrichedReflector +final readonly class EnrichedReflector { public function __construct( private Reflector $reflector, diff --git a/src/Symbol/EnrichedReflectorFactory.php b/src/Symbol/EnrichedReflectorFactory.php index d83f5aa6c..00d4794b4 100644 --- a/src/Symbol/EnrichedReflectorFactory.php +++ b/src/Symbol/EnrichedReflectorFactory.php @@ -16,7 +16,7 @@ use Humbug\PhpScoper\Configuration\SymbolsConfiguration; -final class EnrichedReflectorFactory +final readonly class EnrichedReflectorFactory { public function __construct(private Reflector $reflector) { diff --git a/src/Symbol/NamespaceRegistry.php b/src/Symbol/NamespaceRegistry.php index c9cda0e41..31674bec9 100644 --- a/src/Symbol/NamespaceRegistry.php +++ b/src/Symbol/NamespaceRegistry.php @@ -28,7 +28,7 @@ use function trim; use const SORT_STRING; -final class NamespaceRegistry +final readonly class NamespaceRegistry { private bool $containsGlobalNamespace; diff --git a/src/Symbol/Reflector.php b/src/Symbol/Reflector.php index e57cf04e1..4b9be499b 100644 --- a/src/Symbol/Reflector.php +++ b/src/Symbol/Reflector.php @@ -23,7 +23,7 @@ /** * @private */ -final class Reflector +final readonly class Reflector { private const MISSING_CLASSES = [ // https://youtrack.jetbrains.com/issue/WI-29503 diff --git a/src/Symbol/SymbolRegistry.php b/src/Symbol/SymbolRegistry.php index bdf9048fd..c89dfa7ac 100644 --- a/src/Symbol/SymbolRegistry.php +++ b/src/Symbol/SymbolRegistry.php @@ -33,7 +33,7 @@ final class SymbolRegistry /** * @var array */ - private array $names; + private readonly array $names; /** * @param string[] $names @@ -74,8 +74,8 @@ public static function createForConstants( */ private function __construct( array $names, - private array $regexes, - private bool $constants + private readonly array $regexes, + private readonly bool $constants ) { $this->names = array_flip($names);