diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index ad6af891..4c9d3c6c 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -24,6 +24,8 @@ jobs: - "8.0" - "8.1" - "8.2" + - "8.3" + - "8.4" operating-system: - "ubuntu-latest" fail-fast: false @@ -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 diff --git a/src/ProxyManager/Generator/MethodGenerator.php b/src/ProxyManager/Generator/MethodGenerator.php index ce4937fd..1349c4e7 100644 --- a/src/ProxyManager/Generator/MethodGenerator.php +++ b/src/ProxyManager/Generator/MethodGenerator.php @@ -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); diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptor.php index 4b2cbe7e..5fa22a1a 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodPrefixInterceptor.php @@ -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); diff --git a/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptor.php b/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptor.php index 90a1ac05..e9ba9f16 100644 --- a/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptor.php +++ b/src/ProxyManager/ProxyGenerator/AccessInterceptor/MethodGenerator/SetMethodSuffixInterceptor.php @@ -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); diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializer.php b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializer.php index 54ed2562..0f9e3111 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializer.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingGhost/MethodGenerator/SetProxyInitializer.php @@ -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;' ); diff --git a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializer.php b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializer.php index b2998c79..9c896e7b 100644 --- a/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializer.php +++ b/src/ProxyManager/ProxyGenerator/LazyLoadingValueHolder/MethodGenerator/SetProxyInitializer.php @@ -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;'); diff --git a/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php b/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php index 38cc472d..372ef702 100644 --- a/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php +++ b/tests/ProxyManagerTestAsset/AccessInterceptorValueHolderMock.php @@ -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) } diff --git a/tests/ProxyManagerTestAsset/LazyLoadingMock.php b/tests/ProxyManagerTestAsset/LazyLoadingMock.php index 6a936236..5426a9e6 100644 --- a/tests/ProxyManagerTestAsset/LazyLoadingMock.php +++ b/tests/ProxyManagerTestAsset/LazyLoadingMock.php @@ -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; }