Skip to content

Commit f997609

Browse files
committed
Require Null Safe Object operator
1 parent 8f59dde commit f997609

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
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/expected_report.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ tests/input/new_with_parentheses.php 18 0
2727
tests/input/not_spacing.php 8 0
2828
tests/input/null_coalesce_equal_operator.php 1 0
2929
tests/input/null_coalesce_operator.php 3 0
30+
tests/input/null_safe_operator.php 1 0
3031
tests/input/optimized-functions.php 1 0
3132
tests/input/PropertyTypeHintSpacing.php 6 0
3233
tests/input/return_type_on_closures.php 21 0
@@ -45,9 +46,9 @@ tests/input/use-ordering.php 1 0
4546
tests/input/useless-semicolon.php 2 0
4647
tests/input/UselessConditions.php 20 0
4748
----------------------------------------------------------------------
48-
A TOTAL OF 377 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
49+
A TOTAL OF 378 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
4950
----------------------------------------------------------------------
50-
PHPCBF CAN FIX 313 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
51+
PHPCBF CAN FIX 314 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
5152
----------------------------------------------------------------------
5253

5354

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?->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/php-compatibility.patch

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ index fd5432c..233e24d 100644
1111
tests/input/forbidden-comments.php 14 0
1212
tests/input/forbidden-functions.php 6 0
1313
tests/input/inline_type_hint_assertions.php 7 0
14-
@@ -23,9 +23,9 @@ tests/input/LowCaseTypes.php 2 0
14+
@@ -23,10 +23,10 @@ tests/input/LowCaseTypes.php 2 0
1515
tests/input/namespaces-spacing.php 7 0
1616
tests/input/NamingCamelCase.php 6 0
1717
tests/input/negation-operator.php 2 0
@@ -21,6 +21,7 @@ index fd5432c..233e24d 100644
2121
-tests/input/null_coalesce_equal_operator.php 1 0
2222
+tests/input/null_coalesce_equal_operator.php 5 0
2323
tests/input/null_coalesce_operator.php 3 0
24+
tests/input/null_safe_operator.php 1 0
2425
tests/input/optimized-functions.php 1 0
2526
tests/input/PropertyTypeHintSpacing.php 6 0
2627
@@ -39,15 +39,15 @@ tests/input/superfluous-naming.php 11 0
@@ -34,11 +35,11 @@ index fd5432c..233e24d 100644
3435
tests/input/useless-semicolon.php 2 0
3536
tests/input/UselessConditions.php 20 0
3637
----------------------------------------------------------------------
37-
-A TOTAL OF 377 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
38-
+A TOTAL OF 386 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
38+
-A TOTAL OF 378 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
39+
+A TOTAL OF 387 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
3940
----------------------------------------------------------------------
40-
-PHPCBF CAN FIX 313 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
41-
+PHPCBF CAN FIX 322 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
41+
-PHPCBF CAN FIX 314 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
42+
+PHPCBF CAN FIX 323 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
4243
----------------------------------------------------------------------
4344

4445

0 commit comments

Comments
 (0)