Skip to content

Commit d9e9edf

Browse files
committed
Fixed QA errors.
1 parent 1ccb8af commit d9e9edf

File tree

4 files changed

+364
-3
lines changed

4 files changed

+364
-3
lines changed
Lines changed: 347 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,347 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WPGraphQL Logging" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
3+
4+
<!-- ===================================== -->
5+
<!-- Project Info & Files Scope -->
6+
<!-- ===================================== -->
7+
8+
<description>Coding standards for the WPGraphQL Logging plugin</description>
9+
<file>./wpgraphql-logging.php</file>
10+
<file>./activation.php</file>
11+
<file>./deactivation.php</file>
12+
<file>./vendor/autoload.php</file>
13+
<file>./src/</file>
14+
<exclude-pattern>*/languages/*</exclude-pattern>
15+
<exclude-pattern>*/phpunit.xml*</exclude-pattern>
16+
<exclude-pattern>**/tests/**</exclude-pattern>
17+
<exclude-pattern>*/vendor/*</exclude-pattern>
18+
19+
<!-- ===================================== -->
20+
<!-- CLI Arguments & Version Config -->
21+
<!-- ===================================== -->
22+
23+
<arg value="sp"/>
24+
<arg name="basepath" value="./"/>
25+
<arg name="colors"/>
26+
<arg name="extensions" value="php"/>
27+
<arg name="severity" value="1"/>
28+
<arg name="parallel" value="20"/>
29+
<config name="testVersion" value="7.4-"/>
30+
<config name="minimum_wp_version" value="6.0"/>
31+
32+
<!-- ===================================== -->
33+
<!-- Base Standards -->
34+
<!-- ===================================== -->
35+
36+
<rule ref="PSR2">
37+
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
38+
<exclude name="Generic.Files.LineLength.TooLong"/>
39+
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/>
40+
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
41+
<exclude name="PSR2.Methods.FunctionCallSignature.SpaceAfterOpenBracket"/>
42+
<exclude name="PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket"/>
43+
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine"/>
44+
<exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody"/>
45+
<exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace"/>
46+
<exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpaceBeforeCloseBrace"/>
47+
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps"/>
48+
<exclude name="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen"/>
49+
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace"/>
50+
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen"/>
51+
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingBeforeClose"/>
52+
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/>
53+
</rule>
54+
<rule ref="PSR12.Files.DeclareStatement"/>
55+
<rule ref="PEAR.NamingConventions.ValidClassName"/>
56+
<rule ref="PHPCompatibilityWP"/>
57+
<rule ref="WordPress-VIP-Go"/>
58+
59+
<rule ref="WordPress">
60+
<exclude name="Universal.Arrays.DisallowShortArraySyntax"/>
61+
<exclude name="Universal.Operators.DisallowShortTernary.Found"/>
62+
<exclude name="WordPress.Files.FileName"/>
63+
</rule>
64+
65+
<rule ref="WordPress-Docs">
66+
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
67+
<exclude name="Squiz.Commenting.FileComment.Missing"/>
68+
<exclude name="Squiz.Commenting.ClassComment.Missing" />
69+
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag"/>
70+
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment" />
71+
<exclude name="Squiz.Commenting.VariableComment.MissingVar" />
72+
</rule>
73+
74+
<!-- ===================================== -->
75+
<!-- Prefix & Text Domain Enforcements -->
76+
<!-- ===================================== -->
77+
78+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
79+
<properties>
80+
<property name="prefixes" type="array" value="WPGraphQL\Logging, wpgraphql_logging, WPGRAPHQL_LOGGING__"/>
81+
</properties>
82+
</rule>
83+
84+
<rule ref="WordPress.WP.I18n">
85+
<properties>
86+
<property name="text_domain" type="array">
87+
<element value="wpgraphql-logging"/>
88+
</property>
89+
</properties>
90+
</rule>
91+
92+
<!-- ===================================== -->
93+
<!-- Function Call Formatting -->
94+
<!-- ===================================== -->
95+
96+
<rule ref="PEAR.Functions.FunctionCallSignature">
97+
<properties>
98+
<property name="requiredSpacesAfterOpen" value="1"/>
99+
<property name="requiredSpacesBeforeClose" value="1"/>
100+
</properties>
101+
<severity>0</severity>
102+
</rule>
103+
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket"/>
104+
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket"/>
105+
106+
<!-- ===================================== -->
107+
<!-- Generic & Squiz Formatting Rules -->
108+
<!-- ===================================== -->
109+
110+
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie"/>
111+
<rule ref="Generic.Classes.OpeningBraceSameLine"/>
112+
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
113+
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
114+
<rule ref="Generic.Formatting.MultipleStatementAlignment"/>
115+
<rule ref="Generic.Files.ByteOrderMark"/>
116+
<rule ref="Generic.Files.EndFileNewline"/>
117+
<rule ref="Generic.WhiteSpace.ScopeIndent">
118+
<properties>
119+
<property name="indent" value="4"/>
120+
<property name="tabIndent" value="true"/>
121+
</properties>
122+
</rule>
123+
<rule ref="Generic.VersionControl.GitMergeConflict"/>
124+
<rule ref="Generic.Formatting.SpaceAfterCast">
125+
<properties>
126+
<property name="spacing" value="1"/>
127+
</properties>
128+
</rule>
129+
<rule ref="Generic.Formatting.SpaceAfterNot"/>
130+
<rule ref="Generic.NamingConventions.ConstructorName"/>
131+
<rule ref="Generic.PHP.DeprecatedFunctions"/>
132+
<rule ref="Generic.PHP.DisallowShortOpenTag.EchoFound">
133+
<severity>4</severity>
134+
<type>warning</type>
135+
</rule>
136+
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
137+
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
138+
<properties>
139+
<property name="spacing" value="1" />
140+
<property name="spacingBeforeFirst" value="0" />
141+
<property name="spacingAfterLast" value="0" />
142+
</properties>
143+
</rule>
144+
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
145+
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing"/>
146+
147+
<!-- ===================================== -->
148+
<!-- Slevomat: Class Layout & Formatting -->
149+
<!-- ===================================== -->
150+
151+
<rule ref="SlevomatCodingStandard.Classes.ClassStructure"/>
152+
<rule ref="SlevomatCodingStandard.Classes.ClassMemberSpacing"/>
153+
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing"/>
154+
<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces">
155+
<properties>
156+
<property name="linesCountAfterOpeningBrace" value="0"/>
157+
<property name="linesCountBeforeClosingBrace" value="0"/>
158+
</properties>
159+
</rule>
160+
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility">
161+
<properties>
162+
<property name="fixable" value="true"/>
163+
</properties>
164+
</rule>
165+
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
166+
167+
<!-- ===================================== -->
168+
<!-- Slevomat: Namespace Import Rules -->
169+
<!-- ===================================== -->
170+
171+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
172+
<properties>
173+
<property name="caseSensitive" value="true"/>
174+
</properties>
175+
</rule>
176+
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
177+
<properties>
178+
<property name="searchAnnotations" value="true"/>
179+
</properties>
180+
</rule>
181+
<rule ref="SlevomatCodingStandard.Namespaces.UseSpacing">
182+
<properties>
183+
<property name="linesCountBeforeFirstUse" value="1"/>
184+
<property name="linesCountBetweenUseTypes" value="1"/>
185+
<property name="linesCountAfterLastUse" value="1"/>
186+
</properties>
187+
</rule>
188+
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
189+
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
190+
191+
<!-- ===================================== -->
192+
<!-- Slevomat: Type Hints & Typing -->
193+
<!-- ===================================== -->
194+
195+
<!-- Type hinting & strict typing -->
196+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
197+
<properties>
198+
<property name="spacesCountAroundEqualsSign" value="0"/>
199+
<property name="declareOnFirstLine" value="false"/>
200+
<property name="linesCountAfterDeclare" value="1"/>
201+
</properties>
202+
</rule>
203+
204+
<!-- Return type hints -->
205+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
206+
<properties>
207+
<property name="enableObjectTypeHint" value="true"/>
208+
<property name="traversableTypeHints" type="array">
209+
<element value="Traversable"/>
210+
<element value="Iterator"/>
211+
<element value="Generator"/>
212+
</property>
213+
<!-- PHP 7.4 specific settings -->
214+
<property name="enableMixedTypeHint" value="false"/>
215+
<property name="enableUnionTypeHint" value="false"/>
216+
<property name="enableIntersectionTypeHint" value="false"/>
217+
</properties>
218+
</rule>
219+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
220+
<properties>
221+
<property name="spacesCountBeforeColon" value="0"/>
222+
</properties>
223+
</rule>
224+
225+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
226+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation"/>
227+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint" />
228+
</rule>
229+
230+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
231+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.UselessAnnotation"/>
232+
</rule>
233+
<rule ref="SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax"/>
234+
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
235+
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
236+
<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>
237+
238+
<!-- ===================================== -->
239+
<!-- Slevomat: Arrays -->
240+
<!-- ===================================== -->
241+
242+
<rule ref="SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation"/>
243+
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
244+
<rule ref="SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace">
245+
<properties>
246+
<property name="spacesAroundBrackets" value="1"/>
247+
</properties>
248+
</rule>
249+
250+
<!-- ===================================== -->
251+
<!-- Slevomat: Functions -->
252+
<!-- ===================================== -->
253+
254+
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
255+
<rule ref="SlevomatCodingStandard.Functions.UselessParameterDefaultValue"/>
256+
<rule ref="SlevomatCodingStandard.Functions.RequireSingleLineCall"/>
257+
258+
<!-- ===================================== -->
259+
<!-- Slevomat: Commenting -->
260+
<!-- ===================================== -->
261+
262+
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
263+
<properties>
264+
<property name="linesCountBetweenDifferentAnnotationsTypes" value="1"/>
265+
<property name="linesCountAfterLastContent" value="0"/>
266+
</properties>
267+
</rule>
268+
269+
<!-- ===================================== -->
270+
<!-- Slevomat: Control Structures -->
271+
<!-- ===================================== -->
272+
273+
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit">
274+
<properties>
275+
<property name="ignoreStandaloneIfInScope" value="true"/>
276+
<property name="ignoreOneLineTrailingIf" value="true"/>
277+
</properties>
278+
</rule>
279+
<rule ref="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn"/>
280+
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
281+
<rule ref="SlevomatCodingStandard.ControlStructures.UselessTernaryOperator"/>
282+
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
283+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch"/>
284+
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses"/>
285+
286+
<!-- ===================================== -->
287+
<!-- Slevomat: Exceptions -->
288+
<!-- ===================================== -->
289+
290+
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>
291+
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
292+
<rule ref="SlevomatCodingStandard.Exceptions.DisallowNonCapturingCatch"/>
293+
294+
<!-- ===================================== -->
295+
<!-- Slevomat: Variables -->
296+
<!-- ===================================== -->
297+
298+
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable"/>
299+
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable">
300+
<properties>
301+
<property name="ignoreUnusedValuesWhenOnlyKeysAreUsedInForeach" value="true"/>
302+
</properties>
303+
</rule>
304+
<rule ref="SlevomatCodingStandard.Variables.UselessVariable"/>
305+
306+
<!-- ===================================== -->
307+
<!-- Slevomat: Misc / Operators -->
308+
<!-- ===================================== -->
309+
310+
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
311+
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
312+
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
313+
314+
<rule ref="Squiz.Commenting.FunctionComment">
315+
<properties>
316+
<property name="skipIfInheritdoc" value="true" />
317+
</properties>
318+
</rule>
319+
320+
<!-- ===================================== -->
321+
<!-- Complexity Metrics -->
322+
<!-- ===================================== -->
323+
324+
<rule ref="Generic.Metrics.CyclomaticComplexity">
325+
<properties>
326+
<property name="complexity" value="7"/>
327+
<property name="absoluteComplexity" value="10"/>
328+
</properties>
329+
</rule>
330+
331+
<rule ref="SlevomatCodingStandard.Complexity.Cognitive">
332+
<properties>
333+
<property name="warningThreshold" value="7"/>
334+
<property name="errorThreshold" value="10"/>
335+
</properties>
336+
</rule>
337+
338+
<rule ref="Generic.Metrics.NestingLevel">
339+
<properties>
340+
<property name="nestingLevel" value="2"/>
341+
<property name="absoluteNestingLevel" value="true"/>
342+
</properties>
343+
</rule>
344+
345+
<rule ref="./phpcs/HWPStandard"/>
346+
347+
</ruleset>

plugins/wpgraphql-logging/psalm.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
>
1111
<projectFiles>
1212
<file name="wpgraphql-logging.php"/>
13+
<file name="activation.php"/>
14+
<file name="deactivation.php"/>
1315
<file name="vendor/autoload.php"/>
1416
<directory name="src"/>
1517
</projectFiles>
@@ -25,5 +27,11 @@
2527
<directory name="src"/>
2628
</errorLevel>
2729
</UndefinedConstant>
30+
31+
<MissingFile errorLevel="suppress">
32+
<errorLevel type="suppress">
33+
<file name="src/Logger/Database/DatabaseEntity.php"/>
34+
</errorLevel>
35+
</MissingFile>
2836
</issueHandlers>
2937
</psalm>

plugins/wpgraphql-logging/src/Hooks/PluginHooks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static function deactivate_plugin(): void {
4444
* Register actions and filters.
4545
*/
4646
protected function register(): void {
47-
add_action( 'wpgraphql_logging_activate', [ self::class, 'activate_plugin' ] );
48-
add_action( 'wpgraphql_logging_deactivate', [ self::class, 'deactivate_plugin' ] );
47+
add_action( 'wpgraphql_logging_activate', [ self::class, 'activate_plugin' ], 10, 0 );
48+
add_action( 'wpgraphql_logging_deactivate', [ self::class, 'deactivate_plugin' ], 10, 0 );
4949
}
5050
}

plugins/wpgraphql-logging/src/Logger/Database/DatabaseEntity.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ public static function get_schema(): string {
4545

4646
/**
4747
* Creates the logging table in the database.
48+
*
49+
* @throws \RuntimeException If ABSPATH is not defined.
4850
*/
4951
public static function create_table(): void {
50-
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
52+
if ( ! defined( 'ABSPATH' ) ) {
53+
throw new \RuntimeException( 'ABSPATH is not defined.' );
54+
}
55+
56+
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; // @phpstan-ignore-line
5157
$schema = self::get_schema();
5258
dbDelta( $schema );
5359
}

0 commit comments

Comments
 (0)