Skip to content

Commit 0a73ac7

Browse files
authored
Merge pull request #718 from samsonasik/update-php-up-to-php8
Update to PHP 8.0+ syntax in `src/`, where viable
2 parents b38f401 + f916f65 commit 0a73ac7

25 files changed

+64
-136
lines changed

src/ProxyManager/Autoloader/Autoloader.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@
1212

1313
class Autoloader implements AutoloaderInterface
1414
{
15-
protected FileLocatorInterface $fileLocator;
16-
protected ClassNameInflectorInterface $classNameInflector;
17-
18-
public function __construct(FileLocatorInterface $fileLocator, ClassNameInflectorInterface $classNameInflector)
15+
public function __construct(protected FileLocatorInterface $fileLocator, protected ClassNameInflectorInterface $classNameInflector)
1916
{
20-
$this->fileLocator = $fileLocator;
21-
$this->classNameInflector = $classNameInflector;
2217
}
2318

2419
public function __invoke(string $className): bool

src/ProxyManager/Exception/InvalidProxiedClassException.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,10 @@ public static function abstractProtectedMethodsNotSupported(ReflectionClass $ref
3636
implode(
3737
"\n",
3838
array_map(
39-
static function (ReflectionMethod $reflectionMethod): string {
40-
return $reflectionMethod->getDeclaringClass()->getName() . '::' . $reflectionMethod->getName();
41-
},
39+
static fn (ReflectionMethod $reflectionMethod): string => $reflectionMethod->getDeclaringClass()->getName() . '::' . $reflectionMethod->getName(),
4240
array_filter(
4341
$reflection->getMethods(),
44-
static function (ReflectionMethod $method): bool {
45-
return $method->isAbstract() && $method->isProtected();
46-
}
42+
static fn (ReflectionMethod $method): bool => $method->isAbstract() && $method->isProtected()
4743
)
4844
)
4945
)

src/ProxyManager/Exception/UnsupportedProxiedClassException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public static function nonReferenceableLocalizedReflectionProperties(
3636
return new self(sprintf(
3737
'Cannot create references for following properties of class %s: %s',
3838
$class->getName(),
39-
implode(', ', array_map(static function (ReflectionProperty $property): string {
40-
return $property->getName();
41-
}, $properties->getInstanceProperties()))
39+
implode(', ', array_map(static fn (ReflectionProperty $property): string => $property->getName(), $properties->getInstanceProperties()))
4240
));
4341
}
4442
}

src/ProxyManager/Factory/AccessInterceptorScopeLocalizerFactory.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
use ProxyManager\Signature\Exception\InvalidSignatureException;
1414
use ProxyManager\Signature\Exception\MissingSignatureException;
1515

16-
use function get_class;
17-
1816
/**
1917
* Factory responsible of producing proxy objects
2018
*/
@@ -67,7 +65,7 @@ public function createProxy(
6765
array $prefixInterceptors = [],
6866
array $suffixInterceptors = []
6967
): AccessInterceptorInterface {
70-
$proxyClassName = $this->generateProxy(get_class($instance));
68+
$proxyClassName = $this->generateProxy($instance::class);
7169

7270
/**
7371
* We ignore type checks here, since `staticProxyConstructor` is not interfaced (by design)

src/ProxyManager/Factory/AccessInterceptorValueHolderFactory.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
use ProxyManager\Signature\Exception\InvalidSignatureException;
1616
use ProxyManager\Signature\Exception\MissingSignatureException;
1717

18-
use function get_class;
19-
2018
/**
2119
* Factory responsible of producing proxy objects
2220
*/
@@ -69,7 +67,7 @@ public function createProxy(
6967
array $prefixInterceptors = [],
7068
array $suffixInterceptors = []
7169
): AccessInterceptorValueHolderInterface {
72-
$proxyClassName = $this->generateProxy(get_class($instance));
70+
$proxyClassName = $this->generateProxy($instance::class);
7371

7472
/**
7573
* We ignore type checks here, since `staticProxyConstructor` is not interfaced (by design)

src/ProxyManager/Factory/NullObjectFactory.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use ProxyManager\Signature\Exception\InvalidSignatureException;
1313
use ProxyManager\Signature\Exception\MissingSignatureException;
1414

15-
use function get_class;
1615
use function is_object;
1716

1817
/**
@@ -45,7 +44,7 @@ public function __construct(?Configuration $configuration = null)
4544
*/
4645
public function createProxy(object|string $instanceOrClassName): NullObjectInterface
4746
{
48-
$className = is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName;
47+
$className = is_object($instanceOrClassName) ? $instanceOrClassName::class : $instanceOrClassName;
4948
$proxyClassName = $this->generateProxy($className);
5049

5150
/**

src/ProxyManager/Factory/RemoteObject/Adapter/BaseAdapter.php

+5-13
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,16 @@
1414
*/
1515
abstract class BaseAdapter implements AdapterInterface
1616
{
17-
protected Client $client;
18-
19-
/**
20-
* Service name mapping
21-
*
22-
* @var array<string, string>
23-
*/
24-
protected array $map = [];
25-
2617
/**
2718
* Constructor
2819
*
2920
* @param array<string, string> $map map of service names to their aliases
3021
*/
31-
public function __construct(Client $client, array $map = [])
32-
{
33-
$this->client = $client;
34-
$this->map = $map;
22+
public function __construct(
23+
protected Client $client,
24+
// Service name mapping
25+
protected array $map = []
26+
) {
3527
}
3628

3729
/**

src/ProxyManager/Factory/RemoteObjectFactory.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,23 @@
1313
use ProxyManager\Signature\Exception\InvalidSignatureException;
1414
use ProxyManager\Signature\Exception\MissingSignatureException;
1515

16-
use function get_class;
1716
use function is_object;
1817

1918
/**
2019
* Factory responsible of producing remote proxy objects
2120
*/
2221
class RemoteObjectFactory extends AbstractBaseFactory
2322
{
24-
protected AdapterInterface $adapter;
2523
private ?RemoteObjectGenerator $generator;
2624

2725
/**
2826
* {@inheritDoc}
2927
*
30-
* @param AdapterInterface $adapter
31-
* @param Configuration $configuration
28+
* @param Configuration $configuration
3229
*/
33-
public function __construct(AdapterInterface $adapter, ?Configuration $configuration = null)
30+
public function __construct(protected AdapterInterface $adapter, ?Configuration $configuration = null)
3431
{
3532
parent::__construct($configuration);
36-
37-
$this->adapter = $adapter;
3833
$this->generator = new RemoteObjectGenerator();
3934
}
4035

@@ -54,7 +49,7 @@ public function __construct(AdapterInterface $adapter, ?Configuration $configura
5449
public function createProxy(string|object $instanceOrClassName): RemoteObjectInterface
5550
{
5651
$proxyClassName = $this->generateProxy(
57-
is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName
52+
is_object($instanceOrClassName) ? $instanceOrClassName::class : $instanceOrClassName
5853
);
5954

6055
/**

src/ProxyManager/GeneratorStrategy/FileWriterGeneratorStrategy.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121
*/
2222
class FileWriterGeneratorStrategy implements GeneratorStrategyInterface
2323
{
24-
protected FileLocatorInterface $fileLocator;
2524
private Closure $emptyErrorHandler;
2625

27-
public function __construct(FileLocatorInterface $fileLocator)
26+
public function __construct(protected FileLocatorInterface $fileLocator)
2827
{
29-
$this->fileLocator = $fileLocator;
3028
$this->emptyErrorHandler = static function (): void {
3129
};
3230
}

src/ProxyManager/Inflector/ClassNameInflector.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414

1515
final class ClassNameInflector implements ClassNameInflectorInterface
1616
{
17-
protected string $proxyNamespace;
1817
/** @var int @TODO annotation still needed for phpstan to understand this */
1918
private int $proxyMarkerLength;
2019
private string $proxyMarker;
2120
private ParameterHasher $parameterHasher;
2221

23-
public function __construct(string $proxyNamespace)
22+
public function __construct(protected string $proxyNamespace)
2423
{
25-
$this->proxyNamespace = $proxyNamespace;
2624
$this->proxyMarker = '\\' . self::PROXY_MARKER . '\\';
2725
$this->proxyMarkerLength = strlen($this->proxyMarker);
2826
$this->parameterHasher = new ParameterHasher();

src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizer/MethodGenerator/Util/InterceptorGenerator.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ public static function createInterceptedMethodBody(
6767
'{{$suffixInterceptorsName}}' => $suffixInterceptors->getName(),
6868
'{{$suffixEarlyReturnExpression}}' => ProxiedMethodReturnExpression::generate('$suffixReturnValue', $originalMethod),
6969
'{{$returnExpression}}' => ProxiedMethodReturnExpression::generate('$returnValue', $originalMethod),
70-
'{{$paramsString}}' => 'array(' . implode(', ', array_map(static function (ParameterGenerator $parameter): string {
71-
return var_export($parameter->getName(), true) . ' => $' . $parameter->getName();
72-
}, $method->getParameters())) . ')',
70+
'{{$paramsString}}' => 'array(' . implode(', ', array_map(static fn (ParameterGenerator $parameter): string => var_export($parameter->getName(), true) . ' => $' . $parameter->getName(), $method->getParameters())) . ')',
7371
];
7472

7573
return str_replace(

src/ProxyManager/ProxyGenerator/AccessInterceptorScopeLocalizerGenerator.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,10 @@ private function buildMethodInterceptor(
8989
MethodPrefixInterceptors $prefixInterceptors,
9090
MethodSuffixInterceptors $suffixInterceptors
9191
): callable {
92-
return static function (ReflectionMethod $method) use ($prefixInterceptors, $suffixInterceptors): InterceptedMethod {
93-
return InterceptedMethod::generateMethod(
94-
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
95-
$prefixInterceptors,
96-
$suffixInterceptors
97-
);
98-
};
92+
return static fn (ReflectionMethod $method): InterceptedMethod => InterceptedMethod::generateMethod(
93+
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
94+
$prefixInterceptors,
95+
$suffixInterceptors
96+
);
9997
}
10098
}

src/ProxyManager/ProxyGenerator/AccessInterceptorValueHolderGenerator.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,11 @@ private function buildMethodInterceptor(
128128
MethodSuffixInterceptors $suffixes,
129129
ValueHolderProperty $valueHolder
130130
): callable {
131-
return static function (ReflectionMethod $method) use ($prefixes, $suffixes, $valueHolder): InterceptedMethod {
132-
return InterceptedMethod::generateMethod(
133-
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
134-
$valueHolder,
135-
$prefixes,
136-
$suffixes
137-
);
138-
};
131+
return static fn (ReflectionMethod $method): InterceptedMethod => InterceptedMethod::generateMethod(
132+
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
133+
$valueHolder,
134+
$prefixes,
135+
$suffixes
136+
);
139137
}
140138
}

src/ProxyManager/ProxyGenerator/Assertion/CanProxyAssertion.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ private static function hasNoAbstractProtectedMethods(ReflectionClass $originalC
5858
{
5959
$protectedAbstract = array_filter(
6060
$originalClass->getMethods(),
61-
static function (ReflectionMethod $method): bool {
62-
return $method->isAbstract() && $method->isProtected();
63-
}
61+
static fn (ReflectionMethod $method): bool => $method->isAbstract() && $method->isProtected()
6462
);
6563

6664
if ($protectedAbstract) {

src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/CallInitializer.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ private function getPropertyDefaultsAssignments(array $properties): string
113113
return implode(
114114
"\n",
115115
array_map(
116-
function (ReflectionProperty $property): string {
117-
return ' $instance->' . $property->getName()
118-
. ' = ' . $this->getExportedPropertyDefaultValue($property) . ';';
119-
},
116+
fn (ReflectionProperty $property): string => ' $instance->' . $property->getName()
117+
. ' = ' . $this->getExportedPropertyDefaultValue($property) . ';',
120118
$properties
121119
)
122120
);

src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializer.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
66

7+
use Closure;
78
use Laminas\Code\Generator\ParameterGenerator;
89
use Laminas\Code\Generator\PropertyGenerator;
910
use ProxyManager\Generator\MethodGenerator;
@@ -21,7 +22,7 @@ public function __construct(PropertyGenerator $initializerProperty)
2122
{
2223
parent::__construct(
2324
'setProxyInitializer',
24-
[(new ParameterGenerator('initializer', 'Closure'))->setDefaultValue(null)],
25+
[(new ParameterGenerator('initializer', Closure::class))->setDefaultValue(null)],
2526
self::FLAG_PUBLIC,
2627
'$this->' . $initializerProperty->getName() . ' = $initializer;'
2728
);

src/ProxyManager/ProxyGenerator/LazyLoadingValueHolderGenerator.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ private function buildLazyLoadingMethodInterceptor(
104104
InitializerProperty $initializer,
105105
ValueHolderProperty $valueHolder
106106
): callable {
107-
return static function (ReflectionMethod $method) use ($initializer, $valueHolder): LazyLoadingMethodInterceptor {
108-
return LazyLoadingMethodInterceptor::generateMethod(
109-
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
110-
$initializer,
111-
$valueHolder
112-
);
113-
};
107+
return static fn (ReflectionMethod $method): LazyLoadingMethodInterceptor => LazyLoadingMethodInterceptor::generateMethod(
108+
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
109+
$initializer,
110+
$valueHolder
111+
);
114112
}
115113
}

src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/StaticProxyConstructor.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ public function __construct(ReflectionClass $originalClass)
3030
parent::__construct('staticProxyConstructor', [], self::FLAG_PUBLIC | self::FLAG_STATIC);
3131

3232
$nullableProperties = array_map(
33-
static function (ReflectionProperty $publicProperty): string {
34-
return '$instance->' . $publicProperty->getName() . ' = null;';
35-
},
33+
static fn (ReflectionProperty $publicProperty): string => '$instance->' . $publicProperty->getName() . ' = null;',
3634
Properties::fromReflectionClass($originalClass)
3735
->onlyNullableProperties()
3836
->getPublicProperties()

src/ProxyManager/ProxyGenerator/RemoteObjectGenerator.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ static function (MethodGenerator $generatedMethod) use ($originalClass, $classGe
6262
},
6363
array_merge(
6464
array_map(
65-
static function (ReflectionMethod $method) use ($adapter, $originalClass): RemoteObjectMethod {
66-
return RemoteObjectMethod::generateMethod(
67-
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
68-
$adapter,
69-
$originalClass
70-
);
71-
},
65+
static fn (ReflectionMethod $method): RemoteObjectMethod => RemoteObjectMethod::generateMethod(
66+
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()),
67+
$adapter,
68+
$originalClass
69+
),
7270
ProxiedMethodsFilter::getProxiedMethods(
7371
$originalClass,
7472
['__get', '__set', '__isset', '__unset']

src/ProxyManager/ProxyGenerator/Util/Properties.php

+6-14
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@
2323
*/
2424
final class Properties
2525
{
26-
/** @var ReflectionProperty[] */
27-
private array $properties;
28-
2926
/**
3027
* @param ReflectionProperty[] $properties
3128
*/
32-
private function __construct(array $properties)
29+
private function __construct(private array $properties)
3330
{
34-
$this->properties = $properties;
3531
}
3632

3733
public static function fromReflectionClass(ReflectionClass $reflection): self
@@ -46,15 +42,11 @@ public static function fromReflectionClass(ReflectionClass $reflection): self
4642
} while ($class);
4743

4844
return new self(array_merge(
49-
...array_map(static function (ReflectionClass $class): array {
50-
return array_values(array_filter(
51-
$class->getProperties(),
52-
static function (ReflectionProperty $property) use ($class): bool {
53-
return $class->getName() === $property->getDeclaringClass()->getName()
54-
&& ! $property->isStatic();
55-
}
56-
));
57-
}, $parentClasses)
45+
...array_map(static fn (ReflectionClass $class): array => array_values(array_filter(
46+
$class->getProperties(),
47+
static fn (ReflectionProperty $property): bool => $class->getName() === $property->getDeclaringClass()->getName()
48+
&& ! $property->isStatic()
49+
)), $parentClasses)
5850
));
5951
}
6052

src/ProxyManager/ProxyGenerator/Util/ProxiedMethodsFilter.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ private static function doFilter(ReflectionClass $class, array $excluded, bool $
6363

6464
return array_values(array_filter(
6565
$class->getMethods(ReflectionMethod::IS_PUBLIC),
66-
static function (ReflectionMethod $method) use ($ignored, $requireAbstract): bool {
67-
return (! $requireAbstract || $method->isAbstract()) && ! (
68-
array_key_exists(strtolower($method->getName()), $ignored)
69-
|| self::methodCannotBeProxied($method)
70-
);
71-
}
66+
static fn (ReflectionMethod $method): bool => (! $requireAbstract || $method->isAbstract()) && ! (
67+
array_key_exists(strtolower($method->getName()), $ignored)
68+
|| self::methodCannotBeProxied($method)
69+
)
7270
));
7371
}
7472

0 commit comments

Comments
 (0)