Skip to content

Commit 84e1d05

Browse files
committed
Add phpcs rules
1 parent ac68830 commit 84e1d05

File tree

3 files changed

+130
-1
lines changed

3 files changed

+130
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ build
55
*giza.log
66
source/*
77
backups/*
8+
vendor/
9+
composer.lock
10+
.phpcs-cache

phpcs.xml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<arg name="basepath" value="." />
4+
<arg name="extensions" value="php" />
5+
<arg name="parallel" value="80" />
6+
<arg name="cache" value=".phpcs-cache" />
7+
<arg name="colors" />
8+
9+
<!-- Ignore warnings (n), show progress of the run (p), and show sniff names (s) -->
10+
<arg value="nps"/>
11+
12+
<file>source/examples</file>
13+
14+
<!-- Target minimum supported PHP version -->
15+
<config name="php_version" value="80100"/>
16+
17+
<!-- ****************************************** -->
18+
<!-- Import rules from doctrine/coding-standard -->
19+
<!-- ****************************************** -->
20+
<rule ref="Doctrine">
21+
<!-- No namespace for examples -->
22+
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
23+
24+
<!-- Can cause subtle BC breaks -->
25+
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />
26+
27+
28+
<!-- **************************************** -->
29+
<!-- Exclude sniffs that force unwanted style -->
30+
<!-- **************************************** -->
31+
<exclude name="Generic.Formatting.MultipleStatementAlignment" />
32+
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNoFullStop" />
33+
<exclude name="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat.DisallowedShortNullable" />
34+
35+
<!-- ********************* -->
36+
<!-- Exclude broken sniffs -->
37+
<!-- ********************* -->
38+
39+
<!-- Sniff currently broken when casting arrays, see https://github.com/squizlabs/PHP_CodeSniffer/issues/2937#issuecomment-615498860 -->
40+
<exclude name="Squiz.Arrays.ArrayDeclaration.ValueNoNewline" />
41+
42+
<!-- Disable forbidden annotation sniff as excluding @api from the list doesn't work -->
43+
<exclude name="SlevomatCodingStandard.Commenting.ForbiddenAnnotations.AnnotationForbidden" />
44+
45+
<!-- Example file using HTML templating -->
46+
<exclude name="Generic.Files.InlineHTML.Found"/>
47+
<exclude name="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing.IncorrectLinesCountAfterControlStructure"/>
48+
</rule>
49+
50+
51+
<!-- **************************************** -->
52+
<!-- Enable rules not enforced by Doctrine CS -->
53+
<!-- **************************************** -->
54+
55+
<!-- Forbid fully qualified names even for colliding names -->
56+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
57+
<properties>
58+
<property name="allowFallbackGlobalConstants" value="false"/>
59+
<property name="allowFallbackGlobalFunctions" value="false"/>
60+
<property name="allowFullyQualifiedGlobalClasses" value="false"/>
61+
<property name="allowFullyQualifiedGlobalConstants" value="false"/>
62+
<property name="allowFullyQualifiedGlobalFunctions" value="false"/>
63+
<property phpcs-only="true" name="allowFullyQualifiedNameForCollidingClasses" value="false"/>
64+
<property phpcs-only="true" name="allowFullyQualifiedNameForCollidingConstants" value="false"/>
65+
<property phpcs-only="true" name="allowFullyQualifiedNameForCollidingFunctions" value="false"/>
66+
<property name="searchAnnotations" value="true"/>
67+
</properties>
68+
</rule>
69+
70+
71+
<!-- ****************************************************** -->
72+
<!-- Don't require annotations to specify traversable types -->
73+
<!-- ****************************************************** -->
74+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
75+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification" />
76+
</rule>
77+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
78+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification" />
79+
</rule>
80+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
81+
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />
82+
</rule>
83+
84+
85+
<!-- ************************************************************************** -->
86+
<!-- Require type hints for all parameters, properties, and return types in src -->
87+
<!-- ************************************************************************** -->
88+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint">
89+
<exclude-pattern>tests</exclude-pattern>
90+
</rule>
91+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingAnyTypeHint">
92+
<exclude-pattern>tests</exclude-pattern>
93+
</rule>
94+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint">
95+
<exclude-pattern>tests</exclude-pattern>
96+
</rule>
97+
98+
99+
<!-- *********************************************************** -->
100+
<!-- Require native type hints for all code without a BC promise -->
101+
<!-- *********************************************************** -->
102+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
103+
<exclude-pattern>src</exclude-pattern>
104+
</rule>
105+
106+
107+
<!-- ************************************************************* -->
108+
<!-- Ignore errors for certain files where this is part of the API -->
109+
<!-- ************************************************************* -->
110+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
111+
<exclude-pattern>/src/GridFS/StreamWrapper</exclude-pattern>
112+
<exclude-pattern>/tests/DocumentationExamplesTest.php</exclude-pattern>
113+
<exclude-pattern>/tests/GridFS/UnusableStream.php</exclude-pattern>
114+
<exclude-pattern>/tests/SpecTests/ClientSideEncryption/Prose*</exclude-pattern>
115+
</rule>
116+
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
117+
<exclude-pattern>/examples</exclude-pattern>
118+
<exclude-pattern>/tests/PHPUnit/ConstraintTrait.php</exclude-pattern>
119+
</rule>
120+
<rule ref="Squiz.Classes.ClassFileName.NoMatch">
121+
<exclude-pattern>/examples</exclude-pattern>
122+
</rule>
123+
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
124+
<exclude-pattern>/tests/SpecTests/ClientSideEncryption/Prose*</exclude-pattern>
125+
</rule>
126+
</ruleset>

source/examples/codecs/handling-embedded-documents/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ final class Person
88

99
public function __construct(
1010
public string $name,
11-
public readonly ObjectId $id = new ObjectId()
11+
public readonly ObjectId $id = new ObjectId(),
1212
) {
1313
}
1414
}

0 commit comments

Comments
 (0)