Skip to content

Commit a5b1d54

Browse files
authored
Merge pull request #13 from patchlevel/re-copy-doctrine-standard
re-copy doctrine standard
2 parents aa503f2 + 970c485 commit a5b1d54

File tree

3 files changed

+98
-19
lines changed

3 files changed

+98
-19
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
dependencies:
2121
- "locked"
2222
php-version:
23-
- "8.1"
23+
- "8.2"
2424
operating-system:
2525
- "ubuntu-latest"
2626

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"require": {
3030
"php": "^7.4 || ^8.0",
3131
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2 || ^1.0.0",
32-
"slevomat/coding-standard": "^8.1.0",
33-
"squizlabs/php_codesniffer": "^3.7.1"
32+
"slevomat/coding-standard": "^8.12.1",
33+
"squizlabs/php_codesniffer": "^3.7.2"
3434
},
3535
"config": {
3636
"sort-packages": true,

src/PatchlevelCodingStandard/ruleset.xml

Lines changed: 95 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@
4848
<property name="spacing" value="0"/>
4949
</properties>
5050
</rule>
51-
<!-- Force no whitespace after `!` -->
52-
<rule ref="Generic.Formatting.SpaceAfterNot">
53-
<properties>
54-
<property name="spacing" value="0" />
55-
</properties>
56-
</rule>
5751
<!-- Forbid PHP 4 constructors -->
5852
<rule ref="Generic.NamingConventions.ConstructorName"/>
5953
<!-- Forbid any content before opening tag -->
@@ -108,29 +102,60 @@
108102
<rule ref="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed">
109103
<type>error</type>
110104
</rule>
105+
<!-- Disallow multiple attributes inside one #[] -->
106+
<rule ref="SlevomatCodingStandard.Attributes.DisallowAttributesJoining"/>
107+
<!-- Require only one attribute per line -->
108+
<rule ref="SlevomatCodingStandard.Attributes.DisallowMultipleAttributesPerLine"/>
109+
<!-- Attributes should be adjoined to the PHP element they belong to -->
110+
<rule ref="SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing"/>
111+
<!-- Require PHPDoc always before attributes -->
112+
<rule ref="SlevomatCodingStandard.Attributes.RequireAttributeAfterDocComment"/>
111113
<!-- Require that single line arrays have the correct spacing: no space around brackets and one space after comma -->
112114
<rule ref="SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace"/>
113115
<!-- Require comma after last element in multi-line array -->
114116
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
117+
<!-- Require no space before : and 1 space before Enum type -->
118+
<rule ref="SlevomatCodingStandard.Classes.BackedEnumTypeSpacing"/>
115119
<!-- Require presence of constant visibility -->
116120
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility">
117121
<properties>
118122
<property name="fixable" value="true"/>
119123
</properties>
120124
</rule>
125+
<!-- Enforce consistent constant spacing -->
126+
<rule ref="SlevomatCodingStandard.Classes.ConstantSpacing"/>
121127
<!-- Forbid LSB for constants (static::FOO) -->
122128
<rule ref="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants"/>
123129
<!-- Forbid more than one constant declared per statement -->
124130
<rule ref="SlevomatCodingStandard.Classes.DisallowMultiConstantDefinition"/>
131+
<!-- Forbid string expression property fetch ($foo->{'bar'}) -->
132+
<rule ref="SlevomatCodingStandard.Classes.DisallowStringExpressionPropertyFetch"/>
125133
<!-- Forbid empty lines around type declarations -->
126134
<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces">
127135
<properties>
128136
<property name="linesCountAfterOpeningBrace" value="0"/>
129137
<property name="linesCountBeforeClosingBrace" value="0"/>
130138
</properties>
131139
</rule>
140+
<!-- Add one line around parent call in order to improve readability -->
141+
<rule ref="SlevomatCodingStandard.Classes.ParentCallSpacing"/>
142+
<!-- Ensure that there are consistent blank lines between properties. -->
143+
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing">
144+
<properties>
145+
<property name="minLinesCountBeforeWithComment" value="0" />
146+
</properties>
147+
</rule>
132148
<!-- Require usage of ::class instead of __CLASS__, get_class(), get_class($this), get_called_class() and get_parent_class() -->
133149
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
150+
<!-- https://github.com/slevomat/coding-standard#slevomatcodingstandardclassespropertydeclaration- -->
151+
<rule ref="SlevomatCodingStandard.Classes.PropertyDeclaration">
152+
<properties>
153+
<property name="checkPromoted" value="true"/>
154+
<property name="enableMultipleSpacesBetweenModifiersCheck" value="true"/>
155+
</properties>
156+
</rule>
157+
<!-- Require usage of constructor property promotion -->
158+
<rule ref="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion"/>
134159
<!-- Forbid uses of multiple traits separated by comma -->
135160
<rule ref="SlevomatCodingStandard.Classes.TraitUseDeclaration"/>
136161
<!-- Require no spaces before trait use, between trait uses and one space after trait uses -->
@@ -150,6 +175,8 @@
150175
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
151176
<!-- Forbid suffix "Trait" for traits -->
152177
<rule ref="SlevomatCodingStandard.Classes.SuperfluousTraitNaming"/>
178+
<!-- Forbid invalid annotation names in standard PHPDoc tags -->
179+
<rule ref="SlevomatCodingStandard.Commenting.AnnotationName"/>
153180
<!-- Require specific order of phpDoc annotations with empty newline between specific groups -->
154181
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
155182
<properties>
@@ -172,8 +199,16 @@
172199
@ODM\,
173200
@PHPCR\,
174201
"/>
175-
<element value="@param"/>
176-
<element value="@return"/>
202+
<element value="
203+
@param,
204+
@psalm-param,
205+
@phpstan-param,
206+
"/>
207+
<element value="
208+
@return,
209+
@psalm-return,
210+
@phpstan-return,
211+
"/>
177212
<element value="@throws"/>
178213
</property>
179214
</properties>
@@ -211,8 +246,6 @@
211246
</rule>
212247
<!-- Report invalid format of inline phpDocs with @var -->
213248
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
214-
<!-- Require comments with single line written as one-liners -->
215-
<rule ref="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment"/>
216249
<!-- Forbid assignments in conditions -->
217250
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
218251
<!-- Require consistent spacing for block structures -->
@@ -256,6 +289,8 @@
256289
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator"/>
257290
<!-- Require usage of null coalesce operator when possible -->
258291
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
292+
<!-- Require usage of null safe operator when possible -->
293+
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator"/>
259294
<!-- Forbid usage of conditions when a simple return can be used -->
260295
<rule ref="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn"/>
261296
<!-- Forbid usage of boolean-only ternary operator usage (e.g. $foo ? true : false) -->
@@ -264,6 +299,8 @@
264299
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>
265300
<!-- Require using Throwable instead of Exception -->
266301
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
302+
<!-- Require non-capturing catch when the variable with exception is not used. -->
303+
<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch" />
267304
<!-- Ensure Arrow Functions declaration format -->
268305
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration">
269306
<properties>
@@ -272,6 +309,30 @@
272309
<property name="spacesCountAfterArrow" value="1"/>
273310
</properties>
274311
</rule>
312+
<!-- Disallow trailing commas in single line function calls -->
313+
<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInCall">
314+
<properties>
315+
<property name="onlySingleLine" value="true" />
316+
</properties>
317+
</rule>
318+
<!-- Disallow trailing commas in single line closure use -->
319+
<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInClosureUse">
320+
<properties>
321+
<property name="onlySingleLine" value="true" />
322+
</properties>
323+
</rule>
324+
<!-- Disallow trailing commas in single line function declarations -->
325+
<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInDeclaration">
326+
<properties>
327+
<property name="onlySingleLine" value="true" />
328+
</properties>
329+
</rule>
330+
<!-- Require trailing commas in multiline function calls -->
331+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
332+
<!-- Require trailing commas in multiline closure use -->
333+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInClosureUse"/>
334+
<!-- Require trailing commas in multiline function declarations -->
335+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
275336
<!-- Require closures not referencing $this be static -->
276337
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
277338
<!-- Forbid unused variables passed to closures via `use` -->
@@ -358,7 +419,12 @@
358419
<!-- Forbid useless semicolon `;` -->
359420
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
360421
<!-- Require /* @var type $foo */ and similar simple inline annotations to be replaced by assert() -->
361-
<rule ref="SlevomatCodingStandard.PHP.RequireExplicitAssertion"/>
422+
<rule ref="SlevomatCodingStandard.PHP.RequireExplicitAssertion">
423+
<properties>
424+
<property name="enableAdvancedStringTypes" value="true"/>
425+
<property name="enableIntegerRanges" value="true"/>
426+
</properties>
427+
</rule>
362428
<!-- Require use of short versions of scalar types (i.e. int instead of integer) -->
363429
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
364430
<!-- Require the `null` type hint to be in the last position of annotations -->
@@ -396,7 +462,6 @@
396462
</property>
397463
</properties>
398464
</rule>
399-
<rule ref="SlevomatCodingStandard.Classes.PropertyDeclaration"/>
400465
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
401466
<properties>
402467
<property name="traversableTypeHints" type="array">
@@ -407,8 +472,18 @@
407472
</property>
408473
</properties>
409474
</rule>
475+
<!-- Define unions style -->
476+
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat">
477+
<properties>
478+
<property name="withSpaces" value="no" />
479+
<property name="shortNullable" value="no" />
480+
<property name="nullPosition" value="last" />
481+
</properties>
482+
</rule>
410483
<!-- Forbid useless @var for constants -->
411484
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
485+
<!-- Require One Line Doc Comment where there's only 1 annotation present -->
486+
<rule ref="SlevomatCodingStandard.Commenting.RequireOneLineDocComment"/>
412487
<!-- Forbid useless phpDocs for functions -->
413488
<rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment">
414489
<properties>
@@ -426,6 +501,8 @@
426501
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable"/>
427502
<!-- Forbid useless variables -->
428503
<rule ref="SlevomatCodingStandard.Variables.UselessVariable"/>
504+
<!-- Require nowdoc syntax instead of heredoc when possible -->
505+
<rule ref="SlevomatCodingStandard.PHP.RequireNowdoc" />
429506
<!-- Forbid spaces around square brackets -->
430507
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
431508
<!-- Force array declaration structure -->
@@ -448,6 +525,11 @@
448525
<rule ref="Squiz.Classes.ClassFileName"/>
449526
<!-- Force `self::` for self-reference, force lower-case self, forbid spaces around `::` -->
450527
<rule ref="Squiz.Classes.SelfMemberReference"/>
528+
<!-- Force phpDoc alignment -->
529+
<rule ref="Squiz.Commenting.DocCommentAlignment">
530+
<!-- Allow extra spaces after star, i.e. for indented annotations -->
531+
<exclude name="Squiz.Commenting.DocCommentAlignment.SpaceAfterStar"/>
532+
</rule>
451533
<!-- Force rules for function phpDoc -->
452534
<rule ref="Squiz.Commenting.FunctionComment">
453535
<!-- Allow `@throws` without description -->
@@ -511,9 +593,6 @@
511593
</rule>
512594
<!-- Forbid strings in `"` unless necessary -->
513595
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
514-
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
515-
<message>Variable "%s" not allowed in double quoted string; use sprintf() or concatenation instead</message>
516-
</rule>
517596
<!-- Forbid braces around string in `echo` -->
518597
<rule ref="Squiz.Strings.EchoedStrings"/>
519598
<!-- Forbid spaces in type casts -->
@@ -553,4 +632,4 @@
553632
<!-- turned off by PSR-12 -> turning back on -->
554633
<severity>5</severity>
555634
</rule>
556-
</ruleset>
635+
</ruleset>

0 commit comments

Comments
 (0)