Skip to content

Commit 9775ee2

Browse files
author
Vincent Langlet
committed
✨ Add fixer for BlankLineBeforeReturnSniff
1 parent 801a6c2 commit 9775ee2

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

Symfony3Custom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,21 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6262
) {
6363
return;
6464
} else if (count($prevLineTokens) > 0) {
65-
$phpcsFile->addError(
65+
$fix = $phpcsFile->addFixableError(
6666
'Missing blank line before return statement',
67-
$stackPtr
67+
$stackPtr,
68+
'MissedBlankLineBeforeRetrun'
6869
);
70+
71+
if ($fix === true) {
72+
$phpcsFile->fixer->beginChangeset();
73+
$i = 1;
74+
while($tokens[$stackPtr-$i]['type'] == "T_WHITESPACE") {
75+
$i++;
76+
}
77+
$phpcsFile->fixer->addNewLine($stackPtr-$i);
78+
$phpcsFile->fixer->endChangeset();
79+
}
6980
}
7081

7182
return;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
function validFunctionReturnOne()
3+
{
4+
return;
5+
}
6+
7+
function validFunctionReturnTwo()
8+
{
9+
10+
return;
11+
}
12+
13+
function validFunctionReturnThree()
14+
{
15+
echo "";
16+
17+
return;
18+
}
19+
20+
function validFunctionReturnFour()
21+
{
22+
// comment
23+
return;
24+
}
25+
26+
function validFunctionReturnFive()
27+
{
28+
/**
29+
* multi-line
30+
*/
31+
return;
32+
}
33+
34+
function invalidFunctionReturnOne()
35+
{
36+
echo "";
37+
38+
return;
39+
}
40+
41+
switch ($condition) {
42+
case 'foo':
43+
return true;
44+
45+
default:
46+
return false;
47+
}

0 commit comments

Comments
 (0)