Skip to content

Commit

Permalink
Merge pull request #732 from samsonasik/apply-php8
Browse files Browse the repository at this point in the history
Apply php 8.0 syntax
  • Loading branch information
Ocramius authored Jan 16, 2022
2 parents 22ce87d + 96d5c8d commit 6d2458d
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 154 deletions.
16 changes: 8 additions & 8 deletions src/ProxyManager/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class Configuration
{
public const DEFAULT_PROXY_NAMESPACE = 'ProxyManagerGeneratedProxy';

protected ?string $proxiesTargetDir;
protected string $proxiesNamespace = self::DEFAULT_PROXY_NAMESPACE;
protected ?GeneratorStrategyInterface $generatorStrategy;
protected ?AutoloaderInterface $proxyAutoloader;
protected ?ClassNameInflectorInterface $classNameInflector;
protected ?SignatureGeneratorInterface $signatureGenerator;
protected ?SignatureCheckerInterface $signatureChecker;
protected ?ClassSignatureGeneratorInterface $classSignatureGenerator;
protected ?string $proxiesTargetDir = null;
protected string $proxiesNamespace = self::DEFAULT_PROXY_NAMESPACE;
protected ?GeneratorStrategyInterface $generatorStrategy = null;
protected ?AutoloaderInterface $proxyAutoloader = null;
protected ?ClassNameInflectorInterface $classNameInflector = null;
protected ?SignatureGeneratorInterface $signatureGenerator = null;
protected ?SignatureCheckerInterface $signatureChecker = null;
protected ?ClassSignatureGeneratorInterface $classSignatureGenerator = null;

public function setProxyAutoloader(AutoloaderInterface $proxyAutoloader): void
{
Expand Down
8 changes: 3 additions & 5 deletions tests/ProxyManagerTest/Factory/AbstractBaseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function setUp(): void
$this
->classNameInflector
->method('getUserClassName')
->willReturn('stdClass');
->willReturn(stdClass::class);

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

Expand All @@ -103,7 +103,7 @@ public function testGeneratesClass(): void
$this
->classNameInflector
->method('getProxyClassName')
->with('stdClass')
->with(stdClass::class)
->willReturn($generatedClass);

$this
Expand All @@ -129,9 +129,7 @@ public function testGeneratesClass(): void
->expects(self::once())
->method('generate')
->with(
self::callback(static function (ReflectionClass $reflectionClass): bool {
return $reflectionClass->getName() === stdClass::class;
}),
self::callback(static fn (ReflectionClass $reflectionClass): bool => $reflectionClass->getName() === stdClass::class),
self::isInstanceOf(ClassGenerator::class),
['some' => 'proxy', 'options' => 'here']
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testWillSkipAutoGeneration(): void
->inflector
->expects(self::once())
->method('getProxyClassName')
->with('stdClass')
->with(stdClass::class)
->willReturn(AccessInterceptorValueHolderMock::class);

$factory = new AccessInterceptorScopeLocalizerFactory($this->config);
Expand Down Expand Up @@ -140,9 +140,7 @@ public function testWillTryAutoGeneration(): void
->method('generate')
->with(
self::callback(
static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
return $targetClass->getName() === $proxyClassName;
}
static fn (ClassGenerator $targetClass): bool => $targetClass->getName() === $proxyClassName
)
);

Expand All @@ -164,14 +162,14 @@ static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
->inflector
->expects(self::once())
->method('getProxyClassName')
->with('stdClass')
->with(stdClass::class)
->willReturn($proxyClassName);

$this
->inflector
->expects(self::once())
->method('getUserClassName')
->with('stdClass')
->with(stdClass::class)
->willReturn(LazyLoadingMock::class);

$this->signatureChecker->expects(self::atLeastOnce())->method('checkSignature');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testWillSkipAutoGeneration(): void
->inflector
->expects(self::once())
->method('getProxyClassName')
->with('stdClass')
->with(stdClass::class)
->willReturn(AccessInterceptorValueHolderMock::class);

$factory = new AccessInterceptorValueHolderFactory($this->config);
Expand Down Expand Up @@ -135,9 +135,7 @@ public function testWillTryAutoGeneration(): void
->method('generate')
->with(
self::callback(
static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
return $targetClass->getName() === $proxyClassName;
}
static fn (ClassGenerator $targetClass): bool => $targetClass->getName() === $proxyClassName
)
);

Expand All @@ -159,14 +157,14 @@ static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
->inflector
->expects(self::once())
->method('getProxyClassName')
->with('stdClass')
->with(stdClass::class)
->willReturn($proxyClassName);

$this
->inflector
->expects(self::once())
->method('getUserClassName')
->with('stdClass')
->with(stdClass::class)
->willReturn(EmptyClass::class);

$this->signatureChecker->expects(self::atLeastOnce())->method('checkSignature');
Expand Down
12 changes: 3 additions & 9 deletions tests/ProxyManagerTest/Factory/LazyLoadingGhostFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ public function testWillSkipAutoGeneration(): void
->willReturn(LazyLoadingMock::class);

$factory = new LazyLoadingGhostFactory($this->config);
$initializer = static function (): bool {
return true;
};
$initializer = static fn (): bool => true;
$proxy = $factory->createProxy($className, $initializer);

self::assertSame($initializer, $proxy->getProxyInitializer());
Expand Down Expand Up @@ -123,9 +121,7 @@ public function testWillTryAutoGeneration(): void
->method('generate')
->with(
self::callback(
static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
return $targetClass->getName() === $proxyClassName;
}
static fn (ClassGenerator $targetClass): bool => $targetClass->getName() === $proxyClassName
)
);

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

