Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Nov 18, 2023
1 parent e72c1d7 commit 91be936
Show file tree
Hide file tree
Showing 28 changed files with 79 additions and 80 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
2 changes: 1 addition & 1 deletion src/Autoload/ComposerFileHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/(?<vendor>[^/]+?/[^/]+?)/(?<path>.+?)$~';
Expand Down
6 changes: 3 additions & 3 deletions src/Configuration/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/SymbolsConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Humbug\PhpScoper\Symbol\NamespaceRegistry;
use Humbug\PhpScoper\Symbol\SymbolRegistry;

final class SymbolsConfiguration
final readonly class SymbolsConfiguration
{
use NotInstantiable;

Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/SymbolsConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
12 changes: 6 additions & 6 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @private
* @codeCoverageIgnore
*/
final class Application implements FidryApplication
final readonly class Application implements FidryApplication
{
private const LOGO = <<<'ASCII'
Expand Down Expand Up @@ -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,
) {
}

Expand Down
9 changes: 4 additions & 5 deletions src/Console/Command/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.',
'',
Expand Down
8 changes: 4 additions & 4 deletions src/Console/Command/InspectSymbolCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@
/**
* @private
*/
final class InspectSymbolCommand implements Command
final readonly class InspectSymbolCommand implements Command
{
private const SYMBOL_ARG = 'symbol';
private const SYMBOL_TYPE_ARG = 'type';
private const CONFIG_FILE_OPT = 'config';
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,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/Console/ConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/Console/ConsoleScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Patcher/PatcherChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/PhpParser/NodeTraverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/PhpParser/NodeVisitor/Resolver/IdentifierResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/PhpParser/Printer/StandardPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/PhpParser/StringNodePrefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand All @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpParser/UseStmtName.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/Scoper/Composer/AutoloadPrefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Scoper/Composer/InstalledPackagesScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Scoper/Composer/JsonFileScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/Scoper/PatchScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
12 changes: 6 additions & 6 deletions src/Scoper/PhpScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
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 = '/\..+?$/';
private const PHP_TAG = '/^<\?php/';
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,
) {
}

Expand Down
10 changes: 5 additions & 5 deletions src/Scoper/Symfony/XmlScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '/<prototype.*\snamespace="(?:(?<namespace>(?:[^\\\\]+(?<separator>\\\\(?:\\\\)?))))"/';
private const SINGLE_CLASS_PATTERN = '/(?:(?<singleClass>(?:[\p{L}_\d]+(?<singleSeparator>\\\\(?:\\\\)?))):)|(?<class>(?:[\p{L}_\d]+(?<separator>\\\\(?:\\\\)?)+)+[\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,
) {
}

Expand Down
10 changes: 5 additions & 5 deletions src/Scoper/Symfony/YamlScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '/(?:(?<singleClass>(?:[\p{L}_\d]+(?<singleSeparator>\\\\(?:\\\\)?))):)|(?<class>(?:[\p{L}_\d]+(?<separator>\\\\(?:\\\\)?)+)+[\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,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symbol/EnrichedReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 91be936

Please sign in to comment.