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 committed Mar 16, 2024
1 parent 3587dfb commit cbd41f0
Show file tree
Hide file tree
Showing 20 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion framework/base/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public function off($name, $handler = null)
* @param string $name the event name
* @param Event|null $event the event instance. If not set, a default [[Event]] object will be created.
*/
public function trigger($name, Event $event = null)
public function trigger($name, ?Event $event = null)
{
$this->ensureBehaviors();

Expand Down
2 changes: 1 addition & 1 deletion framework/db/ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ public function orOnCondition($condition, $params = [])
* @throws InvalidConfigException when query is not initialized properly
* @see via()
*/
public function viaTable($tableName, $link, callable $callable = null)
public function viaTable($tableName, $link, ?callable $callable = null)
{
$modelClass = $this->primaryModel ? get_class($this->primaryModel) : $this->modelClass;
$relation = new self($modelClass, [
Expand Down
2 changes: 1 addition & 1 deletion framework/db/ActiveQueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function with();
* Its signature should be `function($query)`, where `$query` is the query to be customized.
* @return $this the relation object itself.
*/
public function via($relationName, callable $callable = null);
public function via($relationName, ?callable $callable = null);

/**
* Finds the related records for the specified primary record.
Expand Down
2 changes: 1 addition & 1 deletion framework/db/ActiveRelationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function __clone()
* Its signature should be `function($query)`, where `$query` is the query to be customized.
* @return $this the relation object itself.
*/
public function via($relationName, callable $callable = null)
public function via($relationName, ?callable $callable = null)
{
$relation = $this->primaryModel->getRelation($relationName);
$callableUsed = $callable !== null;
Expand Down
2 changes: 1 addition & 1 deletion framework/mail/BaseMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class BaseMessage extends BaseObject implements MessageInterface
* the "mailer" application component will be used instead.
* @return bool whether this message is sent successfully.
*/
public function send(MailerInterface $mailer = null)
public function send(?MailerInterface $mailer = null)

Check warning on line 41 in framework/mail/BaseMessage.php

View check run for this annotation

Codecov / codecov/patch

framework/mail/BaseMessage.php#L41

Added line #L41 was not covered by tests
{
if ($mailer === null && $this->mailer === null) {
$mailer = Yii::$app->getMailer();
Expand Down
2 changes: 1 addition & 1 deletion framework/mail/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function embedContent($content, array $options = []);
* If null, the "mailer" application component will be used instead.
* @return bool whether this message is sent successfully.
*/
public function send(MailerInterface $mailer = null);
public function send(?MailerInterface $mailer = null);

/**
* Returns string representation of this message.
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/base/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testRunAction(): void
public function testCreateInlineAction(
string $controllerClass,
string $actionId,
string $expectedActionMethod = null
?string $expectedActionMethod = null
): void {
$this->mockApplication();
/** @var Controller $controller */
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/behaviors/AttributeBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testPreserveNonEmptyValues(
string $aliasExpected,
bool $preserveNonEmptyValues,
string $name,
string $alias = null
?string $alias = null
): void {
$model = new ActiveRecordWithAttributeBehavior();
$model->attributeBehavior->preserveNonEmptyValues = $preserveNonEmptyValues;
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/behaviors/AttributesBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testPreserveNonEmptyValues(
string $aliasExpected,
bool $preserveNonEmptyValues,
string $name,
string $alias = null
?string $alias = null
): void {
$model = new ActiveRecordWithAttributesBehavior();
$model->attributesBehavior->preserveNonEmptyValues = $preserveNonEmptyValues;
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/console/FakePhp71Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function actionInjection(
Request $request,
$between,
DummyService $dummyService,
Post $post = null,
?Post $post = null,
$after
): void {
}
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/console/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static function provider(): array
* @param array $expected The expected result.
* @param array|null $expectedException The expected exception.
*/
public function testResolve(array $params, array $expected, array $expectedException = null): void
public function testResolve(array $params, array $expected, ?array $expectedException = null): void
{
if (isset($expectedException)) {
$this->expectException($expectedException[0]);
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/di/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function testOptionalDependencies(): void
{
$container = new Container();
// Test optional unresolvable dependency.
$closure = fn(QuxInterface $test = null) => $test;
$closure = fn(?QuxInterface $test = null) => $test;
$this->assertNull($container->invoke($closure));
}

Expand Down
8 changes: 4 additions & 4 deletions tests/framework/di/stubs/Alpha.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class Alpha extends BaseObject
public $color = true;

public function __construct(
Beta $beta = null,
QuxInterface $omega = null,
Unknown $unknown = null,
AbstractColor $color = null
?Beta $beta = null,
?QuxInterface $omega = null,
?Unknown $unknown = null,
?AbstractColor $color = null
) {
$this->beta = $beta;
$this->omega = $omega;
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/filters/AccessRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function mockRequest(string $method = 'GET'): Request
return $request;
}

protected function mockUser(string $userid = null): User
protected function mockUser(?string $userid = null): User
{
$user = new User([
'identityClass' => UserIdentity::class,
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/helpers/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ function ($model): void {
/**
* @dataProvider errorSummaryDataProvider
*/
public function testErrorSummary(string $value, array $options, string $expectedHtml, \Closure $beforeValidate = null): void
public function testErrorSummary(string $value, array $options, string $expectedHtml, ?\Closure $beforeValidate = null): void
{
$model = new HtmlTestModel();
$model->name = $value;
Expand Down
4 changes: 2 additions & 2 deletions tests/framework/i18n/FormatterDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public static function dateInputs()
* @param mixed $value
* @param mixed|null $expectedException
*/
public function testIntlDateInput(string|bool $expected, string $value, string $expectedException = null): void
public function testIntlDateInput(string|bool $expected, string $value, ?string $expectedException = null): void
{
$this->testDateInput($expected, $value, $expectedException);
}
Expand All @@ -564,7 +564,7 @@ public function testIntlDateInput(string|bool $expected, string $value, string $
* @param mixed $value
* @param mixed|null $expectedException
*/
public function testDateInput(string|bool $expected, string $value, string $expectedException = null): void
public function testDateInput(string|bool $expected, string $value, ?string $expectedException = null): void
{
if ($expectedException !== null) {
$this->expectException($expectedException);
Expand Down
4 changes: 2 additions & 2 deletions tests/framework/rest/IndexActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public function testPrepareSearchQueryAttribute(): void
public function testPrepareDataProviderWithPaginationAndSorting(
\yii\data\Pagination|bool|array $pagination,
\yii\data\Sort|bool|array $sort,
int $expectedPaginationPageSize = null,
int $expectedPaginationDefaultPageSize = null,
?int $expectedPaginationPageSize = null,
?int $expectedPaginationDefaultPageSize = null,
array $expectedSortOrders = [],
?array $expectedSortDefaultOrder = null
): void {
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/web/AssetBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public static function registerFileDataProvider()
* @param string|bool $appendTimestamp
* @param string|null $webAlias
*/
public function testRegisterFileAppendTimestamp(string $type, string $path, bool $appendTimestamp, string $expected, string $webAlias = null): void
public function testRegisterFileAppendTimestamp(string $type, string $path, bool $appendTimestamp, string $expected, ?string $webAlias = null): void
{
$originalAlias = Yii::getAlias('@web');
if ($webAlias === null) {
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/web/FakePhp71Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function actionInjection(
Request $request,
$between,
VendorImage $vendorImage,
Post $post = null,
?Post $post = null,
$after
): void {
}
Expand Down
4 changes: 2 additions & 2 deletions tests/framework/web/FakePhp7Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class FakePhp7Controller extends Controller
{
public $enableCsrfValidation = false;

public function actionAksi1(int $foo, float $bar = null, bool $true, bool $false): void
public function actionAksi1(int $foo, ?float $bar = null, bool $true, bool $false): void
{
}

public function actionStringy(string $foo = null): void
public function actionStringy(?string $foo = null): void
{
}
}

0 comments on commit cbd41f0

Please sign in to comment.