Skip to content

Commit 9e594c6

Browse files
committed
Set up PHP_CodeSniffer
1 parent d54eb87 commit 9e594c6

24 files changed

+311
-114
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ tests/ export-ignore
66
.editorconfig export-ignore
77
.gitattributes export-ignore
88
.gitignore export-ignore
9-
.styleci.yml export-ignore
9+
phpcs.xml.dist export-ignore
1010
phpunit.xml.dist export-ignore

.github/workflows/phpcs.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: PHPCS
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
phpcs:
9+
runs-on: ubuntu-latest
10+
name: PHP_CodeSniffer
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
- name: Setup PHP
15+
uses: shivammathur/setup-php@v2
16+
with:
17+
php-version: 8.3
18+
tools: cs2pr
19+
- name: Install Composer dependencies
20+
run: composer install --no-interaction --no-progress --no-scripts
21+
- name: Run PHP_CodeSniffer
22+
run: ./vendor/bin/phpcs --report=checkstyle -q | cs2pr --graceful-warnings

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.idea/
2-
public/coverage
2+
.phpunit.cache/
33
vendor/
4-
.phpunit.result.cache
5-
.phpunit.cache
64
composer.lock
5+
phpcs.xml
76
phpunit.xml

.styleci.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ PostalCodes::override([
156156

157157
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
158158

159-
## Contributing
160-
161-
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
162-
163159
## Credits
164160

165161
- [Choraimy Kroonstuiver](https://github.com/axlon)

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"guzzlehttp/guzzle": "^7.8",
2626
"orchestra/testbench": "^8.34 || ^9.12 || ^10.1",
2727
"phpunit/phpunit": "^10.5 || ^11.5",
28+
"slevomat/coding-standard": "^8.16",
2829
"symfony/var-exporter": "^6.4 || ^7.0"
2930
},
3031
"autoload": {
@@ -38,6 +39,9 @@
3839
}
3940
},
4041
"config": {
42+
"allow-plugins": {
43+
"dealerdirect/phpcodesniffer-composer-installer": true
44+
},
4145
"sort-packages": true
4246
},
4347
"extra": {

phpcs.xml.dist

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
name="Coding Standard"
4+
xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">
5+
6+
<arg value="sp"/>
7+
<config name="tab_width" value="4"/>
8+
9+
<rule ref="PSR12"/>
10+
<rule ref="PSR12.Namespaces.CompoundNamespaceDepth">
11+
<properties>
12+
<property name="maxDepth" value="0"/>
13+
</properties>
14+
</rule>
15+
<rule ref="PSR12.ControlStructures.BooleanOperatorPlacement">
16+
<properties>
17+
<property name="allowOnly" value="first"/>
18+
</properties>
19+
</rule>
20+
<rule ref="Generic.Arrays.ArrayIndent"/>
21+
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
22+
<rule ref="Generic.Files.LineLength">
23+
<properties>
24+
<property name="ignoreComments" value="true"/>
25+
</properties>
26+
</rule>
27+
<rule ref="Generic.Formatting.SpaceAfterCast"/>
28+
<rule ref="Generic.Formatting.SpaceAfterNot">
29+
<properties>
30+
<property name="spacing" value="0"/>
31+
</properties>
32+
</rule>
33+
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
34+
<rule ref="SlevomatCodingStandard.Attributes.DisallowAttributesJoining"/>
35+
<rule ref="SlevomatCodingStandard.Attributes.DisallowMultipleAttributesPerLine"/>
36+
<rule ref="SlevomatCodingStandard.Classes.BackedEnumTypeSpacing"/>
37+
<rule ref="SlevomatCodingStandard.Classes.ClassMemberSpacing">
38+
<properties>
39+
<property name="linesCountBetweenMembers" value="1"/>
40+
</properties>
41+
</rule>
42+
<rule ref="SlevomatCodingStandard.Classes.ClassStructure">
43+
<properties>
44+
<property name="groups" type="array">
45+
<element value="uses"/>
46+
<element value="constants"/>
47+
<element value="enum cases"/>
48+
<element value="properties"/>
49+
<element value="constructor"/>
50+
<element value="methods"/>
51+
</property>
52+
</properties>
53+
</rule>
54+
<rule ref="SlevomatCodingStandard.Classes.MethodSpacing">
55+
<properties>
56+
<property name="minLinesCount" value="1"/>
57+
<property name="maxLinesCount" value="1"/>
58+
</properties>
59+
</rule>
60+
<rule ref="SlevomatCodingStandard.Classes.RequireAbstractOrFinal"/>
61+
<rule ref="SlevomatCodingStandard.Classes.SuperfluousTraitNaming"/>
62+
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
63+
<properties>
64+
<property name="linesCountBeforeFirstContent" value="0"/>
65+
<property name="linesCountBetweenDescriptionAndAnnotations" value="1"/>
66+
<property name="linesCountBetweenDifferentAnnotationsTypes" value="0"/>
67+
<property name="linesCountAfterLastContent" value="0"/>
68+
</properties>
69+
</rule>
70+
<rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment"/>
71+
<rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment"/>
72+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
73+
<rule ref="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing">
74+
<properties>
75+
<property name="linesCountBefore" value="1"/>
76+
<property name="linesCountAfter" value="1"/>
77+
<property name="controlStructures" type="array">
78+
<element value="for"/>
79+
<element value="foreach"/>
80+
<element value="if"/>
81+
<element value="switch"/>
82+
<element value="while"/>
83+
</property>
84+
</properties>
85+
</rule>
86+
<rule ref="SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing">
87+
<properties>
88+
<property name="linesCountBefore" value="1"/>
89+
<property name="jumpStatements" type="array">
90+
<element value="break"/>
91+
<element value="continue"/>
92+
<element value="yield"/>
93+
<element value="yield_from"/>
94+
<element value="return"/>
95+
<element value="throw"/>
96+
</property>
97+
</properties>
98+
</rule>
99+
<rule ref="SlevomatCodingStandard.ControlStructures.UselessTernaryOperator"/>
100+
<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch"/>
101+
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration">
102+
<properties>
103+
<property name="spacesCountAfterKeyword" value="1"/>
104+
<property name="spacesCountBeforeArrow" value="1"/>
105+
<property name="spacesCountAfterArrow" value="1"/>
106+
</properties>
107+
</rule>
108+
<rule ref="SlevomatCodingStandard.Functions.NamedArgumentSpacing"/>
109+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
110+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
111+
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
112+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
113+
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"/>
114+
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
115+
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
116+
<rule ref="SlevomatCodingStandard.Operators.NegationOperatorSpacing">
117+
<properties>
118+
<property name="spacesCount" value="0"/>
119+
</properties>
120+
</rule>
121+
<rule ref="SlevomatCodingStandard.Operators.SpreadOperatorSpacing">
122+
<properties>
123+
<property name="spacesCountAfterOperator" value="0"/>
124+
</properties>
125+
</rule>
126+
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
127+
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
128+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
129+
<properties>
130+
<property name="spacesCountAroundEqualsSign" value="0"/>
131+
</properties>
132+
</rule>
133+
<rule ref="SlevomatCodingStandard.TypeHints.DNFTypeHintFormat">
134+
<properties>
135+
<property name="withSpacesAroundOperators" value="no"/>
136+
<property name="withSpacesInsideParentheses" value="no"/>
137+
<property name="shortNullable" value="yes"/>
138+
<property name="nullPosition" value="last"/>
139+
</properties>
140+
</rule>
141+
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
142+
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
143+
<rule ref="SlevomatCodingStandard.Whitespaces.DuplicateSpaces"/>
144+
<rule ref="Squiz.Commenting.FunctionComment">
145+
<exclude name="Squiz.Commenting.FunctionComment.EmptyThrows"/>
146+
<exclude name="Squiz.Commenting.FunctionComment.Missing"/>
147+
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment"/>
148+
<exclude name="Squiz.Commenting.FunctionComment.IncorrectParamVarName"/>
149+
<exclude name="Squiz.Commenting.FunctionComment.IncorrectTypeHint"/>
150+
<exclude name="Squiz.Commenting.FunctionComment.InvalidReturn"/>
151+
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop"/>
152+
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentNotCapital"/>
153+
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing"/>
154+
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamName"/>
155+
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamType"/>
156+
<exclude name="Squiz.Commenting.FunctionComment.TypeHintMissing"/>
157+
</rule>
158+
<rule ref="Squiz.Commenting.FunctionComment.MissingParamTag">
159+
<exclude-pattern>tests/**/*Test.php</exclude-pattern>
160+
</rule>
161+
<rule ref="Squiz.Commenting.FunctionComment.MissingReturn">
162+
<exclude-pattern>tests/**/*Test.php</exclude-pattern>
163+
</rule>
164+
<rule ref="Squiz.Commenting.InlineComment">
165+
<exclude name="Squiz.Commenting.InlineComment.DocBlock"/>
166+
<exclude name="Squiz.Commenting.InlineComment.Empty"/>
167+
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar"/>
168+
<exclude name="Squiz.Commenting.InlineComment.NotCapital"/>
169+
</rule>
170+
<rule ref="Squiz.NamingConventions.ValidVariableName.NotCamelCaps"/>
171+
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
172+
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
173+
<severity>0</severity>
174+
</rule>
175+
<file>./src</file>
176+
<file>./tests</file>
177+
</ruleset>

src/Extensions/PostalCode.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Axlon\PostalCodeValidation\Extensions;
46

57
use Axlon\PostalCodeValidation\PostalCodeValidator;
68
use Axlon\PostalCodeValidation\Support\PostalCodeExamples;
79
use InvalidArgumentException;
810

9-
class PostalCode
11+
final class PostalCode
1012
{
1113
/**
1214
* The postal code examples.

src/Extensions/PostalCodeFor.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Axlon\PostalCodeValidation\Extensions;
46

57
use Axlon\PostalCodeValidation\PostalCodeValidator;
@@ -8,7 +10,7 @@
810
use Illuminate\Validation\Validator;
911
use InvalidArgumentException;
1012

11-
class PostalCodeFor
13+
final class PostalCodeFor
1214
{
1315
/**
1416
* The postal code examples.
@@ -47,8 +49,13 @@ public function __construct(PostalCodeValidator $validator, PostalCodeExamples $
4749
* @param \Illuminate\Validation\Validator $validator
4850
* @return string
4951
*/
50-
public function replace(string $message, string $attribute, string $rule, array $parameters, Validator $validator): string
51-
{
52+
public function replace(
53+
string $message,
54+
string $attribute,
55+
string $rule,
56+
array $parameters,
57+
Validator $validator,
58+
): string {
5259
$countries = [];
5360
$examples = [];
5461

0 commit comments

Comments
 (0)