Skip to content

Commit 3552b1a

Browse files
Ayeshterabytesoftwsamdark
committed
[PHP 8.4] Fixes for implicit nullability deprecation (yiisoft#20133)
Fixes all issues that emit deprecation notices on PHP 8.4 for implicit nullable parameter type declarations. Related to yiisoft#20128. 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) Co-authored-by: Wilmer Arambula <[email protected]> Co-authored-by: Alexander Makarov <[email protected]>
1 parent e221365 commit 3552b1a

File tree

11 files changed

+21
-29
lines changed

11 files changed

+21
-29
lines changed

framework/base/Component.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ public function off($name, $handler = null)
605605
* @param string $name the event name
606606
* @param Event|null $event the event instance. If not set, a default [[Event]] object will be created.
607607
*/
608-
public function trigger($name, Event $event = null)
608+
public function trigger($name, ?Event $event = null)
609609
{
610610
$this->ensureBehaviors();
611611

framework/db/ActiveQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ public function orOnCondition($condition, $params = [])
785785
* @throws InvalidConfigException when query is not initialized properly
786786
* @see via()
787787
*/
788-
public function viaTable($tableName, $link, callable $callable = null)
788+
public function viaTable($tableName, $link, ?callable $callable = null)
789789
{
790790
$modelClass = $this->primaryModel ? get_class($this->primaryModel) : $this->modelClass;
791791
$relation = new self($modelClass, [

framework/db/ActiveQueryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function with();
9797
* Its signature should be `function($query)`, where `$query` is the query to be customized.
9898
* @return $this the relation object itself.
9999
*/
100-
public function via($relationName, callable $callable = null);
100+
public function via($relationName, ?callable $callable = null);
101101

102102
/**
103103
* Finds the related records for the specified primary record.

framework/db/ActiveRelationTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function __clone()
104104
* Its signature should be `function($query)`, where `$query` is the query to be customized.
105105
* @return $this the relation object itself.
106106
*/
107-
public function via($relationName, callable $callable = null)
107+
public function via($relationName, ?callable $callable = null)
108108
{
109109
$relation = $this->primaryModel->getRelation($relationName);
110110
$callableUsed = $callable !== null;

framework/mail/BaseMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ abstract class BaseMessage extends BaseObject implements MessageInterface
3939
* the "mailer" application component will be used instead.
4040
* @return bool whether this message is sent successfully.
4141
*/
42-
public function send(MailerInterface $mailer = null)
42+
public function send(?MailerInterface $mailer = null)
4343
{
4444
if ($mailer === null && $this->mailer === null) {
4545
$mailer = Yii::$app->getMailer();

framework/mail/MessageInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function embedContent($content, array $options = []);
209209
* If null, the "mailer" application component will be used instead.
210210
* @return bool whether this message is sent successfully.
211211
*/
212-
public function send(MailerInterface $mailer = null);
212+
public function send(?MailerInterface $mailer = null);
213213

214214
/**
215215
* Returns string representation of this message.

tests/framework/console/FakePhp71Controller.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414

1515
class FakePhp71Controller extends Controller
1616
{
17-
public function actionInjection(
18-
$before,
19-
Request $request,
20-
$between,
21-
DummyService $dummyService,
22-
Post $post = null,
23-
$after
24-
): void {
17+
public function actionInjection($before, Request $request, $between, DummyService $dummyService, ?Post $post = null, $after)
18+
{
19+
2520
}
2621

2722
public function actionNullableInjection(?Request $request, ?Post $post): void

tests/framework/di/ContainerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ public function testOptionalDependencies(): void
236236
{
237237
$container = new Container();
238238
// Test optional unresolvable dependency.
239-
$closure = fn(QuxInterface $test = null) => $test;
239+
$closure = function (?QuxInterface $test = null) {
240+
return $test;
241+
};
240242
$this->assertNull($container->invoke($closure));
241243
}
242244

tests/framework/di/stubs/Alpha.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ class Alpha extends BaseObject
1212
public $color = true;
1313

1414
public function __construct(
15-
Beta $beta = null,
16-
QuxInterface $omega = null,
17-
Unknown $unknown = null,
18-
AbstractColor $color = null
15+
?Beta $beta = null,
16+
?QuxInterface $omega = null,
17+
?Unknown $unknown = null,
18+
?AbstractColor $color = null
1919
) {
2020
$this->beta = $beta;
2121
$this->omega = $omega;

tests/framework/web/FakePhp71Controller.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,9 @@ class FakePhp71Controller extends Controller
2121
{
2222
public $enableCsrfValidation = false;
2323

24-
public function actionInjection(
25-
$before,
26-
Request $request,
27-
$between,
28-
VendorImage $vendorImage,
29-
Post $post = null,
30-
$after
31-
): void {
24+
public function actionInjection($before, Request $request, $between, VendorImage $vendorImage, ?Post $post = null, $after)
25+
{
26+
3227
}
3328

3429
public function actionNullableInjection(?Request $request, ?Post $post): void

0 commit comments

Comments
 (0)