Skip to content

Commit 6d2458d

Browse files
authored
Merge pull request #732 from samsonasik/apply-php8
Apply php 8.0 syntax
2 parents 22ce87d + 96d5c8d commit 6d2458d

18 files changed

+73
-154
lines changed

src/ProxyManager/Configuration.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ class Configuration
2727
{
2828
public const DEFAULT_PROXY_NAMESPACE = 'ProxyManagerGeneratedProxy';
2929

30-
protected ?string $proxiesTargetDir;
31-
protected string $proxiesNamespace = self::DEFAULT_PROXY_NAMESPACE;
32-
protected ?GeneratorStrategyInterface $generatorStrategy;
33-
protected ?AutoloaderInterface $proxyAutoloader;
34-
protected ?ClassNameInflectorInterface $classNameInflector;
35-
protected ?SignatureGeneratorInterface $signatureGenerator;
36-
protected ?SignatureCheckerInterface $signatureChecker;
37-
protected ?ClassSignatureGeneratorInterface $classSignatureGenerator;
30+
protected ?string $proxiesTargetDir = null;
31+
protected string $proxiesNamespace = self::DEFAULT_PROXY_NAMESPACE;
32+
protected ?GeneratorStrategyInterface $generatorStrategy = null;
33+
protected ?AutoloaderInterface $proxyAutoloader = null;
34+
protected ?ClassNameInflectorInterface $classNameInflector = null;
35+
protected ?SignatureGeneratorInterface $signatureGenerator = null;
36+
protected ?SignatureCheckerInterface $signatureChecker = null;
37+
protected ?ClassSignatureGeneratorInterface $classSignatureGenerator = null;
3838

3939
public function setProxyAutoloader(AutoloaderInterface $proxyAutoloader): void
4040
{

tests/ProxyManagerTest/Factory/AbstractBaseFactoryTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function setUp(): void
8686
$this
8787
->classNameInflector
8888
->method('getUserClassName')
89-
->willReturn('stdClass');
89+
->willReturn(stdClass::class);
9090

9191
$this->factory = $this->getMockForAbstractClass(AbstractBaseFactory::class, [$configuration]);
9292

@@ -103,7 +103,7 @@ public function testGeneratesClass(): void
103103
$this
104104
->classNameInflector
105105
->method('getProxyClassName')
106-
->with('stdClass')
106+
->with(stdClass::class)
107107
->willReturn($generatedClass);
108108

109109
$this
@@ -129,9 +129,7 @@ public function testGeneratesClass(): void
129129
->expects(self::once())
130130
->method('generate')
131131
->with(
132-
self::callback(static function (ReflectionClass $reflectionClass): bool {
133-
return $reflectionClass->getName() === stdClass::class;
134-
}),
132+
self::callback(static fn (ReflectionClass $reflectionClass): bool => $reflectionClass->getName() === stdClass::class),
135133
self::isInstanceOf(ClassGenerator::class),
136134
['some' => 'proxy', 'options' => 'here']
137135
);

tests/ProxyManagerTest/Factory/AccessInterceptorScopeLocalizerFactoryTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testWillSkipAutoGeneration(): void
9494
->inflector
9595
->expects(self::once())
9696
->method('getProxyClassName')
97-
->with('stdClass')
97+
->with(stdClass::class)
9898
->willReturn(AccessInterceptorValueHolderMock::class);
9999

100100
$factory = new AccessInterceptorScopeLocalizerFactory($this->config);
@@ -140,9 +140,7 @@ public function testWillTryAutoGeneration(): void
140140
->method('generate')
141141
->with(
142142
self::callback(
143-
static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
144-
return $targetClass->getName() === $proxyClassName;
145-
}
143+
static fn (ClassGenerator $targetClass): bool => $targetClass->getName() === $proxyClassName
146144
)
147145
);
148146

@@ -164,14 +162,14 @@ static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
164162
->inflector
165163
->expects(self::once())
166164
->method('getProxyClassName')
167-
->with('stdClass')
165+
->with(stdClass::class)
168166
->willReturn($proxyClassName);
169167

170168
$this
171169
->inflector
172170
->expects(self::once())
173171
->method('getUserClassName')
174-
->with('stdClass')
172+
->with(stdClass::class)
175173
->willReturn(LazyLoadingMock::class);
176174

177175
$this->signatureChecker->expects(self::atLeastOnce())->method('checkSignature');

tests/ProxyManagerTest/Factory/AccessInterceptorValueHolderFactoryTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testWillSkipAutoGeneration(): void
9090
->inflector
9191
->expects(self::once())
9292
->method('getProxyClassName')
93-
->with('stdClass')
93+
->with(stdClass::class)
9494
->willReturn(AccessInterceptorValueHolderMock::class);
9595

9696
$factory = new AccessInterceptorValueHolderFactory($this->config);
@@ -135,9 +135,7 @@ public function testWillTryAutoGeneration(): void
135135
->method('generate')
136136
->with(
137137
self::callback(
138-
static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
139-
return $targetClass->getName() === $proxyClassName;
140-
}
138+
static fn (ClassGenerator $targetClass): bool => $targetClass->getName() === $proxyClassName
141139
)
142140
);
143141

