AmpersandHQ / ampersand-magento2-upgrade-patch-helper

Helper script to aid upgrading magento 2 websites by detecting overrides. Now supports third party module detections
GNU Lesser General Public License v3.0
322 stars 39 forks source link

Removed typed properties syntax (introduced in PHP 7.4) so the code c… #100

Closed hostep closed 1 year ago

hostep commented 1 year ago

…an run again on PHP 7.2 or 7.3

Ran into this problem recently when using PHP 7.3 on a Magento 2.3.6 project The composer.json file, claims minimum compatibility with PHP 7.2 After talking to @convenient on Slack, he agreed we'd best fix this.


Maybe it's an idea to run the built-in php linter like this in the automated tests (for each supported php version):

$ find bin src -iname '*.php' -exec php72 -l {} \; | grep -v 'No syntax errors'
PHP Parse error:  syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST) in src/Ampersand/PatchHelper/Checks/ClassPreferencePhp.php on line 15

Parse error: syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST) in src/Ampersand/PatchHelper/Checks/ClassPreferencePhp.php on line 15
Errors parsing src/Ampersand/PatchHelper/Checks/ClassPreferencePhp.php
PHP Parse error:  syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST) in src/Ampersand/PatchHelper/Checks/SetupScriptPhp.php on line 14

Parse error: syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST) in src/Ampersand/PatchHelper/Checks/SetupScriptPhp.php on line 14
Errors parsing src/Ampersand/PatchHelper/Checks/SetupScriptPhp.php
PHP Parse error:  syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST) in src/Ampersand/PatchHelper/Checks/SetupPatchDataPhp.php on line 14

Parse error: syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST) in src/Ampersand/PatchHelper/Checks/SetupPatchDataPhp.php on line 14
Errors parsing src/Ampersand/PatchHelper/Checks/SetupPatchDataPhp.php
PHP Parse error:  syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST) in src/Ampersand/PatchHelper/Checks/SetupPatchSchemaPhp.php on line 14

Parse error: syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST) in src/Ampersand/PatchHelper/Checks/SetupPatchSchemaPhp.php on line 14
Errors parsing src/Ampersand/PatchHelper/Checks/SetupPatchSchemaPhp.php
PHP Parse error:  syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST) in src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php on line 14

Parse error: syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST) in src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php on line 14
Errors parsing src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php

Also https://github.com/PHPCompatibility/PHPCompatibility is able to find this:

$ /path/to/phpcs -s --standard=PHPCompatibility --exclude=PHPCompatibility.FunctionUse.NewFunctions --runtime-set testVersion 7.2- bin/ src/

FILE: src/Ampersand/PatchHelper/Checks/ClassPreferencePhp.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
 15 | ERROR | Typed properties are not supported in PHP 7.3 or earlier. Found: array
    |       | (PHPCompatibility.Classes.NewTypedProperties.Found)
-----------------------------------------------------------------------------------------------------------------------------------------

FILE: src/Ampersand/PatchHelper/Checks/SetupScriptPhp.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
 14 | ERROR | Typed properties are not supported in PHP 7.3 or earlier. Found: array
    |       | (PHPCompatibility.Classes.NewTypedProperties.Found)
-----------------------------------------------------------------------------------------------------------------------------------------

FILE: src/Ampersand/PatchHelper/Checks/SetupPatchDataPhp.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
 14 | ERROR | Typed properties are not supported in PHP 7.3 or earlier. Found: array
    |       | (PHPCompatibility.Classes.NewTypedProperties.Found)
-----------------------------------------------------------------------------------------------------------------------------------------

FILE: src/Ampersand/PatchHelper/Checks/SetupPatchSchemaPhp.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
 14 | ERROR | Typed properties are not supported in PHP 7.3 or earlier. Found: array
    |       | (PHPCompatibility.Classes.NewTypedProperties.Found)
-----------------------------------------------------------------------------------------------------------------------------------------

FILE: src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
 14 | ERROR | Typed properties are not supported in PHP 7.3 or earlier. Found: array
    |       | (PHPCompatibility.Classes.NewTypedProperties.Found)
-----------------------------------------------------------------------------------------------------------------------------------------

Time: 232ms; Memory: 8MB

I've excluded the PHPCompatibility.FunctionUse.NewFunctions rule, otherwise it complained about missing str_starts_with or str_contains, ... functions, but those are actually polyfilled by https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper/blob/34a19cd6597a51a7eca99bd87c47e9d850daf062/src/functions.php

Another remark for the PHPCompatibility tool, the latest stable version only supports up to PHP 7.4, but the develop branch has been updated through the years for support for PHP 8.0, 8.1 & 8.2 (not fully yet, but it's able to detect a lot of issues already)

Checklist