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

Lines changed: 1 addition & 6 deletions
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

Lines changed: 2 additions & 6 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 5 additions & 13 deletions
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

Lines changed: 3 additions & 8 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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();

0 commit comments

Comments
 (0)