Skip to content

Commit

Permalink
Require Null Safe Object operator
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Jul 18, 2021
1 parent 8f59dde commit f997609
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/Doctrine/ruleset.xml
Expand Up @@ -266,6 +266,8 @@
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator"/>
<!-- Require usage of null coalesce operator when possible -->
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
<!-- Require usage of null safe operator when possible -->
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator"/>
<!-- Forbid usage of conditions when a simple return can be used -->
<rule ref="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn"/>
<!-- Forbid usage of boolean-only ternary operator usage (e.g. $foo ? true : false) -->
Expand Down
5 changes: 3 additions & 2 deletions tests/expected_report.txt
Expand Up @@ -27,6 +27,7 @@ tests/input/new_with_parentheses.php 18 0
tests/input/not_spacing.php 8 0
tests/input/null_coalesce_equal_operator.php 1 0
tests/input/null_coalesce_operator.php 3 0
tests/input/null_safe_operator.php 1 0
tests/input/optimized-functions.php 1 0
tests/input/PropertyTypeHintSpacing.php 6 0
tests/input/return_type_on_closures.php 21 0
Expand All @@ -45,9 +46,9 @@ tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
A TOTAL OF 377 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
A TOTAL OF 378 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 313 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 314 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


5 changes: 5 additions & 0 deletions tests/fixed/null_safe_operator.php
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

$var = $object?->property;
5 changes: 5 additions & 0 deletions tests/input/null_safe_operator.php
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

$var = $object === null ? null : $object->property;
11 changes: 6 additions & 5 deletions tests/php-compatibility.patch
Expand Up @@ -11,7 +11,7 @@ index fd5432c..233e24d 100644
tests/input/forbidden-comments.php 14 0
tests/input/forbidden-functions.php 6 0
tests/input/inline_type_hint_assertions.php 7 0
@@ -23,9 +23,9 @@ tests/input/LowCaseTypes.php 2 0
@@ -23,10 +23,10 @@ tests/input/LowCaseTypes.php 2 0
tests/input/namespaces-spacing.php 7 0
tests/input/NamingCamelCase.php 6 0
tests/input/negation-operator.php 2 0
Expand All @@ -21,6 +21,7 @@ index fd5432c..233e24d 100644
-tests/input/null_coalesce_equal_operator.php 1 0
+tests/input/null_coalesce_equal_operator.php 5 0
tests/input/null_coalesce_operator.php 3 0
tests/input/null_safe_operator.php 1 0
tests/input/optimized-functions.php 1 0
tests/input/PropertyTypeHintSpacing.php 6 0
@@ -39,15 +39,15 @@ tests/input/superfluous-naming.php 11 0
Expand All @@ -34,11 +35,11 @@ index fd5432c..233e24d 100644
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 377 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
+A TOTAL OF 386 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
-A TOTAL OF 378 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
+A TOTAL OF 387 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 313 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 322 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 314 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 323 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down

0 comments on commit f997609

Please sign in to comment.