Skip to content

Commit 6c72487

Browse files
authored
Merge pull request #866 from Automattic/fix/phpcs-violations
2 parents 42cb2fa + 8a14936 commit 6c72487

37 files changed

+3188
-2218
lines changed

.github/workflows/php-lint.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,4 @@ jobs:
4242
run: composer lint-ci | cs2pr
4343

4444
- name: PHP coding standards
45-
# continue-on-error until existing violations are addressed
46-
continue-on-error: true
4745
run: composer cs -- --report=checkstyle | cs2pr

.phpcs.xml.dist

Lines changed: 192 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="wp-parsely" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="edit-flow" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
33
<description>Custom ruleset for Edit Flow plugin.</description>
44

55
<!-- For help in understanding this file: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
@@ -11,7 +11,9 @@
1111
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders -->
1212
<exclude-pattern>/node_modules/</exclude-pattern>
1313
<exclude-pattern>/vendor/</exclude-pattern>
14-
<exclude-pattern>/tests/</exclude-pattern>
14+
<exclude-pattern>/build/</exclude-pattern>
15+
<!-- Third-party library for screen options, do not modify -->
16+
<exclude-pattern>common/php/screen-options\.php</exclude-pattern>
1517

1618
<!-- How to scan -->
1719
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
@@ -66,32 +68,42 @@
6668
<!-- We use trigger_error extensively -->
6769
<exclude name="WordPress.PHP.DevelopmentFunctions.error_log_trigger_error" />
6870

69-
<!-- ToDo: Remove these exceptions over time -->
70-
<!-- These are for legacy reasons, as EditFlow's main file cannot be altered -->
71-
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
72-
<exclude name="Universal.Files.SeparateFunctionsFromOO.Mixed" />
73-
<exclude name="PEAR.NamingConventions.ValidClassName.StartWithCapital" />
74-
<exclude name="PEAR.NamingConventions.ValidClassName.Invalid" />
75-
<!-- Allow not returning after the setup theme filter for now -->
76-
<exclude name="WordPressVIPMinimum.Hooks.AlwaysReturnInFilter.MissingReturnStatement" />
77-
<!-- Localization is done in a legacy manner in some places, and its been left as is for now -->
78-
<exclude name="WordPress.WP.I18n.InterpolatedVariableSingular" />
79-
<exclude name="WordPress.WP.I18n.InterpolatedVariablePlural" />
80-
<exclude name="WordPress.WP.I18n.MissingSingularPlaceholder" />
81-
<exclude name="WordPress.WP.I18n.NonSingularStringLiteralText" />
82-
<!-- This rule is hard to solve given the heavy use of JS in the PHP code right now -->
83-
<exclude name="Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure" />
84-
<exclude name="WordPress.DateTime.RestrictedFunctions.date_date" />
71+
<!-- Standard WP_CLI_Command is fine for non-VIP-specific plugins -->
72+
<exclude name="WordPressVIPMinimum.Classes.RestrictedExtendClasses.wp_cli" />
73+
8574
</rule>
8675

8776
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
8877
<properties>
78+
<!-- Minimum prefix length is 4 characters - "ef_" is too short -->
79+
<!-- This matches: edit_flow_function(), EditFlow, Edit_Flow_Class -->
8980
<property name="prefixes" type="array">
90-
<element value="ef"/>
91-
<element value="Edit_Flow"/>
81+
<element value="edit_flow"/>
82+
<element value="EditFlow"/>
83+
<element value="EDIT_FLOW"/>
9284
</property>
9385
</properties>
9486
</rule>
87+
<!-- Legacy "EF_" prefix for classes is established and cannot be changed -->
88+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound">
89+
<severity>0</severity>
90+
</rule>
91+
<!-- Legacy "ef_" prefix for hooks is established and cannot be changed -->
92+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound">
93+
<severity>0</severity>
94+
</rule>
95+
<!-- Legacy "ef_" prefix for functions is established and cannot be changed -->
96+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound">
97+
<severity>0</severity>
98+
</rule>
99+
<!-- Legacy "_ef_" prefix for internal variables is established and cannot be changed -->
100+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound">
101+
<severity>0</severity>
102+
</rule>
103+
<!-- Legacy "EF_" prefix for constants is established and cannot be changed -->
104+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound">
105+
<severity>0</severity>
106+
</rule>
95107

96108
<rule ref="WordPress.WP.I18n">
97109
<properties>
@@ -107,4 +119,164 @@
107119
</properties>
108120
</rule>
109121

