Skip to content

Commit 6d70b46

Browse files
✨ Discourage empty function
1 parent c87db5f commit 6d70b46

36 files changed

+121
-360
lines changed

SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ public function processMultiLineArray(File $phpcsFile, int $stackPtr, int $start
472472
}
473473
}
474474

475-
if (!empty($indices)) {
476-
$count = count($indices);
475+
$count = count($indices);
476+
if ($count > 0) {
477477
$lastIndex = $indices[($count - 1)]['value'];
478478

479479
$trailingContent = $phpcsFile->findPrevious(
@@ -499,12 +499,12 @@ public function processMultiLineArray(File $phpcsFile, int $stackPtr, int $start
499499

500500
$lastValueLine = $stackPtr;
501501
foreach ($indices as $value) {
502-
if (!empty($value['arrow'])) {
502+
if (isset($value['arrow'])) {
503503
// Array value with arrow are checked later cause there is more checks.
504504
continue;
505505
}
506506

507-
if (empty($value['value'])) {
507+
if (!isset($value['value'])) {
508508
// Array was malformed, so we have to ignore it.
509509
// Other parts of this sniff will correct the error.
510510
continue;

SymfonyCustom/Sniffs/Namespaces/AlphabeticallySortedUseSniff.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ public function process(File $phpcsFile, $stackPtr): int
9999
$lastUse = $use;
100100
}
101101

102-
return T_OPEN_TAG === $tokens[$stackPtr]['code']
103-
? $phpcsFile->numTokens + 1
104-
: $stackPtr + 1;
102+
return T_OPEN_TAG === $tokens[$stackPtr]['code'] ? $phpcsFile->numTokens + 1 : $stackPtr + 1;
105103
}
106104

107105
/**
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace SymfonyCustom\Sniffs\PHP;
4+
5+
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
6+
7+
/**
8+
* Class DiscourageEmptySniff
9+
*/
10+
class DiscourageEmptySniff extends ForbiddenFunctionsSniff
11+
{
12+
/**
13+
* @var array
14+
*/
15+
public $forbiddenFunctions = ['empty' => null];
16+
17+
/**
18+
* @var bool
19+
*/
20+
public $error = false;
21+
}

SymfonyCustom/Tests/Arrays/ArrayDeclarationUnitTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
class ArrayDeclarationUnitTest extends AbstractSniffUnitTest
1313
{
1414
/**
15-
* Returns the lines where errors should occur.
16-
*
17-
* The key of the array should represent the line number and the value
18-
* should represent the number of errors that should occur on that line.
19-
*
20-
* @return array<int, int>
15+
* @return array
2116
*/
2217
protected function getErrorList(): array
2318
{
@@ -58,12 +53,7 @@ protected function getErrorList(): array
5853
}
5954

6055
/**
61-
* Returns the lines where warnings should occur.
62-
*
63-
* The key of the array should represent the line number and the value
64-
* should represent the number of warnings that should occur on that line.
65-
*
66-
* @return array<int, int>
56+
* @return array
6757
*/
6858
protected function getWarningList(): array
6959
{

SymfonyCustom/Tests/Classes/ClassDeclarationUnitTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
class ClassDeclarationUnitTest extends AbstractSniffUnitTest
1313
{
1414
/**
15-
* Returns the lines where errors should occur.
16-
*
17-
* The key of the array should represent the line number and the value
18-
* should represent the number of errors that should occur on that line.
19-
*
20-
* @return array<int, int>
15+
* @return array
2116
*/
2217
protected function getErrorList(): array
2318
{
@@ -28,12 +23,7 @@ protected function getErrorList(): array
2823
}
2924

3025
/**
31-
* Returns the lines where warnings should occur.
32-
*
33-
* The key of the array should represent the line number and the value
34-
* should represent the number of errors that should occur on that line.
35-
*
36-
* @return array(int => int)
26+
* @return array
3727
*/
3828
protected function getWarningList(): array
3929
{

SymfonyCustom/Tests/Classes/PropertyDeclarationUnitTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
class PropertyDeclarationUnitTest extends AbstractSniffUnitTest
1313
{
1414
/**
15-
* Returns the lines where errors should occur.
16-
*
17-
* The key of the array should represent the line number and the value
18-
* should represent the number of errors that should occur on that line.
19-
*
20-
* @return array<int, int>
15+
* @return array
2116
*/
2217
protected function getErrorList(): array
2318
{
@@ -27,12 +22,7 @@ protected function getErrorList(): array
2722
}
2823

2924
/**
30-
* Returns the lines where warnings should occur.
31-
*
32-
* The key of the array should represent the line number and the value
33-
* should represent the number of errors that should occur on that line.
34-
*
35-
* @return array(int => int)
25+
* @return array
3626
*/
3727
protected function getWarningList(): array
3828
{

SymfonyCustom/Tests/Commenting/ClassCommentUnitTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
class ClassCommentUnitTest extends AbstractSniffUnitTest
1313
{
1414
/**
15-
* Returns the lines where errors should occur.
16-
*
17-
* The key of the array should represent the line number and the value
18-
* should represent the number of errors that should occur on that line.
19-
*
20-
* @return array<int, int>
15+
* @return array
2116
*/
2217
protected function getErrorList(): array
2318
{
@@ -27,12 +22,7 @@ protected function getErrorList(): array
2722
}
2823

2924
/**
30-
* Returns the lines where warnings should occur.
31-
*
32-
* The key of the array should represent the line number and the value
33-
* should represent the number of warnings that should occur on that line.
34-
*
35-
* @return array(int => int)
25+
* @return array
3626
*/
3727
protected function getWarningList(): array
3828
{

SymfonyCustom/Tests/Commenting/DocCommentForbiddenTagsUnitTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
class DocCommentForbiddenTagsUnitTest extends AbstractSniffUnitTest
1313
{
1414
/**
15-
* Returns the lines where errors should occur.
16-
*
17-
* The key of the array should represent the line number and the value
18-
* should represent the number of errors that should occur on that line.
19-
*
20-
* @return array<int, int>
15+
* @return array
2116
*/
2217
protected function getErrorList(): array
2318
{
@@ -32,12 +27,7 @@ protected function getErrorList(): array
3227
}
3328

3429
/**
35-
* Returns the lines where warnings should occur.
36-
*
37-
* The key of the array should represent the line number and the value
38-
* should represent the number of warnings that should occur on that line.
39-
*
40-
* @return array(int => int)
30+
* @return array
4131
*/
4232
protected function getWarningList(): array
4333
{

SymfonyCustom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
class DocCommentGroupSameTypeUnitTest extends AbstractSniffUnitTest
1313
{
1414
/**
15-
* Returns the lines where errors should occur.
16-
*
17-
* The key of the array should represent the line number and the value
18-
* should represent the number of errors that should occur on that line.
19-
*
20-
* @return array<int, int>
15+
* @return array
2116
*/
2217
protected function getErrorList(): array
2318
{
@@ -37,12 +32,7 @@ protected function getErrorList(): array
3732
}
3833

3934
/**
40-
* Returns the lines where warnings should occur.
41-
*
42-
* The key of the array should represent the line number and the value
43-
* should represent the number of warnings that should occur on that line.
44-
*
45-
* @return array(int => int)
35+
* @return array
4636
*/
4737
protected function getWarningList(): array
4838
{

SymfonyCustom/Tests/Commenting/DocCommentUnitTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
class DocCommentUnitTest extends AbstractSniffUnitTest
1313
{
1414
/**
15-
* Returns the lines where errors should occur.
16-
*
17-
* The key of the array should represent the line number and the value
18-
* should represent the number of errors that should occur on that line.
19-
*
20-
* @return array<int, int>
15+
* @return array
2116
*/
2217
protected function getErrorList(): array
2318
{
@@ -37,12 +32,7 @@ protected function getErrorList(): array
3732
}
3833

3934
/**
40-
* Returns the lines where warnings should occur.
41-
*
42-
* The key of the array should represent the line number and the value
43-
* should represent the number of warnings that should occur on that line.
44-
*
45-
* @return array(int => int)
35+
* @return array
4636
*/
4737
protected function getWarningList(): array
4838
{

SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
class FunctionCommentUnitTest extends AbstractSniffUnitTest
1313
{
1414
/**
15-
* Returns the lines where errors should occur.
16-
*
17-
* The key of the array should represent the line number and the value
18-
* should represent the number of errors that should occur on that line.
19-
*
20-
* @return array<int, int>
15+
* @return array
2116
*/
2217
protected function getErrorList(): array
2318
{
@@ -35,12 +30,7 @@ protected function getErrorList(): array
3530
}
3631

3732
/**
38-
* Returns the lines where warnings should occur.
39-
*
40-
* The key of the array should represent the line number and the value
41-
* should represent the number of warnings that should occur on that line.
42-
*
43-
* @return array(int => int)
33+
* @return array
4434
*/
4535
protected function getWarningList(): array
4636
{

SymfonyCustom/Tests/Commenting/VariableCommentUnitTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
class VariableCommentUnitTest extends AbstractSniffUnitTest
1313
{
1414
/**
15-
* Returns the lines where errors should occur.
16-
*
17-
* The key of the array should represent the line number and the value
18-
* should represent the number of errors that should occur on that line.
19-
*
20-
* @return array<int, int>
15+
* @return array
2116
*/
2217
protected function getErrorList(): array
2318
{
@@ -35,12 +30,7 @@ protected function getErrorList(): array
3530
}
3631

3732
/**
38-
* Returns the lines where warnings should occur.
39-
*
40-
* The key of the array should represent the line number and the value
41-
* should represent the number of warnings that should occur on that line.
42-
*
43-
* @return array<int, int>
33+
* @return array
4434
*/
4535
protected function getWarningList(): array
4636
{

SymfonyCustom/Tests/Errors/ExceptionMessageUnitTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
class ExceptionMessageUnitTest extends AbstractSniffUnitTest
1313
{
1414
/**
15-
* Returns the lines where errors should occur.
16-
*
17-
* The key of the array should represent the line number and the value
18-
* should represent the number of errors that should occur on that line.
19-
*
20-
* @return array<int, int>
15+
* @return array
2116
*/
2217
protected function getErrorList(): array
2318
{
@@ -27,12 +22,7 @@ protected function getErrorList(): array
2722
}
2823

2924
/**
30-
* Returns the lines where warnings should occur.
31-
*
32-
* The key of the array should represent the line number and the value
33-
* should represent the number of errors that should occur on that line.
34-
*
35-
* @return array(int => int)
25+
* @return array
3626
*/
3727
protected function getWarningList(): array
3828
{

SymfonyCustom/Tests/Errors/UserDeprecatedUnitTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
class UserDeprecatedUnitTest extends AbstractSniffUnitTest
1313
{
1414
/**
15-
* Returns the lines where errors should occur.
16-
*
17-
* The key of the array should represent the line number and the value
18-
* should represent the number of errors that should occur on that line.
19-
*
20-
* @return array<int, int>
15+
* @return array
2116
*/
2217
protected function getErrorList(): array
2318
{
@@ -27,12 +22,7 @@ protected function getErrorList(): array
2722
}
2823

2924
/**
30-
* Returns the lines where warnings should occur.
31-
*
32-
* The key of the array should represent the line number and the value
33-
* should represent the number of errors that should occur on that line.
34-
*
35-
* @return array(int => int)
25+
* @return array
3626
*/
3727
protected function getWarningList(): array
3828
{

SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
class BlankLineBeforeReturnUnitTest extends AbstractSniffUnitTest
1313
{
1414
/**
15-
* Returns the lines where errors should occur.
16-
*
17-
* The key of the array should represent the line number and the value
18-
* should represent the number of errors that should occur on that line.
19-
*
20-
* @return array(int => int)
15+
* @return array
2116
*/
2217
protected function getErrorList(): array
2318
{
@@ -29,12 +24,7 @@ protected function getErrorList(): array
2924
}
3025

3126
/**
32-
* Returns the lines where warnings should occur.
33-
*
34-
* The key of the array should represent the line number and the value
35-
* should represent the number of errors that should occur on that line.
36-
*
37-
* @return array(int => int)
27+
* @return array
3828
*/
3929
protected function getWarningList(): array
4030
{

0 commit comments

Comments
 (0)