Skip to content

Commit

Permalink
Fix deprecations related to implicit nullable types
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Mar 19, 2024
1 parent ecadbdc commit 0235d4d
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 10 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"
operating-system:
- "ubuntu-latest"
fail-fast: false
Expand All @@ -50,10 +52,13 @@ jobs:
restore-keys: "php-${{ matrix.php-version }}"

- name: "Test with lowest dependencies"
if: "matrix.php-version != '8.2'"
if: "matrix.php-version != '8.4'"
run: |
composer update --prefer-lowest --no-interaction --no-progress --no-suggest && vendor/bin/simple-phpunit
composer update --prefer-lowest --no-interaction --no-progress --no-suggest
composer update symfony/phpunit-bridge --no-interaction --no-progress --no-suggest
vendor/bin/simple-phpunit
- name: "Test with highest dependencies"
run: |
composer update --no-interaction --no-progress --no-suggest $([[ "${{ matrix.php-version }}" = "8.2" ]] && echo ' --ignore-platform-req=php+') && vendor/bin/simple-phpunit
composer update --no-interaction --no-progress --no-suggest $([[ "${{ matrix.php-version }}" = "8.4" ]] && echo ' --ignore-platform-req=php+')
vendor/bin/simple-phpunit
5 changes: 5 additions & 0 deletions src/ProxyManager/Generator/MethodGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public static function copyMethodSignature(MethodReflection $reflectionMethod):

if ($default !== null) {
$parameter->setDefaultValue(new ValueGenerator($default, $reflectionParameter));
$type = $parameter->getType();

if ($default->getValue() === null && strpos($type ?? '?', '?') !== 0 && strpos($type, '|') === false) {
$parameter->setType('?' . $type);
}
}

$method->setParameter($parameter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(PropertyGenerator $prefixInterceptor)

$interceptor = new ParameterGenerator('prefixInterceptor');

$interceptor->setType(Closure::class);
$interceptor->setType('?' . Closure::class);
$interceptor->setDefaultValue(null);
$this->setParameter(new ParameterGenerator('methodName', 'string'));
$this->setParameter($interceptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(PropertyGenerator $suffixInterceptor)

$interceptor = new ParameterGenerator('suffixInterceptor');

$interceptor->setType(Closure::class);
$interceptor->setType('?' . Closure::class);
$interceptor->setDefaultValue(null);
$this->setParameter(new ParameterGenerator('methodName', 'string'));
$this->setParameter($interceptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(PropertyGenerator $initializerProperty)
{
parent::__construct(
'setProxyInitializer',
[(new ParameterGenerator('initializer', Closure::class))->setDefaultValue(null)],
[(new ParameterGenerator('initializer', '?' . Closure::class))->setDefaultValue(null)],
self::FLAG_PUBLIC,
'$this->' . $initializerProperty->getName() . ' = $initializer;'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(PropertyGenerator $initializerProperty)

$initializerParameter = new ParameterGenerator('initializer');

$initializerParameter->setType(Closure::class);
$initializerParameter->setType('?' . Closure::class);
$initializerParameter->setDefaultValue(null);
$this->setParameter($initializerParameter);
$this->setBody('$this->' . $initializerProperty->getName() . ' = $initializer;');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public static function staticProxyConstructor($instance, $prefixInterceptors, $s
return $selfInstance;
}

public function setMethodPrefixInterceptor(string $methodName, \Closure $prefixInterceptor = null) : void
public function setMethodPrefixInterceptor(string $methodName, ?\Closure $prefixInterceptor = null) : void
{
// no-op (on purpose)
}

public function setMethodSuffixInterceptor(string $methodName, \Closure $suffixInterceptor = null) : void
public function setMethodSuffixInterceptor(string $methodName, ?\Closure $suffixInterceptor = null) : void
{
// no-op (on purpose)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ProxyManagerTestAsset/LazyLoadingMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function staticProxyConstructor($initializer) : self
return $instance;
}

public function setProxyInitializer(\Closure $initializer = null) : void
public function setProxyInitializer(?\Closure $initializer = null) : void
{
$this->initializer = $initializer;
}
Expand Down

0 comments on commit 0235d4d

Please sign in to comment.