From 21956b228b0b757741e73178aeff0da5fd25577e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 13 Apr 2023 21:14:11 +0200 Subject: [PATCH] Disallow string property fetch While we're unlikely to manually write such things, there are custom rectors I've been writing that do so, and massively. --- composer.json | 2 +- lib/Doctrine/ruleset.xml | 2 ++ tests/expected_report.txt | 5 +++-- tests/fixed/string_property_fetch.php | 6 ++++++ tests/input/string_property_fetch.php | 6 ++++++ tests/php72-compatibility.patch | 10 +++++----- tests/php73-compatibility.patch | 10 +++++----- tests/php74-compatibility.patch | 10 +++++----- tests/php80-compatibility.patch | 10 +++++----- 9 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 tests/fixed/string_property_fetch.php create mode 100644 tests/input/string_property_fetch.php diff --git a/composer.json b/composer.json index e0082438..0fc2121b 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/lib/Doctrine/ruleset.xml b/lib/Doctrine/ruleset.xml index ed99bc4e..a7b2266d 100644 --- a/lib/Doctrine/ruleset.xml +++ b/lib/Doctrine/ruleset.xml @@ -136,6 +136,8 @@ + + diff --git a/tests/expected_report.txt b/tests/expected_report.txt index 17734237..18e5ae20 100644 --- a/tests/expected_report.txt +++ b/tests/expected_report.txt @@ -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 @@ -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 ---------------------------------------------------------------------- diff --git a/tests/fixed/string_property_fetch.php b/tests/fixed/string_property_fetch.php new file mode 100644 index 00000000..3cce1b29 --- /dev/null +++ b/tests/fixed/string_property_fetch.php @@ -0,0 +1,6 @@ +b = 'hi'; diff --git a/tests/input/string_property_fetch.php b/tests/input/string_property_fetch.php new file mode 100644 index 00000000..b5729f3c --- /dev/null +++ b/tests/input/string_property_fetch.php @@ -0,0 +1,6 @@ +{'b'} = 'hi'; diff --git a/tests/php72-compatibility.patch b/tests/php72-compatibility.patch index c9767ac2..33934048 100644 --- a/tests/php72-compatibility.patch +++ b/tests/php72-compatibility.patch @@ -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 @@ -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 ---------------------------------------------------------------------- diff --git a/tests/php73-compatibility.patch b/tests/php73-compatibility.patch index b98e0ad1..c5c4e849 100644 --- a/tests/php73-compatibility.patch +++ b/tests/php73-compatibility.patch @@ -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 @@ -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 ---------------------------------------------------------------------- diff --git a/tests/php74-compatibility.patch b/tests/php74-compatibility.patch index c3d3cccf..2b015240 100644 --- a/tests/php74-compatibility.patch +++ b/tests/php74-compatibility.patch @@ -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 @@ -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 ---------------------------------------------------------------------- diff --git a/tests/php80-compatibility.patch b/tests/php80-compatibility.patch index 9321f053..82c013b5 100644 --- a/tests/php80-compatibility.patch +++ b/tests/php80-compatibility.patch @@ -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 ----------------------------------------------------------------------