Skip to content

Commit

Permalink
Add rules for use statements
Browse files Browse the repository at this point in the history
- Check that use statements are alphabetically sorted
- Check that all classes are used through uses and not referenced directly
- Check that there are no use statements for classes within the same namespace
- Check that all declared uses are actually needed
  • Loading branch information
pprkut committed Aug 3, 2024
1 parent 57b6ec5 commit 35cbd1c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "third-party/slevomat"]
path = third-party/slevomat
url = [email protected]:slevomat/coding-standard.git
13 changes: 13 additions & 0 deletions Lunr/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,17 @@
<property name="spacing" value="1"/>
</properties>
</rule>

<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<properties>
<property name="searchAnnotations" value="true"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace"/>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true"/>
</properties>
</rule>
</ruleset>
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,14 @@ $config = [
- Classes must have their opening bracket on a new line and not have it indented.
- There must be a single space after the scope keyword.
- All class keywords must be lowercase.
- Use declarations should be according to PSR-2 [psr-2/#3-namespace-and-use-declarations](https://www.php-fig.org/psr/psr-2/#3-namespace-and-use-declarations)
- There must be only one class declaration per file

## Use declarations
- Use declarations should be according to PSR-2 [psr-2/#3-namespace-and-use-declarations](https://www.php-fig.org/psr/psr-2/#3-namespace-and-use-declarations)
- Use imports should be sorted alphabetically
- All classes from other namespaces should be referenced through use statements
- Classes from the same namespace should not be referenced through use statements

## Strings
- Always have one space preceding and succeeding the concatenation symbol.

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.1"
"php": "^8.1",
"phpstan/phpdoc-parser": "^1.23.1"
},
"autoload": {
"psr-4": {
Expand Down
11 changes: 10 additions & 1 deletion decomposer.json
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
{}
{
"phpdoc-parser": {
"url": "https://github.com/phpstan/phpdoc-parser.git",
"version": "1.29.1",
"psr4": {
"prefix": "PHPStan\\PhpDocParser",
"search-path": "/src/"
}
}
}
1 change: 1 addition & 0 deletions third-party/slevomat
Submodule slevomat added at 7d1d95

0 comments on commit 35cbd1c

Please sign in to comment.