Skip to content

Fix return #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ public function process(File $phpcsFile, $stackPtr)
$tokens = $phpcsFile->getTokens();
$current = $stackPtr;
$previousLine = $tokens[$stackPtr]['line'] - 1;
$prevLineTokens = array();
$prevLineTokens = array();

while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) {
if ($tokens[$current]['line'] === $previousLine
&& 'T_WHITESPACE' !== $tokens[$current]['type']
&& 'T_COMMENT' !== $tokens[$current]['type']
&& 'T_DOC_COMMENT_STRING' !== $tokens[$current]['type']
&& 'T_DOC_COMMENT_OPEN_TAG' !== $tokens[$current]['type']
&& 'T_DOC_COMMENT_CLOSE_TAG' !== $tokens[$current]['type']
&& 'T_DOC_COMMENT_WHITESPACE' !== $tokens[$current]['type']
) {
Expand All @@ -62,7 +64,7 @@ public function process(File $phpcsFile, $stackPtr)
$fix = $phpcsFile->addFixableError(
'Missing blank line before return statement',
$stackPtr,
'MissedBlankLineBeforeRetrun'
'MissedBlankLineBeforeReturn'
);

if (true === $fix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ function validFunctionReturnFive()
return;
}

function validFunctionReturnSix()
{
/** comment */
return;
}

function invalidFunctionReturnOne()
{
echo "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ function validFunctionReturnFive()
return;
}

function validFunctionReturnSix()
{
/** comment */
return;
}

function invalidFunctionReturnOne()
{
echo "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BlankLineBeforeReturnUnitTest extends AbstractSniffUnitTest
public function getErrorList()
{
return array(
37 => 1,
43 => 1,
);
}

Expand Down
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This standard can be installed with the [Composer](https://getcomposer.org/) dep
1. Add the coding standard as a dependency of your project

```
composer require --dev vincentlanglet/symfony3-custom-coding-standard
composer require --dev vincentlanglet/symfony-custom-coding-standard
```

2. Add the coding standard to the PHP_CodeSniffer install path
Expand All @@ -14,7 +14,7 @@ The path is relative to the php_codesniffer install path.
This is important to make it work both in your vagrant, local machine and PHPStorm

```
bin/phpcs --config-set installed_paths ../../vincentlanglet/symfony3-custom-coding-standard
bin/phpcs --config-set installed_paths ../../vincentlanglet/symfony-custom-coding-standard
```

3. Check the installed coding standards
Expand Down