122+
<!-- Test-specific exclusions -->
123+
<!-- Tests use Automattic\EditFlow\Tests namespace, not plugin prefix -->
124+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound">
125+
<exclude-pattern>/tests/</exclude-pattern>
126+
</rule>
127+
<!-- Tests can use camelCase for PHPUnit compatibility and test fixtures -->
128+
<rule ref="WordPress.NamingConventions.ValidVariableName">
129+
<exclude-pattern>/tests/</exclude-pattern>
130+
</rule>
131+
<!-- Test class/method documentation is not required -->
132+
<rule ref="Squiz.Commenting.ClassComment.Missing">
133+
<exclude-pattern>/tests/</exclude-pattern>
134+
</rule>
135+
<rule ref="Squiz.Commenting.FunctionComment.Missing">
136+
<exclude-pattern>/tests/</exclude-pattern>
137+
</rule>
138+
<rule ref="Squiz.Commenting.VariableComment">
139+
<exclude-pattern>/tests/</exclude-pattern>
140+
</rule>
141+
<rule ref="Generic.Commenting.DocComment.MissingShort">
142+
<exclude-pattern>/tests/</exclude-pattern>
143+
</rule>
144+
<!-- Tests may need to override global variables for setup -->
145+
<rule ref="WordPress.WP.GlobalVariablesOverride.Prohibited">
146+
<exclude-pattern>/tests/</exclude-pattern>
147+
</rule>
148+
<!-- Tests can use runtime configuration functions -->
149+
<rule ref="WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting">
150+
<exclude-pattern>/tests/</exclude-pattern>
151+
</rule>
152+
<rule ref="WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_ini_set">
153+
<exclude-pattern>/tests/</exclude-pattern>
154+
</rule>
155+
<!-- Tests don't need security escaping -->
156+
<rule ref="WordPress.Security.EscapeOutput">
157+
<exclude-pattern>/tests/</exclude-pattern>
158+
</rule>
159+
<!-- Tests may use underscore-prefixed properties/methods (PHPUnit convention) -->
160+
<rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
161+
<exclude-pattern>/tests/</exclude-pattern>
162+
</rule>
163+
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
164+
<exclude-pattern>/tests/</exclude-pattern>
165+
</rule>
166+
<!-- Tests may have unused function parameters (required by PHPUnit signatures) -->
167+
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter">
168+
<exclude-pattern>/tests/</exclude-pattern>
169+
</rule>
170+
<!-- Tests can use flush_rewrite_rules for setup -->
171+
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.flush_rewrite_rules_flush_rewrite_rules">
172+
<exclude-pattern>/tests/</exclude-pattern>
173+
</rule>
174+
<!-- Tests may use wp_mail for testing email functionality -->
175+
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.wp_mail_wp_mail">
176+
<exclude-pattern>/tests/</exclude-pattern>
177+
</rule>
178+
<!-- Tests may use constant() dynamically -->
179+
<rule ref="WordPressVIPMinimum.Constants.ConstantString.NotCheckingConstantName">
180+
<exclude-pattern>/tests/</exclude-pattern>
181+
</rule>
182+
<!-- Tests don't require i18n text domain -->
183+
<rule ref="WordPress.WP.I18n.MissingArgDomain">
184+
<exclude-pattern>/tests/</exclude-pattern>
185+
</rule>
186+
<!-- Inline comment formatting is relaxed in tests -->
187+
<rule ref="Squiz.Commenting.InlineComment.InvalidEndChar">
188+
<exclude-pattern>/tests/</exclude-pattern>
189+
</rule>
190+
<!-- Tests may need visibility on methods but not strict enforcement -->
191+
<rule ref="Squiz.Scope.MethodScope.Missing">
192+
<exclude-pattern>/tests/</exclude-pattern>
193+
</rule>
194+
<!-- Tests can use file_get_contents for fixtures -->
195+
<rule ref="WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents">
196+
<exclude-pattern>/tests/</exclude-pattern>
197+
</rule>
198+
<!-- Tests can output directly -->
199+
<rule ref="WordPress.Security.EscapeOutput.OutputNotEscaped">
200+
<exclude-pattern>/tests/</exclude-pattern>
201+
</rule>
202+
<!-- Tests may use switch_to_blog for multisite testing -->
203+
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.switch_to_blog_switch_to_blog">
204+
<exclude-pattern>/tests/</exclude-pattern>
205+
</rule>
206+
<!-- Tests don't need nonce verification -->
207+
<rule ref="WordPress.Security.NonceVerification">
208+
<exclude-pattern>/tests/</exclude-pattern>
209+
</rule>
210+
<!-- Tests don't need input validation/sanitisation -->
211+
<rule ref="WordPress.Security.ValidatedSanitizedInput">
212+
<exclude-pattern>/tests/</exclude-pattern>
213+
</rule>
214+
<!-- Tests can use ini_set for configuration -->
215+
<rule ref="WordPress.PHP.IniSet">
216+
<exclude-pattern>/tests/</exclude-pattern>
217+
</rule>
218+
<!-- Tests can use direct database queries -->
219+
<rule ref="WordPress.DB.DirectDatabaseQuery">
220+
<exclude-pattern>/tests/</exclude-pattern>
221+
</rule>
222+
<!-- Tests can use custom capabilities -->
223+
<rule ref="WordPress.WP.Capabilities.Unknown">
224+
<exclude-pattern>/tests/</exclude-pattern>
225+
</rule>
226+
<!-- Tests can use file_get_contents for remote data in testing -->
227+
<rule ref="WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsRemoteFile">
228+
<exclude-pattern>/tests/</exclude-pattern>
229+
</rule>
230+
<!-- Tests don't require param comments -->
231+
<rule ref="Squiz.Commenting.FunctionComment.MissingParamComment">
232+
<exclude-pattern>/tests/</exclude-pattern>
233+
</rule>
234+
<!-- Tests don't require @throws tag -->
235+
<rule ref="Squiz.Commenting.FunctionCommentThrowTag.Missing">
236+
<exclude-pattern>/tests/</exclude-pattern>
237+
</rule>
238+
<!-- Tests can use putenv for configuration -->
239+
<rule ref="WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv">
240+
<exclude-pattern>/tests/</exclude-pattern>
241+
</rule>
242+
<!-- Allow commented out code in tests (often used for reference/debugging) -->
243+
<rule ref="Squiz.PHP.CommentedOutCode.Found">
244+
<exclude-pattern>/tests/</exclude-pattern>
245+
</rule>
246+
<!-- Test files use PascalCase naming (PHPUnit convention) -->
247+
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
248+
<exclude-pattern>/tests/</exclude-pattern>
249+
</rule>
250+
<!-- Legacy main file uses underscore (WordPress.org plugin slug requirement) -->
251+
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
252+
<exclude-pattern>edit_flow\.php</exclude-pattern>
253+
</rule>
254+
<!-- Third-party screen options library uses class + helper function pattern -->
255+
<rule ref="Universal.Files.SeparateFunctionsFromOO.Mixed">
256+
<exclude-pattern>common/php/screen-options\.php</exclude-pattern>
257+
</rule>
258+
<!-- Main plugin file uses class + global convenience function pattern -->
259+
<rule ref="Universal.Files.SeparateFunctionsFromOO.Mixed">
260+
<exclude-pattern>edit_flow\.php</exclude-pattern>
261+
</rule>
262+
<!-- Third-party screen options library uses non-standard class naming -->
263+
<rule ref="PEAR.NamingConventions.ValidClassName">
264+
<exclude-pattern>common/php/screen-options\.php</exclude-pattern>
265+
</rule>
266+
<!-- Legacy edit_flow class name (backwards compatibility requirement) -->
267+
<rule ref="PEAR.NamingConventions.ValidClassName">
268+
<exclude-pattern>edit_flow\.php</exclude-pattern>
269+
</rule>
270+
<!-- Editorial modules intentionally use date() with local timezone for scheduling/metadata display -->
271+
<rule ref="WordPress.DateTime.RestrictedFunctions.date_date">
272+
<exclude-pattern>modules/calendar/calendar\.php</exclude-pattern>
273+
<exclude-pattern>modules/editorial-metadata/editorial-metadata\.php</exclude-pattern>
274+
<exclude-pattern>modules/notifications/notifications\.php</exclude-pattern>
275+
<exclude-pattern>modules/story-budget/story-budget\.php</exclude-pattern>
276+
</rule>
277+
<!-- Tests can use date() for test data setup -->
278+
<rule ref="WordPress.DateTime.RestrictedFunctions.date_date">
279+
<exclude-pattern>/tests/</exclude-pattern>
280+
</rule>
281+
110282
</ruleset>

0 commit comments

Comments
 (0)