Skip to content

Commit

Permalink
[PHP 8.4] Fixes for implicit nullability deprecation
Browse files Browse the repository at this point in the history
Fixes all issues that emit deprecation notices on PHP 8.4 for implicit nullable parameter type declarations.

See:
 - [RFC](https://wiki.php.net/rfc/deprecate-implicitly-nullable-types)
 - [PHP 8.4: Implicitly nullable parameter declarations deprecated](https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated)
  • Loading branch information
Ayesh authored and ghostwriter committed Mar 18, 2024
1 parent c9cf52d commit cbb5798
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions library/Mockery.php
Expand Up @@ -247,7 +247,7 @@ public static function fetchMock($name)
*
* @return string
*/
public static function formatArgs($method, array $arguments = null)
public static function formatArgs($method, ?array $arguments = null)
{
if ($arguments === null) {
return $method . '()';
Expand All @@ -266,7 +266,7 @@ public static function formatArgs($method, array $arguments = null)
*
* @return string
*/
public static function formatObjects(array $objects = null)
public static function formatObjects(?array $objects = null)
{
static $formatting;

Expand Down
2 changes: 1 addition & 1 deletion library/Mockery/Container.php
Expand Up @@ -101,7 +101,7 @@ class Container
*/
protected $instantiator;

public function __construct(Generator $generator = null, LoaderInterface $loader = null, Instantiator $instantiator = null)
public function __construct(?Generator $generator = null, ?LoaderInterface $loader = null, ?Instantiator $instantiator = null)
{
$this->_generator = $generator instanceof Generator ? $generator : Mockery::getDefaultGenerator();
$this->_loader = $loader instanceof LoaderInterface ? $loader : Mockery::getDefaultLoader();
Expand Down
4 changes: 2 additions & 2 deletions library/Mockery/Expectation.php
Expand Up @@ -362,7 +362,7 @@ public function andSet($name, ...$values)
*
* @return self
*/
public function andThrow($exception, $message = '', $code = 0, \Exception $previous = null)
public function andThrow($exception, $message = '', $code = 0, ?\Exception $previous = null)
{
$this->_throw = true;

Expand Down Expand Up @@ -391,7 +391,7 @@ public function andThrowExceptions(array $exceptions)
return $this->andReturnValues($exceptions);
}

public function andThrows($exception, $message = '', $code = 0, \Exception $previous = null)
public function andThrows($exception, $message = '', $code = 0, ?\Exception $previous = null)
{
return $this->andThrow($exception, $message, $code, $previous);
}
Expand Down
Expand Up @@ -79,7 +79,7 @@ public function apply($code, MockConfiguration $config)
*
* @return array
*/
public function getMagicMethods(TargetClassInterface $class = null)
public function getMagicMethods(?TargetClassInterface $class = null)
{
if (! $class instanceof TargetClassInterface) {
return [];
Expand Down
4 changes: 2 additions & 2 deletions library/Mockery/LegacyMockInterface.php
Expand Up @@ -107,7 +107,7 @@ public function mockery_getName();
*
* @return void
*/
public function mockery_init(Container $container = null, $partialObject = null);
public function mockery_init(?Container $container = null, $partialObject = null);

/**
* @return bool
Expand Down Expand Up @@ -220,7 +220,7 @@ public function shouldIgnoreMissing($returnValue = null);
*
* @return mixed
*/
public function shouldNotHaveBeenCalled(array $args = null);
public function shouldNotHaveBeenCalled(?array $args = null);

/**
* @param string $method
Expand Down
4 changes: 2 additions & 2 deletions library/Mockery/Mock.php
Expand Up @@ -181,7 +181,7 @@ class Mock implements MockInterface
* @param bool $instanceMock
* @return void
*/
public function mockery_init(Container $container = null, $partialObject = null, $instanceMock = true)
public function mockery_init(?Container $container = null, $partialObject = null, $instanceMock = true)

Check warning on line 184 in library/Mockery/Mock.php

View check run for this annotation

Codecov / codecov/patch

library/Mockery/Mock.php#L184

Added line #L184 was not covered by tests
{
if (is_null($container)) {
$container = new Container();
Expand Down Expand Up @@ -839,7 +839,7 @@ public function shouldNotHaveReceived($method = null, $args = null)
return null;
}

public function shouldNotHaveBeenCalled(array $args = null)
public function shouldNotHaveBeenCalled(?array $args = null)

Check warning on line 842 in library/Mockery/Mock.php

View check run for this annotation

Codecov / codecov/patch

library/Mockery/Mock.php#L842

Added line #L842 was not covered by tests
{
return $this->shouldNotHaveReceived('__invoke', $args);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Mockery/ContainerTest.php
Expand Up @@ -1777,7 +1777,7 @@ public function foo(callable $baz)
$baz();
}

public function bar(callable $callback = null)
public function bar(?callable $callback = null)
{
$callback();
}
Expand Down Expand Up @@ -1864,7 +1864,7 @@ public static function keepMe($b)

class MockeryTest_MethodWithRequiredParamWithDefaultValue
{
public function foo(DateTime $bar = null, $baz)
public function foo(?DateTime $bar = null, $baz)

Check warning on line 1867 in tests/Mockery/ContainerTest.php

View workflow job for this annotation

GitHub Actions / PHPUnit on PHP 8.1 with highest Dependencies

Optional parameter $bar declared before required parameter $baz is implicitly treated as a required parameter

Check warning on line 1867 in tests/Mockery/ContainerTest.php

View workflow job for this annotation

GitHub Actions / PHPUnit on PHP 8.1 with locked Dependencies

Optional parameter $bar declared before required parameter $baz is implicitly treated as a required parameter

Check warning on line 1867 in tests/Mockery/ContainerTest.php

View workflow job for this annotation

GitHub Actions / PHPUnit on PHP 8.2 with highest Dependencies

Optional parameter $bar declared before required parameter $baz is implicitly treated as a required parameter

Check warning on line 1867 in tests/Mockery/ContainerTest.php

View workflow job for this annotation

GitHub Actions / PHPUnit on PHP 8.2 with locked Dependencies

Optional parameter $bar declared before required parameter $baz is implicitly treated as a required parameter

Check warning on line 1867 in tests/Mockery/ContainerTest.php

View workflow job for this annotation

GitHub Actions / PHPUnit on PHP 8.3 with highest Dependencies

Optional parameter $bar declared before required parameter $baz is implicitly treated as a required parameter

Check warning on line 1867 in tests/Mockery/ContainerTest.php

View workflow job for this annotation

GitHub Actions / PHPUnit on PHP 8.3 with locked Dependencies

Optional parameter $bar declared before required parameter $baz is implicitly treated as a required parameter
{
}
}
Expand Down
Expand Up @@ -27,7 +27,7 @@ public function foo(?string $bar)
{
}

public function bar(string $bar = null)
public function bar(?string $bar = null)
{
}

Expand Down
Expand Up @@ -27,7 +27,7 @@ public function foo($bar = null)
{
}

public function bar(string $bar = null)
public function bar(?string $bar = null)
{
}
}

0 comments on commit cbb5798

Please sign in to comment.