Skip to content

Commit bc9bf7e

Browse files
committed
Require Null Safe Object operator
1 parent 5f16759 commit bc9bf7e

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

lib/Doctrine/ruleset.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@
266266
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator"/>
267267
<!-- Require usage of null coalesce operator when possible -->
268268
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
269+
<!-- Require usage of null safe operator when possible -->
270+
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator"/>
269271
<!-- Forbid usage of conditions when a simple return can be used -->
270272
<rule ref="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn"/>
271273
<!-- Forbid usage of boolean-only ternary operator usage (e.g. $foo ? true : false) -->

tests/fixed/null_safe_operator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$var = $object === null ? null : $object->property;

tests/input/null_safe_operator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$var = $object === null ? null : $object->property;

tests/php80-compatibility.patch

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
2-
index c644926..1b5b271 100644
2+
index c644926..d0f0a44 100644
33
--- a/tests/expected_report.txt
44
+++ b/tests/expected_report.txt
5-
@@ -15,17 +15,17 @@ tests/input/ControlStructures.php 28 0
5+
@@ -15,18 +15,19 @@ tests/input/ControlStructures.php 28 0
66
tests/input/doc-comment-spacing.php 11 0
77
tests/input/duplicate-assignment-variable.php 1 0
88
tests/input/EarlyReturn.php 6 0
@@ -22,9 +22,11 @@ index c644926..1b5b271 100644
2222
-tests/input/null_coalesce_equal_operator.php 1 0
2323
+tests/input/null_coalesce_equal_operator.php 5 0
2424
tests/input/null_coalesce_operator.php 3 0
25+
+tests/input/null_safe_operator.php 1 0
2526
tests/input/optimized-functions.php 1 0
2627
tests/input/PropertyTypeHintSpacing.php 6 0
27-
@@ -39,15 +39,15 @@ tests/input/superfluous-naming.php 11 0
28+
tests/input/return_type_on_closures.php 21 0
29+
@@ -39,15 +40,15 @@ tests/input/superfluous-naming.php 11 0
2830
tests/input/test-case.php 8 0
2931
tests/input/trailing_comma_on_array.php 1 0
3032
tests/input/traits-uses.php 11 0
@@ -36,10 +38,10 @@ index c644926..1b5b271 100644
3638
tests/input/UselessConditions.php 20 0
3739
----------------------------------------------------------------------
3840
-A TOTAL OF 377 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
39-
+A TOTAL OF 390 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
41+
+A TOTAL OF 391 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
4042
----------------------------------------------------------------------
4143
-PHPCBF CAN FIX 313 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
42-
+PHPCBF CAN FIX 326 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
44+
+PHPCBF CAN FIX 327 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
4345
----------------------------------------------------------------------
4446

4547

@@ -138,6 +140,16 @@ index 8846dd1..51c361c 100644
138140

139141
$bar = $bar['baz'] ?? 'baz';
140142

143+
diff --git a/tests/fixed/null_safe_operator.php b/tests/fixed/null_safe_operator.php
144+
index 5bbb636..7ce8a3d 100644
145+
--- a/tests/fixed/null_safe_operator.php
146+
+++ b/tests/fixed/null_safe_operator.php
147+
@@ -2,4 +2,4 @@
148+
149+
declare(strict_types=1);
150+
151+
-$var = $object === null ? null : $object->property;
152+
+$var = $object?->property;
141153
diff --git a/tests/fixed/type-hints.php b/tests/fixed/type-hints.php
142154
index 0e952fc..9824fb0 100644
143155
--- a/tests/fixed/type-hints.php

0 commit comments

Comments
 (0)