Skip to content

Commit ba42e97

Browse files
✨ Minor improvements
1 parent e181258 commit ba42e97

File tree

9 files changed

+41
-15
lines changed

9 files changed

+41
-15
lines changed

SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,13 @@ public function process(File $phpcsFile, $stackPtr)
109109
true
110110
);
111111

112-
// If a backslash is used before the class name then this is some other use statement.
113-
if (T_USE !== $tokens[$beforeUsage]['code'] && T_NS_SEPARATOR !== $tokens[$beforeUsage]['code']) {
112+
if (!in_array($tokens[$beforeUsage]['code'], [
113+
T_USE,
114+
// If a backslash is used before the class name then this is some other use statement.
115+
T_NS_SEPARATOR,
116+
// If an object operator is used before the class name then is a class property.
117+
T_OBJECT_OPERATOR,
118+
])) {
114119
return;
115120
}
116121

SymfonyCustom/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PHP_CodeSniffer\Util\Tokens;
88

99
/**
10-
* Checks that there is no white space before a closing bracket, for ")" and "}".
10+
* Checks that there is no white space before a closing bracket, for ")", "}", and array bracket.
1111
* Square Brackets are handled by Squiz_Sniffs_Arrays_ArrayBracketSpacingSniff.
1212
*/
1313
class CloseBracketSpacingSniff implements Sniff

SymfonyCustom/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use PHP_CodeSniffer\Sniffs\Sniff;
77

88
/**
9-
* Checks that there is no white space after an opening bracket, for "(" and "{".
9+
* Checks that there is no white space after an opening bracket, for "(", "{", and array bracket.
1010
* Square Brackets are handled by Squiz_Sniffs_Arrays_ArrayBracketSpacingSniff.
1111
*/
1212
class OpenBracketSpacingSniff implements Sniff

SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use Client;
1313
use Clients;
1414
use PasClient;
1515
use Somewhere\Something;
16+
use Somewhere\SomethingElse;
1617

1718
class Container
1819
{
@@ -28,7 +29,8 @@ class Container
2829
function test (Bar $bar): Something
2930
{
3031
/** @var Client|Clients[]|PasClient $client */
32+
$client = [$this->somethingElse];
3133

32-
return;
34+
return $client;
3335
}
3436
}

SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.inc.fixed

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class Container
2727
function test (Bar $bar): Something
2828
{
2929
/** @var Client|Clients[]|PasClient $client */
30+
$client = [$this->somethingElse];
3031

31-
return;
32+
return $client;
3233
}
3334
}

SymfonyCustom/Tests/Namespaces/UnusedUseUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function getErrorList()
2323
{
2424
return [
2525
11 => 1,
26+
16 => 1,
2627
];
2728
}
2829

SymfonyCustom/ruleset.xml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,10 @@
6060
</rule>
6161

6262
<!-- Added by VincentLanglet repo -->
63-
<rule ref="Generic.PHP.ForbiddenFunctions"/>
64-
<rule ref="Squiz.PHP.DiscouragedFunctions"/>
65-
<rule ref="Squiz.Strings.DoubleQuoteUsage">
66-
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/>
67-
</rule>
63+
<!-- Whitespace -->
64+
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
6865
<rule ref="Squiz.WhiteSpace.FunctionOpeningBraceSpace"/>
66+
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
6967
<rule ref="Squiz.WhiteSpace.OperatorSpacing">
7068
<properties>
7169
<property name="ignoreNewlines" value="true"/>
@@ -77,9 +75,19 @@
7775
</properties>
7876
</rule>
7977
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
78+
79+
<!-- Comment -->
80+
<rule ref="Generic.Commenting.DocComment">
81+
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
82+
</rule>
83+
<rule ref="Squiz.Commenting.DocCommentAlignment"/>
84+
85+
<!-- Others -->
86+
<rule ref="Generic.PHP.ForbiddenFunctions"/>
87+
<rule ref="Squiz.PHP.DiscouragedFunctions"/>
8088
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
89+
<rule ref="Squiz.Strings.DoubleQuoteUsage">
90+
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/>
91+
</rule>
8192
<rule ref="Generic.CodeAnalysis.EmptyPHPStatement"/>
82-
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
83-
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
84-
<rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing"/>
8593
</ruleset>

docs/standards.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ we do not respect this rule:
138138
</rule>
139139
```
140140

141+
- DocComment should start on a new line, end on a new line and be correctly indented
142+
143+
```
144+
<rule ref="Generic.Commenting.DocComment">
145+
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
146+
</rule>
147+
<rule ref="Squiz.Commenting.DocCommentAlignment"/>
148+
```
149+
141150
### Custom
142151
- Some others checks are made about array (`=>` alignments and indentation)
143152

docs/standards/symfony.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ Covered by `PSR1` completed by
182182

183183
- Add PHPDoc blocks for all classes, methods, and functions
184184

185-
We added exceptions for functions `setUp`, `tearDown` and `tests` with no `@param` or `@return`
185+
We added exceptions for functions with no `@param` or `@return`
186186
```
187187
<rule ref="SymfonyCustom.Commenting.ClassComment"/>
188188
<rule ref="SymfonyCustom.Commenting.FunctionComment"/>

0 commit comments

Comments
 (0)