Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow string property fetch #310

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"require": {
"php": "^7.2 || ^8.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0.0",
"slevomat/coding-standard": "^8.6.2",
"slevomat/coding-standard": "^8.10.0",
"squizlabs/php_codesniffer": "^3.7"
},
"config": {
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
<rule ref="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants"/>
<!-- Forbid more than one constant declared per statement -->
<rule ref="SlevomatCodingStandard.Classes.DisallowMultiConstantDefinition"/>
<!-- Forbid string expression property fetch ($foo->{'bar'}) -->
<rule ref="SlevomatCodingStandard.Classes.DisallowStringExpressionPropertyFetch"/>
<!-- Forbid empty lines around type declarations -->
<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces">
<properties>
Expand Down
5 changes: 3 additions & 2 deletions tests/expected_report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tests/input/semicolon_spacing.php 3 0
tests/input/single-line-array-spacing.php 5 0
tests/input/spread-operator.php 6 0
tests/input/static-closures.php 1 0
tests/input/string_property_fetch.php 1 0
tests/input/strings.php 3 0
tests/input/superfluous-naming.php 11 0
tests/input/test-case.php 8 0
Expand All @@ -52,9 +53,9 @@ tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 21 0
----------------------------------------------------------------------
A TOTAL OF 453 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
A TOTAL OF 454 ERRORS AND 0 WARNINGS WERE FOUND IN 49 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 375 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 376 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


6 changes: 6 additions & 0 deletions tests/fixed/string_property_fetch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

declare(strict_types=1);

$a = new stdClass();
$a->b = 'hi';
6 changes: 6 additions & 0 deletions tests/input/string_property_fetch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

declare(strict_types=1);

$a = new stdClass();
$a->{'b'} = 'hi';
10 changes: 5 additions & 5 deletions tests/php72-compatibility.patch
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ index d1e1fad..ea3b611 100644
tests/input/semicolon_spacing.php 3 0
tests/input/single-line-array-spacing.php 5 0
tests/input/spread-operator.php 6 0
@@ -44,17 +41,16 @@ tests/input/strings.php 1 0
@@ -43,17 +42,16 @@ tests/input/strings.php 1 0
tests/input/superfluous-naming.php 11 0
tests/input/test-case.php 8 0
tests/input/trailing_comma_on_array.php 1 0
Expand All @@ -55,11 +55,11 @@ index d1e1fad..ea3b611 100644
-tests/input/UselessConditions.php 21 0
+tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 453 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 406 ERRORS AND 0 WARNINGS WERE FOUND IN 44 FILES
-A TOTAL OF 454 ERRORS AND 0 WARNINGS WERE FOUND IN 49 FILES
+A TOTAL OF 407 ERRORS AND 0 WARNINGS WERE FOUND IN 45 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 375 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 328 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 376 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 329 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down
10 changes: 5 additions & 5 deletions tests/php73-compatibility.patch
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ index d1e1fad..9a78bc1 100644
tests/input/semicolon_spacing.php 3 0
tests/input/single-line-array-spacing.php 5 0
tests/input/spread-operator.php 6 0
@@ -44,17 +41,17 @@ tests/input/strings.php 1 0
@@ -43,17 +42,17 @@ tests/input/strings.php 1 0
tests/input/superfluous-naming.php 11 0
tests/input/test-case.php 8 0
tests/input/trailing_comma_on_array.php 1 0
Expand All @@ -56,11 +56,11 @@ index d1e1fad..9a78bc1 100644
-tests/input/UselessConditions.php 21 0
+tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 453 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 408 ERRORS AND 0 WARNINGS WERE FOUND IN 45 FILES
-A TOTAL OF 454 ERRORS AND 0 WARNINGS WERE FOUND IN 49 FILES
+A TOTAL OF 409 ERRORS AND 0 WARNINGS WERE FOUND IN 46 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 375 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 330 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 376 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 331 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down
10 changes: 5 additions & 5 deletions tests/php74-compatibility.patch
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ index d1e1fad..ed67841 100644
tests/input/semicolon_spacing.php 3 0
tests/input/single-line-array-spacing.php 5 0
tests/input/spread-operator.php 6 0
@@ -44,17 +41,17 @@ tests/input/strings.php 1 0
@@ -43,17 +42,17 @@ tests/input/strings.php 1 0
tests/input/superfluous-naming.php 11 0
tests/input/test-case.php 8 0
tests/input/trailing_comma_on_array.php 1 0
Expand All @@ -54,11 +54,11 @@ index d1e1fad..ed67841 100644
-tests/input/UselessConditions.php 21 0
+tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 453 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 417 ERRORS AND 0 WARNINGS WERE FOUND IN 45 FILES
-A TOTAL OF 454 ERRORS AND 0 WARNINGS WERE FOUND IN 49 FILES
+A TOTAL OF 418 ERRORS AND 0 WARNINGS WERE FOUND IN 46 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 375 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 339 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 376 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 340 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down
10 changes: 5 additions & 5 deletions tests/php80-compatibility.patch
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ index d1e1fad..71022c4 100644
tests/input/return_type_on_closures.php 26 0
tests/input/return_type_on_methods.php 22 0
tests/input/semicolon_spacing.php 3 0
@@ -52,9 +51,9 @@ tests/input/use-ordering.php 1 0
@@ -51,9 +52,9 @@ tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 21 0
----------------------------------------------------------------------
-A TOTAL OF 453 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 447 ERRORS AND 0 WARNINGS WERE FOUND IN 47 FILES
-A TOTAL OF 454 ERRORS AND 0 WARNINGS WERE FOUND IN 49 FILES
+A TOTAL OF 448 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 375 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 369 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 376 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 370 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down