Skip to content

Commit

Permalink
Merge pull request #629 from nicolas-grekas/cleanups
Browse files Browse the repository at this point in the history
Various minor cleanups
  • Loading branch information
Ocramius authored Nov 12, 2020
2 parents 7452942 + ae17c4b commit f65ae0f
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/ProxyManager/Factory/AbstractBaseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class AbstractBaseFactory

public function __construct(?Configuration $configuration = null)
{
$this->configuration = $configuration ?: new Configuration();
$this->configuration = $configuration ?? new Configuration();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ProxyManager/Generator/Util/IdentifierSuffixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function getIdentifier(string $name): string
/** @var string|null $salt */
static $salt;

$salt ??= $salt = self::loadBaseHashSalt();
$salt ??= self::loadBaseHashSalt();
$suffix = substr(sha1($name . $salt), 0, 5);

if (! preg_match(self::VALID_IDENTIFIER_FORMAT, $name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function propertiesInitializationCode(Properties $properties): string
foreach ($properties->getGroupedPrivateProperties() as $className => $privateProperties) {
$cacheKey = 'cache' . str_replace('\\', '_', $className);
$assignments[] = 'static $' . $cacheKey . ";\n\n"
. '$' . $cacheKey . ' ?: $' . $cacheKey . " = \\Closure::bind(static function (\$instance) {\n"
. '$' . $cacheKey . ' ?? $' . $cacheKey . " = \\Closure::bind(static function (\$instance) {\n"
. $this->getPropertyDefaultsAssignments($privateProperties) . "\n"
. '}, null, ' . var_export($className, true) . ");\n\n"
. '$' . $cacheKey . "(\$this);\n\n";
Expand Down Expand Up @@ -139,7 +139,7 @@ private function propertiesReferenceArrayCode(Properties $properties): string
$cacheKey = 'cacheFetch' . str_replace('\\', '_', $className);

$code .= 'static $' . $cacheKey . ";\n\n"
. '$' . $cacheKey . ' ?: $' . $cacheKey
. '$' . $cacheKey . ' ?? $' . $cacheKey
. " = \\Closure::bind(function (\$instance, array & \$properties) {\n"
. $this->generatePrivatePropertiesAssignmentsCode($classPrivateProperties)
. '}, $this, ' . var_export($className, true) . ");\n\n"
Expand Down
4 changes: 2 additions & 2 deletions src/ProxyManager/ProxyGenerator/Util/PublicScopeSimulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static function getUndefinedPropertyNotice(string $operationType, string
return '';
}

return ' $backtrace = debug_backtrace(false);' . "\n"
return ' $backtrace = debug_backtrace(false, 1);' . "\n"
. ' trigger_error(' . "\n"
. ' sprintf(' . "\n"
. ' \'Undefined property: %s::$%s in %s on line %s\',' . "\n"
Expand Down Expand Up @@ -147,7 +147,7 @@ private static function getOperation(string $operationType, string $nameParamete
*/
private static function getScopeReBind(): string
{
return '$backtrace = debug_backtrace(true);' . "\n"
return '$backtrace = debug_backtrace(true, 2);' . "\n"
. '$scopeObject = isset($backtrace[1][\'object\'])'
. ' ? $backtrace[1][\'object\'] : new \ProxyManager\Stub\EmptyClassStub();' . "\n"
. '$accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));' . "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function generateMethod(ReflectionClass $originalClass, PropertyGe
$constructor->setBody(
'static $reflection;' . "\n\n"
. 'if (! $this->' . $valueHolder->getName() . ') {' . "\n"
. ' $reflection = $reflection ?: new \ReflectionClass('
. ' $reflection = $reflection ?? new \ReflectionClass('
. var_export($originalClass->getName(), true)
. ");\n"
. ' $this->' . $valueHolder->getName() . ' = $reflection->newInstanceWithoutConstructor();' . "\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function testPropertyUnset(
AccessInterceptorValueHolderInterface $proxy,
string $publicProperty
): void {
$instance = $proxy->getWrappedValueHolderValue() ?: $instance;
$instance = $proxy->getWrappedValueHolderValue() ?? $instance;
unset($proxy->$publicProperty);

self::assertFalse(isset($instance->$publicProperty));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function testPropertyAbsence(object $instance, VirtualProxyInterface $pro
self::markTestSkipped('Non-nullable typed properties cannot be removed/unset');
}

$instance = $proxy->getWrappedValueHolderValue() ?: $instance;
$instance = $proxy->getWrappedValueHolderValue() ?? $instance;
$instance->$publicProperty = null;
self::assertFalse(isset($proxy->$publicProperty));
self::assertTrue($proxy->isProxyInitialized());
Expand All @@ -214,7 +214,7 @@ public function testPropertyAbsence(object $instance, VirtualProxyInterface $pro
*/
public function testPropertyUnset(object $instance, VirtualProxyInterface $proxy, string $publicProperty): void
{
$instance = $proxy->getWrappedValueHolderValue() ?: $instance;
$instance = $proxy->getWrappedValueHolderValue() ?? $instance;
unset($proxy->$publicProperty);

self::assertTrue($proxy->isProxyInitialized());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testBodyStructure(): void
$this->protectedProperty2 = 'protectedProperty2';
static $cacheProxyManagerTestAsset_ClassWithMixedProperties;
$cacheProxyManagerTestAsset_ClassWithMixedProperties ?: $cacheProxyManagerTestAsset_ClassWithMixedProperties = \Closure::bind(static function ($instance) {
$cacheProxyManagerTestAsset_ClassWithMixedProperties ?? $cacheProxyManagerTestAsset_ClassWithMixedProperties = \Closure::bind(static function ($instance) {
$instance->privateProperty0 = 'privateProperty0';
$instance->privateProperty1 = 'privateProperty1';
$instance->privateProperty2 = 'privateProperty2';
Expand All @@ -72,7 +72,7 @@ public function testBodyStructure(): void
static $cacheFetchProxyManagerTestAsset_ClassWithMixedProperties;
$cacheFetchProxyManagerTestAsset_ClassWithMixedProperties ?: $cacheFetchProxyManagerTestAsset_ClassWithMixedProperties = \Closure::bind(function ($instance, array & $properties) {
$cacheFetchProxyManagerTestAsset_ClassWithMixedProperties ?? $cacheFetchProxyManagerTestAsset_ClassWithMixedProperties = \Closure::bind(function ($instance, array & $properties) {
$properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedProperties' . "\0" . 'privateProperty0'] = & $instance->privateProperty0;
$properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedProperties' . "\0" . 'privateProperty1'] = & $instance->privateProperty1;
$properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedProperties' . "\0" . 'privateProperty2'] = & $instance->privateProperty2;
Expand Down Expand Up @@ -175,7 +175,7 @@ public function testBodyStructureWithTypedProperties(): void
$this->protectedNullableClassProperty = NULL;
static $cacheProxyManagerTestAsset_ClassWithMixedTypedProperties;
$cacheProxyManagerTestAsset_ClassWithMixedTypedProperties ?: $cacheProxyManagerTestAsset_ClassWithMixedTypedProperties = \Closure::bind(static function ($instance) {
$cacheProxyManagerTestAsset_ClassWithMixedTypedProperties ?? $cacheProxyManagerTestAsset_ClassWithMixedTypedProperties = \Closure::bind(static function ($instance) {
$instance->privateUnTypedProperty = 'privateUnTypedProperty';
$instance->privateUnTypedPropertyWithoutDefaultValue = NULL;
$instance->privateBoolProperty = true;
Expand Down Expand Up @@ -262,7 +262,7 @@ public function testBodyStructureWithTypedProperties(): void
static $cacheFetchProxyManagerTestAsset_ClassWithMixedTypedProperties;
$cacheFetchProxyManagerTestAsset_ClassWithMixedTypedProperties ?: $cacheFetchProxyManagerTestAsset_ClassWithMixedTypedProperties = \Closure::bind(function ($instance, array & $properties) {
$cacheFetchProxyManagerTestAsset_ClassWithMixedTypedProperties ?? $cacheFetchProxyManagerTestAsset_ClassWithMixedTypedProperties = \Closure::bind(function ($instance, array & $properties) {
$properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateUnTypedProperty'] = & $instance->privateUnTypedProperty;
$properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateUnTypedPropertyWithoutDefaultValue'] = & $instance->privateUnTypedPropertyWithoutDefaultValue;
$properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateBoolProperty'] = & $instance->privateBoolProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testSimpleGet(): void
if (! $realInstanceReflection->hasProperty($foo)) {
$targetObject = $this;
$backtrace = debug_backtrace(false);
$backtrace = debug_backtrace(false, 1);
trigger_error(
sprintf(
'Undefined property: %s::$%s in %s on line %s',
Expand All @@ -44,7 +44,7 @@ public function testSimpleGet(): void
$accessor = function & () use ($targetObject, $name) {
return $targetObject->$foo;
};
$backtrace = debug_backtrace(true);
$backtrace = debug_backtrace(true, 2);
$scopeObject = isset($backtrace[1]['object']) ? $backtrace[1]['object'] : new \ProxyManager\Stub\EmptyClassStub();
$accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));
$bar = & $accessor();
Expand Down Expand Up @@ -78,7 +78,7 @@ public function testSimpleSet(): void
$accessor = function & () use ($targetObject, $name, $value) {
return $targetObject->$foo = $baz;
};
$backtrace = debug_backtrace(true);
$backtrace = debug_backtrace(true, 2);
$scopeObject = isset($backtrace[1]['object']) ? $backtrace[1]['object'] : new \ProxyManager\Stub\EmptyClassStub();
$accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));
$bar = & $accessor();
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testSimpleIsset(): void
$accessor = function () use ($targetObject, $name) {
return isset($targetObject->$foo);
};
$backtrace = debug_backtrace(true);
$backtrace = debug_backtrace(true, 2);
$scopeObject = isset($backtrace[1]['object']) ? $backtrace[1]['object'] : new \ProxyManager\Stub\EmptyClassStub();
$accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));
$bar = $accessor();
Expand Down Expand Up @@ -146,7 +146,7 @@ public function testSimpleUnset(): void
$accessor = function () use ($targetObject, $name) {
unset($targetObject->$foo);
};
$backtrace = debug_backtrace(true);
$backtrace = debug_backtrace(true, 2);
$scopeObject = isset($backtrace[1]['object']) ? $backtrace[1]['object'] : new \ProxyManager\Stub\EmptyClassStub();
$accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));
$bar = $accessor();
Expand Down Expand Up @@ -193,7 +193,7 @@ public function testDelegatesToValueHolderWhenAvailable(): void
$accessor = function & () use ($targetObject, $name, $value) {
return $targetObject->$foo = $baz;
};
$backtrace = debug_backtrace(true);
$backtrace = debug_backtrace(true, 2);
$scopeObject = isset($backtrace[1]['object']) ? $backtrace[1]['object'] : new \ProxyManager\Stub\EmptyClassStub();
$accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));
$bar = & $accessor();
Expand Down Expand Up @@ -226,7 +226,7 @@ public function testWillReturnDirectlyWithNoReturnParam(): void
if (! $realInstanceReflection->hasProperty($foo)) {
$targetObject = $this;
$backtrace = debug_backtrace(false);
$backtrace = debug_backtrace(false, 1);
trigger_error(
sprintf(
'Undefined property: %s::$%s in %s on line %s',
Expand All @@ -245,7 +245,7 @@ public function testWillReturnDirectlyWithNoReturnParam(): void
$accessor = function & () use ($targetObject, $name) {
return $targetObject->$foo;
};
$backtrace = debug_backtrace(true);
$backtrace = debug_backtrace(true, 2);
$scopeObject = isset($backtrace[1]['object']) ? $backtrace[1]['object'] : new \ProxyManager\Stub\EmptyClassStub();
$accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));
$returnValue = & $accessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testBodyStructure(): void
'static $reflection;
if (! $this->foo) {
$reflection = $reflection ?: new \ReflectionClass(\'ProxyManagerTestAsset\\\\ProxyGenerator\\\\LazyLoading\\\\'
$reflection = $reflection ?? new \ReflectionClass(\'ProxyManagerTestAsset\\\\ProxyGenerator\\\\LazyLoading\\\\'
. 'MethodGenerator\\\\ClassWithTwoPublicProperties\');
$this->foo = $reflection->newInstanceWithoutConstructor();
unset($this->bar, $this->baz);
Expand All @@ -68,7 +68,7 @@ public function testBodyStructureWithoutPublicProperties(): void
'static $reflection;
if (! $this->foo) {
$reflection = $reflection ?: new \ReflectionClass(\'ProxyManagerTestAsset\\\\EmptyClass\');
$reflection = $reflection ?? new \ReflectionClass(\'ProxyManagerTestAsset\\\\EmptyClass\');
$this->foo = $reflection->newInstanceWithoutConstructor();
}',
$constructor->getBody()
Expand All @@ -89,7 +89,7 @@ public function testBodyStructureWithStaticProperties(): void
$expectedCode = 'static $reflection;
if (! $this->foo) {
$reflection = $reflection ?: new \ReflectionClass(\'ProxyManagerTestAsset\\\\ClassWithMixedProperties\');
$reflection = $reflection ?? new \ReflectionClass(\'ProxyManagerTestAsset\\\\ClassWithMixedProperties\');
$this->foo = $reflection->newInstanceWithoutConstructor();
unset($this->publicProperty0, $this->publicProperty1, $this->publicProperty2, $this->protectedProperty0, '
. '$this->protectedProperty1, $this->protectedProperty2);
Expand Down Expand Up @@ -121,7 +121,7 @@ public function testBodyStructureWithVariadicArguments(): void
static $reflection;
if (! $this->foo) {
$reflection = $reflection ?: new \ReflectionClass('ProxyManagerTestAsset\\ClassWithVariadicConstructorArgument');
$reflection = $reflection ?? new \ReflectionClass('ProxyManagerTestAsset\\ClassWithVariadicConstructorArgument');
$this->foo = $reflection->newInstanceWithoutConstructor();
\Closure::bind(function (\ProxyManagerTestAsset\ClassWithVariadicConstructorArgument $instance) {
unset($instance->foo, $instance->bar);
Expand Down
2 changes: 1 addition & 1 deletion tests/ProxyManagerTestAsset/ClassWithFinalMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final public function foo()
{
}

final private function bar()
private function bar()
{
}

Expand Down

0 comments on commit f65ae0f

Please sign in to comment.