$factory = new LazyLoadingGhostFactory($this->config);
$initializer = static function (): bool {
return true;
};
$initializer = static fn (): bool => true;
$proxy = $factory->createProxy($className, $initializer);

self::assertSame($initializer, $proxy->getProxyInitializer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ public function testWillSkipAutoGeneration(): void
->willReturn(LazyLoadingMock::class);

$factory = new LazyLoadingValueHolderFactory($this->config);
$initializer = static function (): bool {
return true;
};
$initializer = static fn (): bool => true;
$proxy = $factory->createProxy($className, $initializer);

self::assertSame($initializer, $proxy->getProxyInitializer());
Expand Down Expand Up @@ -124,9 +122,7 @@ public function testWillTryAutoGeneration(): void
->method('generate')
->with(
self::callback(
static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
return $targetClass->getName() === $proxyClassName;
}
static fn (ClassGenerator $targetClass): bool => $targetClass->getName() === $proxyClassName
)
);

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

$factory = new LazyLoadingValueHolderFactory($this->config);
$initializer = static function (): bool {
return true;
};
$initializer = static fn (): bool => true;
$proxy = $factory->createProxy($className, $initializer);

self::assertInstanceOf($proxyClassName, $proxy);
Expand Down
10 changes: 4 additions & 6 deletions tests/ProxyManagerTest/Factory/NullObjectFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testWillSkipAutoGeneration(): void
->inflector
->expects(self::once())
->method('getProxyClassName')
->with('stdClass')
->with(stdClass::class)
->willReturn(NullObjectMock::class);

(new NullObjectFactory($this->config))->createProxy($instance);
Expand Down Expand Up @@ -105,9 +105,7 @@ public function testWillTryAutoGeneration(): void
->method('generate')
->with(
self::callback(
static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
return $targetClass->getName() === $proxyClassName;
}
static fn (ClassGenerator $targetClass): bool => $targetClass->getName() === $proxyClassName
)
);

Expand All @@ -126,14 +124,14 @@ static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
->inflector
->expects(self::once())
->method('getProxyClassName')
->with('stdClass')
->with(stdClass::class)
->willReturn($proxyClassName);

$this
->inflector
->expects(self::once())
->method('getUserClassName')
->with('stdClass')
->with(stdClass::class)
->willReturn(NullObjectMock::class);

