Skip to content

Commit fc47c7b

Browse files
committed
:octocat: PHPCS: add Slevomat standard
1 parent c4ed672 commit fc47c7b

File tree

8 files changed

+124
-7
lines changed

8 files changed

+124
-7
lines changed

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"phpunit/phpunit": "^9.6",
5151
"phpmd/phpmd": "^2.15",
5252
"setasign/fpdf": "^1.8.2",
53+
"slevomat/coding-standard": "^8.15",
5354
"squizlabs/php_codesniffer": "^3.10"
5455
},
5556
"suggest": {
@@ -75,6 +76,9 @@
7576
"config": {
7677
"lock": false,
7778
"sort-packages": true,
78-
"platform-check": true
79+
"platform-check": true,
80+
"allow-plugins": {
81+
"dealerdirect/phpcodesniffer-composer-installer": true
82+
}
7983
}
8084
}

examples/qrcode-interactive.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
$moduleValues = array_map(function($v){
5050
if(preg_match('/[a-f\d]{6}/i', $v) === 1){
51-
return in_array($_POST['output_type'], ['png', 'jpg', 'gif'])
51+
return in_array($_POST['output_type'], ['png', 'jpg', 'gif'], true)
5252
? array_map('hexdec', str_split($v, 2))
5353
: '#'.$v ;
5454
}
@@ -73,7 +73,7 @@
7373

7474
$qrcode = (new QRCode($options))->render($_POST['inputstring']);
7575

76-
if(in_array($_POST['output_type'], ['png', 'jpg', 'gif', 'svg'])){
76+
if(in_array($_POST['output_type'], ['png', 'jpg', 'gif', 'svg'], true)){
7777
$qrcode = '<img alt="qrcode" src="'.$qrcode.'" />';
7878
}
7979
elseif($_POST['output_type'] === 'text'){

phpcs.xml.dist

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,115 @@
1717
<type>error</type>
1818
</rule>
1919

20+
<!--
21+
Slevomat https://github.com/slevomat/coding-standard
22+
-->
23+
24+
<config name="installed_paths" value="../../slevomat/coding-standard"/>
25+
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
26+
<rule ref="SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation"/>
27+
<rule ref="SlevomatCodingStandard.Arrays.DisallowPartiallyKeyed"/>
28+
29+
<rule ref="SlevomatCodingStandard.Attributes.DisallowAttributesJoining"/>
30+
<rule ref="SlevomatCodingStandard.Attributes.DisallowMultipleAttributesPerLine"/>
31+
<rule ref="SlevomatCodingStandard.Attributes.RequireAttributeAfterDocComment"/>
32+
33+
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility"/>
34+
<rule ref="SlevomatCodingStandard.Classes.DisallowConstructorPropertyPromotion"/>
35+
<rule ref="SlevomatCodingStandard.Classes.ForbiddenPublicProperty"/>
36+
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
37+
38+
<rule ref="SlevomatCodingStandard.Commenting.DeprecatedAnnotationDeclaration"/>
39+
<!--
40+
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
41+
<rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment"/>
42+
<rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment"/>
43+
-->
44+
45+
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
46+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch"/>
47+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator"/>
48+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowTrailingMultiLineTernaryOperator"/>
49+
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithoutParentheses"/>
50+
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator"/>
51+
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
52+
<!--<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator"/>-->
53+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
54+
<rule ref="SlevomatCodingStandard.ControlStructures.UselessTernaryOperator"/>
55+
56+
<!--<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch"/>-->
57+
58+
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction"/>
59+
<!--
60+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
61+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
62+
-->
63+
<rule ref="SlevomatCodingStandard.Functions.StrictCall"/>
64+
65+
<rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/>
66+
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
67+
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
68+
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"/>
69+
70+
<rule ref="SlevomatCodingStandard.Numbers.DisallowNumericLiteralSeparator"/>
71+
72+
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
73+
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
74+
75+
<rule ref="SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking"/>
76+
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
77+
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
78+
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
79+
80+
<rule ref="SlevomatCodingStandard.Strings.DisallowVariableParsing"/>
81+
82+
<!--<rule ref="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint"/>-->
83+
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
84+
<!--<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>-->
85+
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
86+
<!--
87+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
88+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
89+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
90+
-->
91+
92+
<rule ref="SlevomatCodingStandard.Variables.DisallowVariableVariable"/>
93+
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable"/>
94+
<rule ref="SlevomatCodingStandard.Variables.UselessVariable"/>
95+
96+
<!--
97+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
98+
<properties>
99+
<property name="linesCountBeforeDeclare" value="0"/>
100+
<property name="linesCountAfterDeclare" value="1"/>
101+
<property name="spacesCountAroundEqualsSign" value="0"/>
102+
</properties>
103+
</rule>
104+
-->
105+
106+
<rule ref="SlevomatCodingStandard.Functions.RequireMultiLineCall">
107+
<properties>
108+
<property name="minLineLength" value="131"/>
109+
</properties>
110+
</rule>
111+
112+
<rule ref="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable">
113+
<exclude-pattern>examples</exclude-pattern>
114+
</rule>
115+
116+
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat">
117+
<properties>
118+
<property name="enable" value="false"/>
119+
</properties>
120+
</rule>
121+
122+
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable">
123+
<properties>
124+
<property name="ignoreUnusedValuesWhenOnlyKeysAreUsedInForeach" value="true"/>
125+
</properties>
126+
</rule>
127+
128+
20129
<!--
21130
PHPCS built-in https://tentyp.dev/library/php/phpcs/
22131
-->

src/Data/ECI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static function parseValue(BitBuffer $bitBuffer):ECICharset{
108108
$id = ((($firstByte & 0b00011111) << 16) | $bitBuffer->read(16));
109109
}
110110
else{
111-
throw new QRCodeDataException(sprintf('error decoding ECI value first byte: %08b', $firstByte)); // @codeCoverageIgnore
111+
throw new QRCodeDataException(sprintf('error decoding ECI value first byte: %08b', $firstByte));// @codeCoverageIgnore
112112
}
113113

114114
return new ECICharset($id);

src/Decoder/ReedSolomonDecoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private function deinterleaveRawBytes(array $rawCodewords):array{
9494
while($longerBlocksStartAt >= 0){
9595
$numCodewords = count($result[$longerBlocksStartAt][1]);
9696

97-
if($numCodewords == $shorterBlocksTotalCodewords){
97+
if($numCodewords === $shorterBlocksTotalCodewords){
9898
break;
9999
}
100100

src/Detector/AlignmentPatternFinder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private function crossCheckVertical(int $startI, int $centerJ, int $maxCount, in
256256
$i++;
257257
}
258258

259-
if($i == $maxI || $stateCount[1] > $maxCount){
259+
if($i === $maxI || $stateCount[1] > $maxCount){
260260
return null;
261261
}
262262

@@ -269,6 +269,7 @@ private function crossCheckVertical(int $startI, int $centerJ, int $maxCount, in
269269
return null;
270270
}
271271

272+
// phpcs:ignore
272273
if((5 * abs(($stateCount[0] + $stateCount[1] + $stateCount[2]) - $originalStateCountTotal)) >= (2 * $originalStateCountTotal)){
273274
return null;
274275
}

src/Detector/FinderPatternFinder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,13 @@ private function crossCheckDiagonal(int $centerI, int $centerJ):bool{
290290

291291
// Now also count down, right from center
292292
$i = 1;
293+
// phpcs:ignore
293294
while(($centerI + $i) < $dimension && ($centerJ + $i) < $dimension && $this->matrix->check(($centerJ + $i), ($centerI + $i))){
294295
$stateCount[2]++;
295296
$i++;
296297
}
297298

299+
// phpcs:ignore
298300
while(($centerI + $i) < $dimension && ($centerJ + $i) < $dimension && !$this->matrix->check(($centerJ + $i), ($centerI + $i))){
299301
$stateCount[3]++;
300302
$i++;
@@ -304,6 +306,7 @@ private function crossCheckDiagonal(int $centerI, int $centerJ):bool{
304306
return false;
305307
}
306308

309+
// phpcs:ignore
307310
while(($centerI + $i) < $dimension && ($centerJ + $i) < $dimension && $this->matrix->check(($centerJ + $i), ($centerI + $i))){
308311
$stateCount[4]++;
309312
$i++;

src/QRCode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ protected function initOutputInterface(QRMatrix $matrix):QROutputInterface{
303303
throw new QRCodeOutputException('invalid output module');
304304
}
305305

306-
if(!in_array(QROutputInterface::class, class_implements($outputInterface))){
306+
if(!in_array(QROutputInterface::class, class_implements($outputInterface), true)){
307307
throw new QRCodeOutputException('output module does not implement QROutputInterface');
308308
}
309309

0 commit comments

Comments
 (0)