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

PHPCompatibility v10 #1

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9af66e8
PHPCompatibility: development branch (PHP 8 support)
jrchamp Oct 15, 2021
3d5fdce
PHPCompatibility: development branch (PHP 8.0/8.1 support)
jrchamp May 26, 2022
9640e7e
bump versions: PHPCS 3.7.1; PHPCSUtils develop; PHP 7.2
jrchamp Jul 29, 2022
93b0481
moodle: use moodle-cs repo (v3.2.4) instead of local_codechecker
jrchamp Jul 29, 2022
9d12f2a
DELTA: Ignore WordPress-specific rules for ini_set()
jrchamp Sep 16, 2022
1abc8db
moodle-cs: v3.2.5
jrchamp Dec 2, 2022
64a562c
PHPCompatibility: develop branch 2022-11-22; PHPCSUtils: 1.0.0-alpha4
jrchamp Dec 2, 2022
e7ad191
cleanup: fix phpcs errors in the runner
jrchamp Dec 2, 2022
4b045a4
PHPCompatibility: develop branch 2023-01-08; PHPCSUtils: 1.0.1; moodl…
jrchamp Jan 18, 2023
6bbf6d8
PHPCSExtra: v1.0.2
jrchamp Feb 24, 2023
8c66c67
delta: Ignore package tag rule
jrchamp Feb 24, 2023
f036cc9
moodle-cs: v3.3.2
jrchamp Feb 24, 2023
8d3be1b
PHP_CodeSniffer: 3.7.2
jrchamp Feb 24, 2023
e464378
rulesets: use full WordPress for wp ruleset; exclude unhelpful rules …
jrchamp May 9, 2023
57142d5
WordPress: develop branch 2023-05-01; add PHPCSExtra to paths;
jrchamp May 16, 2023
87cb445
moodle: Include non-conflicting rules from the PSR1 and PSR12 standards.
jrchamp May 16, 2023
f27f181
rulesets: Ignore PHPCompatibility htmlspecialchars() flags sniff (we …
jrchamp May 16, 2023
4865bcb
PHPCompatibility: develop branch 2023-05-14; PHPCSUtils: 1.0.5; PHPCS…
jrchamp May 16, 2023
0a36371
ruleset: delta - more complete rules; phpcompatibility - also check s…
jrchamp May 23, 2023
a995b26
PHPCSExtra: 1.1.1; PHPCSUtils: 1.0.8; PHPCompatibility: develop branc…
jrchamp Sep 19, 2023
48eee8f
rulesets: check PHP syntax; use moodle-extra
jrchamp Sep 19, 2023
ef0351f
delta: remove more WordPress spaces
jrchamp Sep 19, 2023
402fdc7
delta: exclude more WordPress-specific rules
jrchamp Sep 19, 2023
472d84f
moodle-cs: v3.3.9; remove namescape fix that was merged upstream
jrchamp Sep 28, 2023
0195acb
moodle-cs: v3.3.11; PHPCSExtra 1.1.2
jrchamp Nov 30, 2023
a211a3c
standards: PHPCSExtra 1.2.1; PHPCSUtils 1.0.9; PHPCompatibility 2024-…
jrchamp Mar 14, 2024
a32c53b
standards: PHPCSUtils 1.0.10; PHPCompatibility 2024-04-08; PHP_CodeSn…
jrchamp Apr 9, 2024
845ea29
standards: PHPCSUtils 1.0.12; PHPCompatibility 2024-08-11; PHP_CodeSn…
jrchamp Aug 29, 2024
1a4e4d0
wordpress: check all files, not just PHP
jrchamp Oct 11, 2024
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
14 changes: 10 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
url = https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git
[submodule "PHP_CodeSniffer"]
path = PHP_CodeSniffer
url = https://github.com/squizlabs/PHP_CodeSniffer.git
[submodule "moodle-local_codechecker"]
path = moodle-local_codechecker
url = https://github.com/moodlehq/moodle-local_codechecker.git
url = https://github.com/PHPCSStandards/PHP_CodeSniffer.git
[submodule "PHPCSUtils"]
path = PHPCSUtils
url = https://github.com/PHPCSStandards/PHPCSUtils.git
[submodule "moodle-cs"]
path = moodle-cs
url = https://github.com/moodlehq/moodle-cs.git
[submodule "PHPCSExtra"]
path = PHPCSExtra
url = https://github.com/PHPCSStandards/PHPCSExtra.git
1 change: 1 addition & 0 deletions PHPCSExtra
Submodule PHPCSExtra added at 11d387
1 change: 1 addition & 0 deletions PHPCSUtils
Submodule PHPCSUtils added at 87b233
2 changes: 1 addition & 1 deletion PHPCompatibility
Submodule PHPCompatibility updated 643 files
2 changes: 1 addition & 1 deletion PHP_CodeSniffer
Submodule PHP_CodeSniffer updated 1184 files
2 changes: 1 addition & 1 deletion WordPress-Coding-Standards
85 changes: 64 additions & 21 deletions delta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<arg name="parallel" value="8"/>

<!-- Load additional standards. -->
<config name="installed_paths" value="/misc/temp/phpcs/WordPress-Coding-Standards,/misc/temp/phpcs/PHPCompatibility" />
<config name="installed_paths" value="/misc/temp/phpcs/WordPress-Coding-Standards,/misc/temp/phpcs/PHPCompatibility,/misc/temp/phpcs/PHPCSUtils,/misc/temp/phpcs/PHPCSExtra" />

<!-- Exclude the Composer Vendor directory. -->
<exclude-pattern>/vendor/*</exclude-pattern>
Expand All @@ -20,8 +20,31 @@
<!-- Exclude minified Javascript files. -->
<exclude-pattern>*.min.js</exclude-pattern>

<!-- Include the WordPress-Extra standard. -->
<rule ref="WordPress-Extra">
<!-- Include the PSR1 standard. -->
<rule ref="PSR1">
<!-- WordPress has its own rules for these. -->
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
<exclude name="PSR1.Classes.ClassDeclaration"/>
<exclude name="PSR1.Methods.CamelCapsMethodName"/>

<!-- Legacy code has lots of side effects. -->
<exclude name="PSR1.Files.SideEffects"/>
</rule>

<!-- Include the PSR12 standard. -->
<rule ref="PSR12">
<!-- WordPress has its own rules for these. -->
<exclude name="Generic.Files.LineLength"/>
<exclude name="PSR12.ControlStructures.ControlStructureSpacing"/>
<exclude name="PSR12.Files.FileHeader"/>
<exclude name="PSR2.Classes.ClassDeclaration"/>
<exclude name="PSR2.Methods.FunctionCallSignature"/>
<exclude name="Squiz.Classes.ValidClassName"/>
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration"/>
</rule>

<!-- Include the WordPress standard. -->
<rule ref="WordPress">
<!--
We can run `phpcs` with the '-s' flag, which allows us to see the names
of the sniffs reporting errors. Once we know the sniff names, we can opt
Expand All @@ -36,6 +59,7 @@

<!-- File-level comments are not required. -->
<exclude name="Squiz.Commenting.FileComment.Missing"/>
<exclude name="Squiz.Commenting.FileComment.MissingPackageTag"/>

<!-- Comment alignment spacing. -->
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamType"/>
Expand All @@ -44,47 +68,46 @@
<!-- Add back? Double quotes only when necessary. -->
<exclude name="Squiz.Strings.DoubleQuoteUsage"/>

<!-- Allow increment/decrement after variable. -->
<exclude name="Universal.Operators.DisallowStandalonePostIncrementDecrement"/>

<!-- Add back? Hyphenated filenames. -->
<exclude name="WordPress.Files.FileName"/>

<!-- Add back? No assignments in while conditions. -->
<exclude name="WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition"/>

<!-- Add back? date() vs gmdate(). -->
<exclude name="WordPress.DateTime.RestrictedFunctions"/>
<exclude name="WordPress.DateTime"/>

<!-- No WordPress spaces. -->
<exclude name="Generic.WhiteSpace.ArbitraryParenthesesSpacing"/>
<exclude name="WordPress.Arrays.ArrayDeclarationSpacing"/>
<exclude name="WordPress.Arrays.ArrayKeySpacingRestrictions"/>
<exclude name="Generic.WhiteSpace.ArbitraryParenthesesSpacing"/>
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing"/>
<exclude name="WordPress.WhiteSpace.OperatorSpacing"/>
<exclude name="WordPress.WhiteSpace"/>

<!-- Yoda is illogical and handled by WordPress.CodeAnalysis.AssignmentInCondition. -->
<exclude name="WordPress.PHP.YodaConditions"/>

<!-- WP Specific: Requires use of $wpdb. -->
<exclude name="WordPress.DB.RestrictedClasses"/>
<exclude name="WordPress.DB.RestrictedFunctions"/>
<exclude name="WordPress.DB"/>

<!-- WP Specific: Requires use of WP functions. -->
<exclude name="WordPress.Security.EscapeOutput"/>
<exclude name="WordPress.Security.NonceVerification"/>
<exclude name="WordPress.WP.AlternativeFunctions"/>
<exclude name="WordPress.WP.DeprecatedFunctions"/>
<exclude name="WordPress.WP.EnqueuedResources"/>
<exclude name="WordPress.WP.TimezoneChange"/>
<exclude name="WordPress.WP.GlobalVariablesOverride"/>
</rule>
<exclude name="WordPress.PHP.IniSet"/>
<exclude name="WordPress.Security"/>

<!-- Let's also check that everything is properly documented. -->
<rule ref="WordPress-Docs"/>
<!-- WP Specific: General WordPress -->
<exclude name="WordPress.WP"/>
</rule>

<!-- Check for PHP cross-version compatibility. -->
<config name="testVersion" value="7.1-99.0"/>
<config name="testVersion" value="7.2-99.0"/>
<rule ref="PHPCompatibility">
<!-- Incorrect error. -->
<!-- PHP 4.3 - Incorrect error. -->
<exclude name="PHPCompatibility.PHP.NewFunctionParameters.php_uname_modeFound"/>

<!-- PHP 8.1 - We don't care that the default flags for htmlspecialchars() has changed. Both defaults are acceptable. -->
<exclude name="PHPCompatibility.ParameterValues.NewHTMLEntitiesFlagsDefault.NotSet"/>
</rule>

<!-- No spaces around function call signature. No WordPress spaces. -->
Expand All @@ -105,9 +128,13 @@
<rule ref="Generic.CodeAnalysis">
<!-- Add back? No assignments in while conditions. -->
<exclude name="Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition"/>

<!-- Handled in a better way by Squiz.Commenting.EmptyCatchComment.Missing -->
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCatch"/>
</rule>
<rule ref="Generic.Commenting"/>
<rule ref="Generic.Metrics"/>
<rule ref="Generic.PHP.Syntax"/>
<rule ref="Generic.Strings.UnnecessaryStringConcat">
<properties>
<property name="allowMultiline" value="true" />
Expand Down Expand Up @@ -148,9 +175,25 @@
</properties>
</rule>

<!-- Switch breaks are followed by newline or the switch end. -->
<rule ref="Squiz.ControlStructures.SwitchDeclaration">
<exclude name="Squiz.ControlStructures.SwitchDeclaration.BreakIndent" />
</rule>

<!-- Scope closing brace on own line. -->
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace" />

<!-- Enforce arrays with commas and appropriate spaces. -->
<rule ref="NormalizedArrays.Arrays.ArrayBraceSpacing">
<properties>
<property name="spacesSingleLine" value="0"/>
</properties>
</rule>
<rule ref="NormalizedArrays.Arrays.CommaAfterLast"/>

<!-- Disallow PHP's alternative control structure syntax. -->
<rule ref="Universal.ControlStructures.DisallowAlternativeSyntax"/>

<!-- Forbidden functions. -->
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
Expand Down
1 change: 1 addition & 0 deletions moodle-cs
Submodule moodle-cs added at 89ff0a
1 change: 0 additions & 1 deletion moodle-local_codechecker
Submodule moodle-local_codechecker deleted from 681105
10 changes: 8 additions & 2 deletions moodle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<arg name="parallel" value="8"/>

<!-- Load additional standards. -->
<config name="installed_paths" value="/misc/temp/phpcs/moodle-local_codechecker" />
<config name="installed_paths" value="/misc/temp/phpcs/moodle-cs,/misc/temp/phpcs/PHPCompatibility,/misc/temp/phpcs/PHPCSUtils,/misc/temp/phpcs/PHPCSExtra" />

<!-- Exclude the Composer Vendor directory. -->
<exclude-pattern>/vendor/*</exclude-pattern>
Expand All @@ -21,14 +21,20 @@
<exclude-pattern>*.min.js</exclude-pattern>

<!-- Include the moodle standard. -->
<rule ref="moodle">
<rule ref="moodle-extra">
<!--
We can run `phpcs` with the '-s' flag, which allows us to see the names
of the sniffs reporting errors. Once we know the sniff names, we can opt
to exclude sniffs which don't suit our project.
-->
</rule>

<!-- Check PHP syntax. -->
<rule ref="Generic.PHP.Syntax"/>

<!-- We require PHP >= 7.1 which allows constant visibility -->
<rule ref="PSR12.Properties.ConstantVisibility"/>

<!-- Check for PHP cross-version compatibility. -->
<config name="testVersion" value="7.1-99.0"/>
</ruleset>
1 change: 1 addition & 0 deletions phpcompatibility.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/misc/temp/phpcs/PHP_CodeSniffer/bin/phpcs -p --colors --standard=/misc/temp/phpcs/phpcompatibility.xml --basepath=. .
13 changes: 10 additions & 3 deletions phpcompatibility.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- Check up to 8 files simultanously. -->
<arg name="parallel" value="8"/>

<config name="installed_paths" value="/misc/temp/phpcs/PHPCompatibility" />
<config name="installed_paths" value="/misc/temp/phpcs/PHPCompatibility,/misc/temp/phpcs/PHPCSUtils,/misc/temp/phpcs/PHPCSExtra" />

<!-- Exclude the Composer Vendor directory. -->
<exclude-pattern>/vendor/*</exclude-pattern>
Expand All @@ -19,9 +19,16 @@
<!-- Exclude minified Javascript files. -->
<exclude-pattern>*.min.js</exclude-pattern>

<!-- Check PHP syntax. -->
<rule ref="Generic.PHP.Syntax"/>

<!-- Check for PHP cross-version compatibility. -->
<config name="testVersion" value="7.1-99.0"/>
<config name="testVersion" value="7.0-99.0"/>
<rule ref="PHPCompatibility">
<exclude name="PHPCompatibility.PHP.NewFunctionParameters.php_uname_modeFound"/> <!-- Incorrect error -->
<!-- PHP 4.3 - Incorrect error. -->
<exclude name="PHPCompatibility.PHP.NewFunctionParameters.php_uname_modeFound"/>

<!-- PHP 8.1 - We don't care that the default flags for htmlspecialchars() has changed. Both defaults are acceptable. -->
<exclude name="PHPCompatibility.ParameterValues.NewHTMLEntitiesFlagsDefault.NotSet"/>
</rule>
</ruleset>
6 changes: 1 addition & 5 deletions run_phpcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
if (is_readable($path)) {
echo $filename . PHP_EOL;
passthru("phpcs -p --colors --standard=$phpcs_dir/phpcompatibility.xml --report=json --report-file=$phpcs_dir/output/$filename.json --basepath=$path $path");
}
else {
} else {
echo 'ERROR: Folder not readable - ' . $path . PHP_EOL;
}
}
else {
//echo 'ERROR: Folder does not exist - ' . $path . PHP_EOL;
}
}
22 changes: 8 additions & 14 deletions wp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
<ruleset name="DELTA-WordPress-Development">
<description>A custom set of rules based on WordPress project</description>

<!-- Only scan PHP files. -->
<arg name="extensions" value="php"/>

<!-- Check up to 8 files simultanously. -->
<arg name="parallel" value="8"/>

<!-- Load additional standards. -->
<config name="installed_paths" value="/misc/temp/phpcs/WordPress-Coding-Standards,/misc/temp/phpcs/PHPCompatibility" />
<config name="installed_paths" value="/misc/temp/phpcs/WordPress-Coding-Standards,/misc/temp/phpcs/PHPCompatibility,/misc/temp/phpcs/PHPCSUtils,/misc/temp/phpcs/PHPCSExtra" />

<!-- Exclude the Composer Vendor directory. -->
<exclude-pattern>/vendor/*</exclude-pattern>
Expand All @@ -20,29 +17,30 @@
<!-- Exclude minified Javascript files. -->
<exclude-pattern>*.min.js</exclude-pattern>

<!-- Include the WordPress-Extra standard. -->
<rule ref="WordPress-Extra"/>

<!-- Let's also check that everything is properly documented. -->
<rule ref="WordPress-Docs"/>
<!-- Include the WordPress standard. -->
<rule ref="WordPress"/>

<!-- This rule is not part of the standard, but is used by WPCS natively. -->
<rule ref="PSR2.Methods.FunctionClosingBrace"/>

<!-- Check for PHP cross-version compatibility. -->
<config name="testVersion" value="5.6-99.0"/>
<rule ref="PHPCompatibility">
<!-- Incorrect error. -->
<!-- PHP 4.3 - Incorrect error. -->
<exclude name="PHPCompatibility.PHP.NewFunctionParameters.php_uname_modeFound"/>

<!-- Only applies to PHP 5.6.16 and older. -->
<exclude name="PHPCompatibility.PHP.NewConstants.mysqli_client_ssl_dont_verify_server_certFound"/>

<!-- PHP 8.1 - We don't care that the default flags for htmlspecialchars() has changed. Both defaults are acceptable. -->
<exclude name="PHPCompatibility.ParameterValues.NewHTMLEntitiesFlagsDefault.NotSet"/>
</rule>

<!-- Code quality. -->
<rule ref="Generic.CodeAnalysis"/>
<rule ref="Generic.Commenting"/>
<rule ref="Generic.Metrics"/>
<rule ref="Generic.PHP.Syntax"/>
<rule ref="Generic.Strings.UnnecessaryStringConcat">
<properties>
<property name="allowMultiline" value="true" />
Expand All @@ -64,10 +62,6 @@
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamType"/>
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamName"/>
</rule>
<rule ref="Squiz.Commenting.InlineComment">
<!-- Add back? Requires either a period, question mark or exclamation point, but that's too restrictive (e.g. URLs). -->
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
</rule>
<rule ref="Squiz.Commenting.VariableComment"/>

<!-- Override statement alignment to have a single space. -->
Expand Down