Skip to content

Commit 280f7c9

Browse files
committed
Updated coding standard that can run on PHP 7.4
1 parent 5e8127d commit 280f7c9

File tree

8 files changed

+50
-24
lines changed

8 files changed

+50
-24
lines changed

build-cs/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/composer.lock
2+
/vendor

build-cs/composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"require-dev": {
3+
"consistence/coding-standard": "^3.10",
4+
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
5+
"slevomat/coding-standard": "^6.0.8",
6+
"squizlabs/php_codesniffer": "^3.5.3"
7+
}
8+
}

build.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,21 @@
132132
<target name="cs">
133133
<php expression="PHP_VERSION_ID &gt;= 70400 ?'true':'false'" returnProperty="isPHP74" level="verbose" />
134134
<if>
135-
<equals arg1="${isPHP74}" arg2="false" />
135+
<equals arg1="${isPHP74}" arg2="true" />
136136
<then>
137137
<exec
138-
executable="vendor/bin/phpcs"
138+
executable="composer"
139+
logoutput="true"
140+
passthru="true"
141+
checkreturn="true"
142+
>
143+
<arg value="install"/>
144+
<arg value="--working-dir"/>
145+
<arg path="build-cs"/>
146+
<arg value="--ansi"/>
147+
</exec>
148+
<exec
149+
executable="build-cs/vendor/bin/phpcs"
139150
logoutput="true"
140151
passthru="true"
141152
checkreturn="true"
@@ -157,7 +168,7 @@
157168

158169
<target name="cs-fix">
159170
<exec
160-
executable="vendor/bin/phpcbf"
171+
executable="build-cs/vendor/bin/phpcbf"
161172
logoutput="true"
162173
passthru="true"
163174
checkreturn="true"

composer.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
"phpstan/phpstan": "self.version"
2525
},
2626
"require-dev": {
27-
"consistence/coding-standard": "^3.5",
28-
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
2927
"ergebnis/composer-normalize": "^2.0.2",
3028
"irstea/phpunit-shim": "7.5.18",
3129
"jakub-onderka/php-parallel-lint": "^1.0",
@@ -34,9 +32,7 @@
3432
"phpstan/phpstan-deprecation-rules": "^0.12",
3533
"phpstan/phpstan-php-parser": "^0.12",
3634
"phpstan/phpstan-phpunit": "^0.12",
37-
"phpstan/phpstan-strict-rules": "^0.12",
38-
"slevomat/coding-standard": "^4.7.2",
39-
"squizlabs/php_codesniffer": "^3.3.2"
35+
"phpstan/phpstan-strict-rules": "^0.12"
4036
},
4137
"config": {
4238
"platform": {

phpcs.xml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<ruleset name="PHPStan">
3-
<rule ref="vendor/consistence/coding-standard/Consistence/ruleset.xml">
3+
<rule ref="build-cs/vendor/consistence/coding-standard/Consistence/ruleset.xml">
44
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.InvalidFormat"/>
55
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword"/>
66
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
@@ -19,16 +19,23 @@
1919
<property name="newlinesCountBetweenOpenTagAndDeclare" value="0"/>
2020
</properties>
2121
</rule>
22-
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
22+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
2323
<properties>
24-
<property name="usefulAnnotations" type="array" value="
25-
@dataProvider,
26-
@requires
27-
"/>
2824
<property name="enableObjectTypeHint" value="false"/>
2925
</properties>
30-
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/>
31-
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"/>
26+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
27+
</rule>
28+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
29+
<properties>
30+
<property name="enableNativeTypeHint" value="false"/>
31+
</properties>
32+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
33+
</rule>
34+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
35+
<properties>
36+
<property name="enableObjectTypeHint" value="false"/>
37+
</properties>
38+
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
3239
</rule>
3340
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure.UnusedInheritedVariable">
3441
<exclude-pattern>src/Command/CommandHelper.php</exclude-pattern>
@@ -37,9 +44,10 @@
3744
<exclude-pattern>tests</exclude-pattern>
3845
</rule>
3946
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
40-
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators"/>
4147
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
42-
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
48+
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit">
49+
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.UselessElseIf"/>
50+
</rule>
4351
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
4452
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
4553
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator"/>
@@ -50,6 +58,7 @@
5058
</rule>
5159
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
5260
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
61+
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
5362
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
5463
<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>
5564
<rule ref="SlevomatCodingStandard.Classes.TraitUseDeclaration"/>

src/Analyser/IgnoredError.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class IgnoredError
99
{
1010

1111
/**
12-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
12+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
1313
* @param mixed[]|string $ignoredError
1414
* @return string Representation of the ignored error
1515
*/
@@ -34,7 +34,7 @@ public static function stringifyPattern($ignoredError): string
3434
}
3535

3636
/**
37-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
37+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
3838
* @param FileHelper $fileHelper
3939
* @param Error $error
4040
* @param string $ignoredErrorPattern

src/Command/ErrorsConsoleStyle.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function table(array $headers, array $rows): void
6262
}
6363

6464
/**
65-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
65+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
6666
* @param int $max
6767
*/
6868
public function createProgressBar($max = 0): ProgressBar
@@ -73,7 +73,7 @@ public function createProgressBar($max = 0): ProgressBar
7373
}
7474

7575
/**
76-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
76+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
7777
* @param int $max
7878
*/
7979
public function progressStart($max = 0): void
@@ -85,7 +85,7 @@ public function progressStart($max = 0): void
8585
}
8686

8787
/**
88-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
88+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
8989
* @param int $step
9090
*/
9191
public function progressAdvance($step = 1): void

tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testFormatErrorMessagesRegexEscape(): void
126126
{
127127
$formatter = new BaselineNeonErrorFormatter(new SimpleRelativePathHelper(self::DIRECTORY_PATH));
128128

129-
$result = new AnalysisResult(
129+
$result = new AnalysisResult(
130130
[new Error('Escape Regex with file # ~ \' ()', 'Testfile')],
131131
['Escape Regex without file # ~ <> \' ()'],
132132
false,

0 commit comments

Comments
 (0)