Skip to content

Commit 3c2646a

Browse files
committed
Improved code style and added stricter type hints
This commit adds strict type declarations to all files and modified exceptions thrown in test classes to use `Throwable`. It also updates the dependency list and configurations for coding style checks. Furthermore, it added new scripts and plugins to facilitate and ensure code quality.
1 parent 0f9a17e commit 3c2646a

File tree

5 files changed

+323
-25
lines changed

5 files changed

+323
-25
lines changed

composer.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@
2525
],
2626
"require-dev": {
2727
"squizlabs/php_codesniffer": "^3.10",
28-
"phpunit/phpunit": "^11.1"
28+
"phpunit/phpunit": "^11.1",
29+
"slevomat/coding-standard": "^8.15"
2930
},
3031
"scripts": {
31-
"lint": "phpcs --ignore=/vendor/* --standard=PSR12 .",
32-
"lint:fix": "phpcbf --ignore=/vendor/* --standard=PSR12 .",
32+
"lint": "phpcs",
33+
"lint:fix": "phpcbf",
3334
"test": "phpunit --testdox --coverage-clover coverage/clover.xml --coverage-html coverage --coverage-filter src/"
35+
},
36+
"config": {
37+
"allow-plugins": {
38+
"dealerdirect/phpcodesniffer-composer-installer": true
39+
}
3440
}
3541
}

composer.lock

Lines changed: 191 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpcs.xml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHPStan deprecation rules">
3+
<config name="php_version" value="70100"/>
4+
<arg name="colors"/>
5+
<arg name="extensions" value="php"/>
6+
<arg name="encoding" value="utf-8"/>
7+
<arg name="tab-width" value="4"/>
8+
<arg value="sp"/>
9+
<file>src</file>
10+
<file>tests</file>
11+
12+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
13+
<properties>
14+
<property name="caseSensitive" value="false"/>
15+
<property name="psr12Compatible" value="true"/>
16+
</properties>
17+
</rule>
18+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
19+
<properties>
20+
<property name="declareOnFirstLine" value="true"/>
21+
</properties>
22+
</rule>
23+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
24+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
25+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
26+
</rule>
27+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation">
28+
<severity>10</severity>
29+
</rule>
30+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
31+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
32+
</rule>
33+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.UselessAnnotation">
34+
<severity>10</severity>
35+
</rule>
36+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
37+
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
38+
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint"/>
39+
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
40+
</rule>
41+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation">
42+
<severity>10</severity>
43+
</rule>
44+
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure.UnusedInheritedVariable"/>
45+
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException"/>
46+
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable"/>
47+
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
48+
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit">
49+
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.UselessElseIf"/>
50+
</rule>
51+
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
52+
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
53+
<rule ref="SlevomatCodingStandard.Files">
54+
<exclude name="SlevomatCodingStandard.Files.TypeNameMatchesFileName"/>
55+
</rule>
56+
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
57+
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
58+
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
59+
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
60+
<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>
61+
<rule ref="SlevomatCodingStandard.Classes.TraitUseDeclaration"/>
62+
<rule ref="SlevomatCodingStandard.Classes.TraitUseSpacing"/>
63+
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable"/>
64+
<rule ref="SlevomatCodingStandard.Variables.UselessVariable"/>
65+
<!--<rule ref="SlevomatCodingStandard.Functions.UnusedParameter"/>-->
66+
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
67+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
68+
<properties>
69+
<property name="searchAnnotations" value="true"/>
70+
<property name="namespacesRequiredToUse" value=""/>
71+
<property name="allowPartialUses" value="true"/>
72+
<property name="allowFallbackGlobalFunctions" value="false"/>
73+
<property name="allowFallbackGlobalConstants" value="false"/>
74+
<property name="allowFullyQualifiedExceptions" value="false"/>
75+
<property name="allowFullyQualifiedNameForCollidingClasses" value="true"/>
76+
<property name="allowFullyQualifiedNameForCollidingFunctions" value="true"/>
77+
<property name="allowFullyQualifiedNameForCollidingConstants" value="true"/>
78+
</properties>
79+
</rule>
80+
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
81+
<rule ref="SlevomatCodingStandard.Namespaces.UseSpacing"/>
82+
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
83+
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses"/>
84+
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
85+
<properties>
86+
<property name="spacing" value="1" />
87+
<property name="spacingBeforeFirst" value="1"/>
88+
<property name="spacingAfterLast" value="1"/>
89+
</properties>
90+
</rule>
91+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
92+
<exclude-pattern>tests/*/data</exclude-pattern>
93+
</ruleset>

0 commit comments

Comments
 (0)