$this->signatureChecker->expects(self::atLeastOnce())->method('checkSignature');
Expand Down
7 changes: 3 additions & 4 deletions tests/ProxyManagerTest/Factory/RemoteObjectFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use ProxyManager\Signature\SignatureCheckerInterface;
use ProxyManagerTestAsset\BaseInterface;
use ProxyManagerTestAsset\RemoteProxy\RemoteObjectMock;
use stdClass;

/**
* @covers \ProxyManager\Factory\AbstractBaseFactory
Expand Down Expand Up @@ -97,9 +98,7 @@ public function testWillTryAutoGeneration(): void
->method('generate')
->with(
self::callback(
static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
return $targetClass->getName() === $proxyClassName;
}
static fn (ClassGenerator $targetClass): bool => $targetClass->getName() === $proxyClassName
)
);

Expand Down Expand Up @@ -130,7 +129,7 @@ static function (ClassGenerator $targetClass) use ($proxyClassName): bool {
->expects(self::once())
->method('getUserClassName')
->with(BaseInterface::class)
->willReturn('stdClass');
->willReturn(stdClass::class);

$this->signatureChecker->expects(self::atLeastOnce())->method('checkSignature');
$this->classSignatureGenerator->expects(self::once())->method('addSignature')->will(self::returnArgument(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use stdClass;

use function array_values;
use function get_class;
use function random_int;
use function serialize;
use function uniqid;
Expand Down Expand Up @@ -333,10 +332,8 @@ public function testWillBehaveLikeObjectWithNormalConstructor(): void
self::assertSame(13, $instance->amount, 'Verifying that test asset works as expected');
self::assertSame(13, $instance->getAmount(), 'Verifying that test asset works as expected');

$proxyName = get_class(
(new AccessInterceptorScopeLocalizerFactory())
->createProxy(new ClassWithCounterConstructor(0))
);
$proxyName = (new AccessInterceptorScopeLocalizerFactory())
->createProxy(new ClassWithCounterConstructor(0))::class;

/** @psalm-suppress UnsafeInstantiation it is allowed (by design) to instantiate these proxies */
$proxy = new $proxyName(15);
Expand Down Expand Up @@ -441,9 +438,7 @@ public function testWillForwardVariadicArguments(): void
$object = $factory->createProxy(
$targetObject,
[
'bar' => static function (): string {
return 'Foo Baz';
},
'bar' => static fn (): string => 'Foo Baz',
]
);

Expand All @@ -467,9 +462,7 @@ public function testWillForwardVariadicByRefArguments(): void
$object = $factory->createProxy(
$targetObject,
[
'bar' => static function (): string {
return 'Foo Baz';
},
'bar' => static fn (): string => 'Foo Baz',
]
);

Expand All @@ -493,9 +486,7 @@ public function testWillNotForwardDynamicArguments(): void
->createProxy(
new ClassWithDynamicArgumentsMethod(),
[
'dynamicArgumentsMethod' => static function (): string {
return 'Foo Baz';
},
'dynamicArgumentsMethod' => static fn (): string => 'Foo Baz',
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

use function array_values;
use function assert;
use function get_class;
use function is_callable;
use function random_int;
use function serialize;
Expand Down Expand Up @@ -338,10 +337,8 @@ public function testWillBehaveLikeObjectWithNormalConstructor(): void
self::assertSame(13, $instance->amount, 'Verifying that test asset works as expected');
self::assertSame(13, $instance->getAmount(), 'Verifying that test asset works as expected');

$proxyName = get_class(
(new AccessInterceptorValueHolderFactory())
->createProxy(new ClassWithCounterConstructor(0))
);
$proxyName = (new AccessInterceptorValueHolderFactory())
->createProxy(new ClassWithCounterConstructor(0))::class;

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

Expand All @@ -383,9 +378,7 @@ public function testWillForwardVariadicByRefArguments(): void
$object = (new AccessInterceptorValueHolderFactory())->createProxy(
new ClassWithMethodWithByRefVariadicFunction(),
[
'bar' => static function (): string {
return 'Foo Baz';
},
'bar' => static fn (): string => 'Foo Baz',
]
);

Expand Down
Loading

0 comments on commit 6d2458d

Please sign in to comment.