Skip to content

Commit

Permalink
[PHP 8.4] Fixes for implicit nullability deprecation (#337)
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 Apr 23, 2024
1 parent 9eb17b7 commit 78aa6be
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 99 deletions.
6 changes: 3 additions & 3 deletions lib/Assert/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class Assert
* The assertion chain can be stateful, that means be careful when you reuse
* it. You should never pass around the chain.
*/
public static function that($value, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain
public static function that($value, $defaultMessage = null, ?string $defaultPropertyPath = null): AssertionChain
{
$assertionChain = new AssertionChain($value, $defaultMessage, $defaultPropertyPath);

Expand All @@ -55,7 +55,7 @@ public static function that($value, $defaultMessage = null, string $defaultPrope
* @param mixed $values
* @param string|callable|null $defaultMessage
*/
public static function thatAll($values, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain
public static function thatAll($values, $defaultMessage = null, ?string $defaultPropertyPath = null): AssertionChain
{
return static::that($values, $defaultMessage, $defaultPropertyPath)->all();
}
Expand All @@ -66,7 +66,7 @@ public static function thatAll($values, $defaultMessage = null, string $defaultP
* @param mixed $value
* @param string|callable|null $defaultMessage
*/
public static function thatNullOr($value, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain
public static function thatNullOr($value, $defaultMessage = null, ?string $defaultPropertyPath = null): AssertionChain
{
return static::that($value, $defaultMessage, $defaultPropertyPath)->nullOr();
}
Expand Down
178 changes: 89 additions & 89 deletions lib/Assert/Assertion.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/Assert/AssertionChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class AssertionChain
* @param mixed $value
* @param string|callable|null $defaultMessage
*/
public function __construct($value, $defaultMessage = null, string $defaultPropertyPath = null)
public function __construct($value, $defaultMessage = null, ?string $defaultPropertyPath = null)
{
$this->value = $value;
$this->defaultMessage = $defaultMessage;
Expand Down
2 changes: 1 addition & 1 deletion lib/Assert/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class InvalidArgumentException extends \InvalidArgumentException implements Asse
*/
private $constraints;

public function __construct($message, $code, string $propertyPath = null, $value = null, array $constraints = [])
public function __construct($message, $code, ?string $propertyPath = null, $value = null, array $constraints = [])
{
parent::__construct($message, $code);

Expand Down
2 changes: 1 addition & 1 deletion lib/Assert/LazyAssertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class LazyAssertion
*
* @return static
*/
public function that($value, string $propertyPath = null, $defaultMessage = null)
public function that($value, ?string $propertyPath = null, $defaultMessage = null)
{
$this->currentChainFailed = false;
$this->thisChainTryAll = false;
Expand Down
6 changes: 3 additions & 3 deletions lib/Assert/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* The assertion chain can be stateful, that means be careful when you reuse
* it. You should never pass around the chain.
*/
function that($value, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain
function that($value, $defaultMessage = null, ?string $defaultPropertyPath = null): AssertionChain
{
return Assert::that($value, $defaultMessage, $defaultPropertyPath);
}
Expand All @@ -44,7 +44,7 @@ function that($value, $defaultMessage = null, string $defaultPropertyPath = null
* @param string|callable|null $defaultMessage
* @param string $defaultPropertyPath
*/
function thatAll($values, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain
function thatAll($values, $defaultMessage = null, ?string $defaultPropertyPath = null): AssertionChain
{
return Assert::thatAll($values, $defaultMessage, $defaultPropertyPath);
}
Expand All @@ -58,7 +58,7 @@ function thatAll($values, $defaultMessage = null, string $defaultPropertyPath =
*
* @deprecated In favour of Assert::thatNullOr($value, $defaultMessage = null, $defaultPropertyPath = null)
*/
function thatNullOr($value, $defaultMessage = null, string $defaultPropertyPath = null): AssertionChain
function thatNullOr($value, $defaultMessage = null, ?string $defaultPropertyPath = null): AssertionChain
{
return Assert::thatNullOr($value, $defaultMessage, $defaultPropertyPath);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Assert/Tests/Fixtures/CustomAssertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function getCalls()
return self::$calls;
}

public static function string($value, $message = null, string $propertyPath = null): bool
public static function string($value, $message = null, ?string $propertyPath = null): bool
{
self::$calls[] = ['string', $value];

Expand Down

0 comments on commit 78aa6be

Please sign in to comment.