Skip to content

Commit 8e3ba4b

Browse files
OskarStarknicolas-grekas
authored andcommitted
[Config] Use CPP
1 parent 8789646 commit 8e3ba4b

19 files changed

+69
-102
lines changed

Builder/ClassBuilder.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121
class ClassBuilder
2222
{
23-
private string $namespace;
2423
private string $name;
2524

2625
/** @var Property[] */
@@ -33,9 +32,10 @@ class ClassBuilder
3332
private array $implements = [];
3433
private bool $allowExtraKeys = false;
3534

36-
public function __construct(string $namespace, string $name)
37-
{
38-
$this->namespace = $namespace;
35+
public function __construct(
36+
private string $namespace,
37+
string $name,
38+
) {
3939
$this->name = ucfirst($this->camelCase($name)).'Config';
4040
}
4141

Builder/ConfigBuilderGenerator.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ class ConfigBuilderGenerator implements ConfigBuilderGeneratorInterface
3737
* @var ClassBuilder[]
3838
*/
3939
private array $classes = [];
40-
private string $outputDir;
4140

42-
public function __construct(string $outputDir)
43-
{
44-
$this->outputDir = $outputDir;
41+
public function __construct(
42+
private string $outputDir,
43+
) {
4544
}
4645

4746
/**

Builder/Method.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
*/
2121
class Method
2222
{
23-
private string $content;
24-
25-
public function __construct(string $content)
26-
{
27-
$this->content = $content;
23+
public function __construct(
24+
private string $content,
25+
) {
2826
}
2927

3028
public function getContent(): string

Builder/Property.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@
2020
*/
2121
class Property
2222
{
23-
private string $name;
24-
private string $originalName;
2523
private bool $array = false;
2624
private bool $scalarsAllowed = false;
2725
private ?string $type = null;
2826
private ?string $content = null;
2927

30-
public function __construct(string $originalName, string $name)
31-
{
32-
$this->name = $name;
33-
$this->originalName = $originalName;
28+
public function __construct(
29+
private string $originalName,
30+
private string $name,
31+
) {
3432
}
3533

3634
public function getName(): string

ConfigCache.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@
2525
*/
2626
class ConfigCache extends ResourceCheckerConfigCache
2727
{
28-
private bool $debug;
29-
3028
/**
3129
* @param string $file The absolute cache path
3230
* @param bool $debug Whether debugging is enabled or not
3331
*/
34-
public function __construct(string $file, bool $debug)
35-
{
36-
$this->debug = $debug;
37-
32+
public function __construct(
33+
string $file,
34+
private bool $debug,
35+
) {
3836
$checkers = [];
3937
if (true === $this->debug) {
4038
$checkers = [new SelfCheckingResourceChecker()];

ConfigCacheFactory.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
*/
2323
class ConfigCacheFactory implements ConfigCacheFactoryInterface
2424
{
25-
private bool $debug;
26-
2725
/**
2826
* @param bool $debug The debug flag to pass to ConfigCache
2927
*/
30-
public function __construct(bool $debug)
31-
{
32-
$this->debug = $debug;
28+
public function __construct(
29+
private bool $debug,
30+
) {
3331
}
3432

3533
public function cache(string $file, callable $callback): ConfigCacheInterface

Definition/BaseNode.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ abstract class BaseNode implements NodeInterface
3030
private static array $placeholders = [];
3131

3232
protected string $name;
33-
protected ?NodeInterface $parent;
3433
protected array $normalizationClosures = [];
3534
protected array $normalizedTypes = [];
3635
protected array $finalValidationClosures = [];
@@ -39,22 +38,22 @@ abstract class BaseNode implements NodeInterface
3938
protected array $deprecation = [];
4039
protected array $equivalentValues = [];
4140
protected array $attributes = [];
42-
protected string $pathSeparator;
4341

4442
private mixed $handlingPlaceholder = null;
4543

4644
/**
4745
* @throws \InvalidArgumentException if the name contains a period
4846
*/
49-
public function __construct(?string $name, NodeInterface $parent = null, string $pathSeparator = self::DEFAULT_PATH_SEPARATOR)
50-
{
47+
public function __construct(
48+
?string $name,
49+
protected ?NodeInterface $parent = null,
50+
protected string $pathSeparator = self::DEFAULT_PATH_SEPARATOR,
51+
) {
5152
if (str_contains($name = (string) $name, $pathSeparator)) {
5253
throw new \InvalidArgumentException('The name must not contain ".'.$pathSeparator.'".');
5354
}
5455

5556
$this->name = $name;
56-
$this->parent = $parent;
57-
$this->pathSeparator = $pathSeparator;
5857
}
5958

6059
/**

Definition/Builder/ExprBuilder.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ class ExprBuilder
3030
public ?\Closure $ifPart = null;
3131
public ?\Closure $thenPart = null;
3232

33-
protected NodeDefinition $node;
34-
35-
public function __construct(NodeDefinition $node)
36-
{
37-
$this->node = $node;
33+
public function __construct(
34+
protected NodeDefinition $node,
35+
) {
3836
}
3937

4038
/**

Definition/Builder/MergeBuilder.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ class MergeBuilder
2121
public bool $allowFalse = false;
2222
public bool $allowOverwrite = true;
2323

24-
protected NodeDefinition $node;
25-
26-
public function __construct(NodeDefinition $node)
27-
{
28-
$this->node = $node;
24+
public function __construct(
25+
protected NodeDefinition $node,
26+
) {
2927
}
3028

3129
/**

Definition/Builder/NormalizationBuilder.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ class NormalizationBuilder
2222
public array $declaredTypes = [];
2323
public array $remappings = [];
2424

25-
protected NodeDefinition $node;
26-
27-
public function __construct(NodeDefinition $node)
28-
{
29-
$this->node = $node;
25+
public function __construct(
26+
protected NodeDefinition $node,
27+
) {
3028
}
3129

3230
/**

Definition/Builder/ValidationBuilder.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ class ValidationBuilder
2020
{
2121
public array $rules = [];
2222

23-
protected NodeDefinition $node;
24-
25-
public function __construct(NodeDefinition $node)
26-
{
27-
$this->node = $node;
23+
public function __construct(
24+
protected NodeDefinition $node,
25+
) {
2826
}
2927

3028
/**

Loader/Loader.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
abstract class Loader implements LoaderInterface
2222
{
2323
protected LoaderResolverInterface $resolver;
24-
protected ?string $env;
2524

26-
public function __construct(string $env = null)
27-
{
28-
$this->env = $env;
25+
public function __construct(
26+
protected ?string $env = null,
27+
) {
2928
}
3029

3130
public function getResolver(): LoaderResolverInterface

Loader/ParamConfigurator.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
*/
1919
class ParamConfigurator
2020
{
21-
private string $name;
22-
23-
public function __construct(string $name)
24-
{
25-
$this->name = $name;
21+
public function __construct(
22+
private string $name,
23+
) {
2624
}
2725

2826
public function __toString(): string

Resource/ClassExistenceResource.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424
class ClassExistenceResource implements SelfCheckingResourceInterface
2525
{
26-
private string $resource;
2726
private ?array $exists = null;
2827

2928
private static int $autoloadLevel = 0;
@@ -34,9 +33,10 @@ class ClassExistenceResource implements SelfCheckingResourceInterface
3433
* @param string $resource The fully-qualified class name
3534
* @param bool|null $exists Boolean when the existence check has already been done
3635
*/
37-
public function __construct(string $resource, bool $exists = null)
38-
{
39-
$this->resource = $resource;
36+
public function __construct(
37+
private string $resource,
38+
bool $exists = null,
39+
) {
4040
if (null !== $exists) {
4141
$this->exists = [$exists, null];
4242
}

Resource/DirectoryResource.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
2121
class DirectoryResource implements SelfCheckingResourceInterface
2222
{
2323
private string $resource;
24-
private ?string $pattern;
2524

2625
/**
2726
* @param string $resource The file path to the resource
2827
* @param string|null $pattern A pattern to restrict monitored files
2928
*
3029
* @throws \InvalidArgumentException
3130
*/
32-
public function __construct(string $resource, string $pattern = null)
33-
{
31+
public function __construct(
32+
string $resource,
33+
private ?string $pattern = null,
34+
) {
3435
$resolvedResource = realpath($resource) ?: (file_exists($resource) ? $resource : false);
35-
$this->pattern = $pattern;
3636

3737
if (false === $resolvedResource || !is_dir($resolvedResource)) {
3838
throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist.', $resource));

Resource/FileExistenceResource.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@
2323
*/
2424
class FileExistenceResource implements SelfCheckingResourceInterface
2525
{
26-
private string $resource;
27-
2826
private bool $exists;
2927

3028
/**
3129
* @param string $resource The file path to the resource
3230
*/
33-
public function __construct(string $resource)
34-
{
35-
$this->resource = $resource;
31+
public function __construct(
32+
private string $resource,
33+
) {
3634
$this->exists = file_exists($resource);
3735
}
3836

Resource/GlobResource.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface
2929
{
3030
private string $prefix;
31-
private string $pattern;
32-
private bool $recursive;
3331
private string $hash;
34-
private bool $forExclusion;
3532
private array $excludedPrefixes;
3633
private int $globBrace;
3734

@@ -42,13 +39,15 @@ class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface
4239
*
4340
* @throws \InvalidArgumentException
4441
*/
45-
public function __construct(string $prefix, string $pattern, bool $recursive, bool $forExclusion = false, array $excludedPrefixes = [])
46-
{
42+
public function __construct(
43+
string $prefix,
44+
private string $pattern,
45+
private bool $recursive,
46+
private bool $forExclusion = false,
47+
array $excludedPrefixes = [],
48+
) {
4749
ksort($excludedPrefixes);
4850
$resolvedPrefix = realpath($prefix) ?: (file_exists($prefix) ? $prefix : false);
49-
$this->pattern = $pattern;
50-
$this->recursive = $recursive;
51-
$this->forExclusion = $forExclusion;
5251
$this->excludedPrefixes = $excludedPrefixes;
5352
$this->globBrace = \defined('GLOB_BRACE') ? \GLOB_BRACE : 0;
5453

ResourceCheckerConfigCache.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,14 @@
2323
*/
2424
class ResourceCheckerConfigCache implements ConfigCacheInterface
2525
{
26-
private string $file;
27-
28-
/**
29-
* @var iterable<mixed, ResourceCheckerInterface>
30-
*/
31-
private iterable $resourceCheckers;
32-
3326
/**
3427
* @param string $file The absolute cache path
3528
* @param iterable<mixed, ResourceCheckerInterface> $resourceCheckers The ResourceCheckers to use for the freshness check
3629
*/
37-
public function __construct(string $file, iterable $resourceCheckers = [])
38-
{
39-
$this->file = $file;
40-
$this->resourceCheckers = $resourceCheckers;
30+
public function __construct(
31+
private string $file,
32+
private iterable $resourceCheckers = [],
33+
) {
4134
}
4235

4336
public function getPath(): string

ResourceCheckerConfigCacheFactory.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
*/
2020
class ResourceCheckerConfigCacheFactory implements ConfigCacheFactoryInterface
2121
{
22-
private iterable $resourceCheckers = [];
23-
2422
/**
2523
* @param iterable<int, ResourceCheckerInterface> $resourceCheckers
2624
*/
27-
public function __construct(iterable $resourceCheckers = [])
28-
{
29-
$this->resourceCheckers = $resourceCheckers;
25+
public function __construct(
26+
private iterable $resourceCheckers = [],
27+
) {
3028
}
3129

3230
public function cache(string $file, callable $callable): ConfigCacheInterface

0 commit comments

Comments
 (0)