@@ -159,14 +157,14 @@ static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
159157
->inflector
160158
->expects(self::once())
161159
->method('getProxyClassName')
162-
->with('stdClass')
160+
->with(stdClass::class)
163161
->willReturn($proxyClassName);
164162

165163
$this
166164
->inflector
167165
->expects(self::once())
168166
->method('getUserClassName')
169-
->with('stdClass')
167+
->with(stdClass::class)
170168
->willReturn(EmptyClass::class);
171169

172170
$this->signatureChecker->expects(self::atLeastOnce())->method('checkSignature');

tests/ProxyManagerTest/Factory/LazyLoadingGhostFactoryTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ public function testWillSkipAutoGeneration(): void
9191
->willReturn(LazyLoadingMock::class);
9292

9393
$factory = new LazyLoadingGhostFactory($this->config);
94-
$initializer = static function (): bool {
95-
return true;
96-
};
94+
$initializer = static fn (): bool => true;
9795
$proxy = $factory->createProxy($className, $initializer);
9896

9997
self::assertSame($initializer, $proxy->getProxyInitializer());
@@ -123,9 +121,7 @@ public function testWillTryAutoGeneration(): void
123121
->method('generate')
124122
->with(
125123
self::callback(
126-
static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
127-
return $targetClass->getName() === $proxyClassName;
128-
}
124+
static fn (ClassGenerator $targetClass): bool => $targetClass->getName() === $proxyClassName
129125
)
130126
);
131127

@@ -158,9 +154,7 @@ static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
158154
$this->classSignatureGenerator->expects(self::once())->method('addSignature')->will(self::returnArgument(0));
159155

160156
$factory = new LazyLoadingGhostFactory($this->config);
161-
$initializer = static function (): bool {
162-
return true;
163-
};
157+
$initializer = static fn (): bool => true;
164158
$proxy = $factory->createProxy($className, $initializer);
165159

166160
self::assertSame($initializer, $proxy->getProxyInitializer());

tests/ProxyManagerTest/Factory/LazyLoadingValueHolderFactoryTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ public function testWillSkipAutoGeneration(): void
9292
->willReturn(LazyLoadingMock::class);
9393

9494
$factory = new LazyLoadingValueHolderFactory($this->config);
95-
$initializer = static function (): bool {
96-
return true;
97-
};
95+
$initializer = static fn (): bool => true;
9896
$proxy = $factory->createProxy($className, $initializer);
9997

10098
self::assertSame($initializer, $proxy->getProxyInitializer());
@@ -124,9 +122,7 @@ public function testWillTryAutoGeneration(): void
124122
->method('generate')
125123
->with(
126124
self::callback(
127-
static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
128-
return $targetClass->getName() === $proxyClassName;
129-
}
125+
static fn (ClassGenerator $targetClass): bool => $targetClass->getName() === $proxyClassName
130126
)
131127
);
132128

@@ -159,9 +155,7 @@ static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
159155
$this->classSignatureGenerator->expects(self::once())->method('addSignature')->will(self::returnArgument(0));
160156

161157
$factory = new LazyLoadingValueHolderFactory($this->config);
162-
$initializer = static function (): bool {
163-
return true;
164-
};
158+
$initializer = static fn (): bool => true;
165159
$proxy = $factory->createProxy($className, $initializer);
166160

167161
self::assertInstanceOf($proxyClassName, $proxy);

tests/ProxyManagerTest/Factory/NullObjectFactoryTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testWillSkipAutoGeneration(): void
7575
->inflector
7676
->expects(self::once())
7777
->method('getProxyClassName')
78-
->with('stdClass')
78+
->with(stdClass::class)
7979
->willReturn(NullObjectMock::class);
8080

8181
(new NullObjectFactory($this->config))->createProxy($instance);
@@ -105,9 +105,7 @@ public function testWillTryAutoGeneration(): void
105105
->method('generate')
106106
->with(
107107
self::callback(
108-
static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
109-
return $targetClass->getName() === $proxyClassName;
110-
}
108+
static fn (ClassGenerator $targetClass): bool => $targetClass->getName() === $proxyClassName
111109
)
112110
);
113111

@@ -126,14 +124,14 @@ static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
126124
->inflector
127125
->expects(self::once())
128126
->method('getProxyClassName')
129-
->with('stdClass')
127+
->with(stdClass::class)
130128
->willReturn($proxyClassName);
131129

132130
$this
133131
->inflector
134132
->expects(self::once())
135133
->method('getUserClassName')
136-
->with('stdClass')
134+
->with(stdClass::class)
137135
->willReturn(NullObjectMock::class);
138136

139137
$this->signatureChecker->expects(self::atLeastOnce())->method('checkSignature');

tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ProxyManager\Signature\SignatureCheckerInterface;
1919
use ProxyManagerTestAsset\BaseInterface;
2020
use ProxyManagerTestAsset\RemoteProxy\RemoteObjectMock;
21+
use stdClass;
2122

2223
/**
2324
* @covers \ProxyManager\Factory\AbstractBaseFactory
@@ -97,9 +98,7 @@ public function testWillTryAutoGeneration(): void
9798
->method('generate')
9899
->with(
99100
self::callback(
100-
static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
101-
return $targetClass->getName() === $proxyClassName;
102-
}
101+
static fn (ClassGenerator $targetClass): bool => $targetClass->getName() === $proxyClassName
103102
)
104103
);
105104

@@ -130,7 +129,7 @@ static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
130129
->expects(self::once())
131130
->method('getUserClassName')
132131
->with(BaseInterface::class)
133-
->willReturn('stdClass');
132+
->willReturn(stdClass::class);
134133

135134
$this->signatureChecker->expects(self::atLeastOnce())->method('checkSignature');
136135
$this->classSignatureGenerator->expects(self::once())->method('addSignature')->will(self::returnArgument(0));

tests/ProxyManagerTest/Functional/AccessInterceptorScopeLocalizerFunctionalTest.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use stdClass;
3030

3131
use function array_values;
32-
use function get_class;
3332
use function random_int;
3433
use function serialize;
3534
use function uniqid;
@@ -333,10 +332,8 @@ public function testWillBehaveLikeObjectWithNormalConstructor(): void
333332
self::assertSame(13, $instance->amount, 'Verifying that test asset works as expected');
334333
self::assertSame(13, $instance->getAmount(), 'Verifying that test asset works as expected');
335334

336-
$proxyName = get_class(
337-
(new AccessInterceptorScopeLocalizerFactory())
338-
->createProxy(new ClassWithCounterConstructor(0))
339-
);
335+
$proxyName = (new AccessInterceptorScopeLocalizerFactory())
336+
->createProxy(new ClassWithCounterConstructor(0))::class;
340337

341338
/** @psalm-suppress UnsafeInstantiation it is allowed (by design) to instantiate these proxies */
342339
$proxy = new $proxyName(15);
@@ -441,9 +438,7 @@ public function testWillForwardVariadicArguments(): void
441438
$object = $factory->createProxy(
442439
$targetObject,
443440
[
444-
'bar' => static function (): string {
445-
return 'Foo Baz';
446-
},
441+
'bar' => static fn (): string => 'Foo Baz',
447442
]
448443
);
449444

@@ -467,9 +462,7 @@ public function testWillForwardVariadicByRefArguments(): void
467462
$object = $factory->createProxy(
468463
$targetObject,
469464
[
470-
'bar' => static function (): string {
471-
return 'Foo Baz';
472-
},
465+
'bar' => static fn (): string => 'Foo Baz',
473466
]
474467
);
475468

@@ -493,9 +486,7 @@ public function testWillNotForwardDynamicArguments(): void
493486
->createProxy(
494487
new ClassWithDynamicArgumentsMethod(),
495488
[
496-
'dynamicArgumentsMethod' => static function (): string {
497-
return 'Foo Baz';
498-
},
489+
'dynamicArgumentsMethod' => static fn (): string => 'Foo Baz',
499490
]
500491
);
501492

tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
use function array_values;
3434
use function assert;
35-
use function get_class;
3635
use function is_callable;
3736
use function random_int;
3837
use function serialize;
@@ -338,10 +337,8 @@ public function testWillBehaveLikeObjectWithNormalConstructor(): void
338337
self::assertSame(13, $instance->amount, 'Verifying that test asset works as expected');
339338
self::assertSame(13, $instance->getAmount(), 'Verifying that test asset works as expected');
340339

341-
$proxyName = get_class(
342-
(new AccessInterceptorValueHolderFactory())
343-
->createProxy(new ClassWithCounterConstructor(0))
344-
);
340+
$proxyName = (new AccessInterceptorValueHolderFactory())
341+
->createProxy(new ClassWithCounterConstructor(0))::class;
345342

346343
/** @psalm-suppress UnsafeInstantiation it is allowed (by design) to instantiate these proxies */
347344
$proxy = new $proxyName(15);
@@ -361,9 +358,7 @@ public function testWillForwardVariadicArguments(): void
361358
$object = $factory->createProxy(
362359
$targetObject,
363360
[
364-
'bar' => static function (): string {
365-
return 'Foo Baz';
366-
},
361+
'bar' => static fn (): string => 'Foo Baz',
367362
]
368363
);
369364

@@ -383,9 +378,7 @@ public function testWillForwardVariadicByRefArguments(): void
383378
$object = (new AccessInterceptorValueHolderFactory())->createProxy(
384379
new ClassWithMethodWithByRefVariadicFunction(),
385380
[
386-
'bar' => static function (): string {
387-
return 'Foo Baz';
388-
},
381+
'bar' => static fn (): string => 'Foo Baz',
389382
]
390383
);
391384

0 commit comments

Comments
 (0)