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 15, 2024
1 parent b0aa6ab commit d4e4d08
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 15 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)
{
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/console/FakePhp71Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class FakePhp71Controller extends Controller
{
public function actionInjection($before, Request $request, $between, DummyService $dummyService, Post $post = null, $after)
public function actionInjection($before, Request $request, $between, DummyService $dummyService, ?Post $post = null, $after)
{

}
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 @@ -252,7 +252,7 @@ public function testOptionalDependencies()
{
$container = new Container();
// Test optional unresolvable dependency.
$closure = function (QuxInterface $test = null) {
$closure = function (?QuxInterface $test = null) {
return $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/web/FakePhp71Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FakePhp71Controller extends Controller
{
public $enableCsrfValidation = false;

public function actionInjection($before, Request $request, $between, VendorImage $vendorImage, Post $post = null, $after)
public function actionInjection($before, Request $request, $between, VendorImage $vendorImage, ?Post $post = null, $after)
{

}
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)
public function actionAksi1(int $foo, ?float $bar = null, bool $true, bool $false)
{
}

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

0 comments on commit d4e4d08

Please sign in to comment.