:octocat: PHPCS: add Slevomat standard

This commit is contained in:
smiley
2024-07-22 14:29:50 +02:00
parent c4ed672a84
commit fc47c7b40f
8 changed files with 124 additions and 7 deletions
+5 -1
View File
@@ -50,6 +50,7 @@
"phpunit/phpunit": "^9.6",
"phpmd/phpmd": "^2.15",
"setasign/fpdf": "^1.8.2",
"slevomat/coding-standard": "^8.15",
"squizlabs/php_codesniffer": "^3.10"
},
"suggest": {
@@ -75,6 +76,9 @@
"config": {
"lock": false,
"sort-packages": true,
"platform-check": true
"platform-check": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
+2 -2
View File
@@ -48,7 +48,7 @@ try{
$moduleValues = array_map(function($v){
if(preg_match('/[a-f\d]{6}/i', $v) === 1){
return in_array($_POST['output_type'], ['png', 'jpg', 'gif'])
return in_array($_POST['output_type'], ['png', 'jpg', 'gif'], true)
? array_map('hexdec', str_split($v, 2))
: '#'.$v ;
}
@@ -73,7 +73,7 @@ try{
$qrcode = (new QRCode($options))->render($_POST['inputstring']);
if(in_array($_POST['output_type'], ['png', 'jpg', 'gif', 'svg'])){
if(in_array($_POST['output_type'], ['png', 'jpg', 'gif', 'svg'], true)){
$qrcode = '<img alt="qrcode" src="'.$qrcode.'" />';
}
elseif($_POST['output_type'] === 'text'){
+109
View File
@@ -17,6 +17,115 @@
<type>error</type>
</rule>
<!--
Slevomat https://github.com/slevomat/coding-standard
-->
<config name="installed_paths" value="../../slevomat/coding-standard"/>
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
<rule ref="SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation"/>
<rule ref="SlevomatCodingStandard.Arrays.DisallowPartiallyKeyed"/>
<rule ref="SlevomatCodingStandard.Attributes.DisallowAttributesJoining"/>
<rule ref="SlevomatCodingStandard.Attributes.DisallowMultipleAttributesPerLine"/>
<rule ref="SlevomatCodingStandard.Attributes.RequireAttributeAfterDocComment"/>
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility"/>
<rule ref="SlevomatCodingStandard.Classes.DisallowConstructorPropertyPromotion"/>
<rule ref="SlevomatCodingStandard.Classes.ForbiddenPublicProperty"/>
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
<rule ref="SlevomatCodingStandard.Commenting.DeprecatedAnnotationDeclaration"/>
<!--
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
<rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment"/>
<rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment"/>
-->
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch"/>
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator"/>
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowTrailingMultiLineTernaryOperator"/>
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithoutParentheses"/>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator"/>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
<!--<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator"/>-->
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
<rule ref="SlevomatCodingStandard.ControlStructures.UselessTernaryOperator"/>
<!--<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch"/>-->
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction"/>
<!--
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
-->
<rule ref="SlevomatCodingStandard.Functions.StrictCall"/>
<rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/>
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"/>
<rule ref="SlevomatCodingStandard.Numbers.DisallowNumericLiteralSeparator"/>
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
<rule ref="SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking"/>
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
<rule ref="SlevomatCodingStandard.Strings.DisallowVariableParsing"/>
<!--<rule ref="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint"/>-->
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
<!--<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>-->
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
<!--
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
-->
<rule ref="SlevomatCodingStandard.Variables.DisallowVariableVariable"/>
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable"/>
<rule ref="SlevomatCodingStandard.Variables.UselessVariable"/>
<!--
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="linesCountBeforeDeclare" value="0"/>
<property name="linesCountAfterDeclare" value="1"/>
<property name="spacesCountAroundEqualsSign" value="0"/>
</properties>
</rule>
-->
<rule ref="SlevomatCodingStandard.Functions.RequireMultiLineCall">
<properties>
<property name="minLineLength" value="131"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable">
<exclude-pattern>examples</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat">
<properties>
<property name="enable" value="false"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable">
<properties>
<property name="ignoreUnusedValuesWhenOnlyKeysAreUsedInForeach" value="true"/>
</properties>
</rule>
<!--
PHPCS built-in https://tentyp.dev/library/php/phpcs/
-->
+1 -1
View File
@@ -108,7 +108,7 @@ final class ECI extends QRDataModeAbstract{
$id = ((($firstByte & 0b00011111) << 16) | $bitBuffer->read(16));
}
else{
throw new QRCodeDataException(sprintf('error decoding ECI value first byte: %08b', $firstByte)); // @codeCoverageIgnore
throw new QRCodeDataException(sprintf('error decoding ECI value first byte: %08b', $firstByte));// @codeCoverageIgnore
}
return new ECICharset($id);
+1 -1
View File
@@ -94,7 +94,7 @@ final class ReedSolomonDecoder{
while($longerBlocksStartAt >= 0){
$numCodewords = count($result[$longerBlocksStartAt][1]);
if($numCodewords == $shorterBlocksTotalCodewords){
if($numCodewords === $shorterBlocksTotalCodewords){
break;
}
+2 -1
View File
@@ -256,7 +256,7 @@ final class AlignmentPatternFinder{
$i++;
}
if($i == $maxI || $stateCount[1] > $maxCount){
if($i === $maxI || $stateCount[1] > $maxCount){
return null;
}
@@ -269,6 +269,7 @@ final class AlignmentPatternFinder{
return null;
}
// phpcs:ignore
if((5 * abs(($stateCount[0] + $stateCount[1] + $stateCount[2]) - $originalStateCountTotal)) >= (2 * $originalStateCountTotal)){
return null;
}
+3
View File
@@ -290,11 +290,13 @@ final class FinderPatternFinder{
// Now also count down, right from center
$i = 1;
// phpcs:ignore
while(($centerI + $i) < $dimension && ($centerJ + $i) < $dimension && $this->matrix->check(($centerJ + $i), ($centerI + $i))){
$stateCount[2]++;
$i++;
}
// phpcs:ignore
while(($centerI + $i) < $dimension && ($centerJ + $i) < $dimension && !$this->matrix->check(($centerJ + $i), ($centerI + $i))){
$stateCount[3]++;
$i++;
@@ -304,6 +306,7 @@ final class FinderPatternFinder{
return false;
}
// phpcs:ignore
while(($centerI + $i) < $dimension && ($centerJ + $i) < $dimension && $this->matrix->check(($centerJ + $i), ($centerI + $i))){
$stateCount[4]++;
$i++;
+1 -1
View File
@@ -303,7 +303,7 @@ class QRCode{
throw new QRCodeOutputException('invalid output module');
}
if(!in_array(QROutputInterface::class, class_implements($outputInterface))){
if(!in_array(QROutputInterface::class, class_implements($outputInterface), true)){
throw new QRCodeOutputException('output module does not implement QROutputInterface');
}