Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecations related to implicit nullable types #37

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading