Skip to content

Commit

Permalink
Squiz/FunctionSpacing: minor touch-up
Browse files Browse the repository at this point in the history
Minor other code simplifications and documentation improvements.
  • Loading branch information
jrfnl committed Nov 30, 2018
1 parent e548964 commit 080bfb3
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class FunctionSpacingSniff implements Sniff
public $spacingAfterLast = 2;

/**
* The number of blank lines after the last function in a class.
* Original properties as set in a custom ruleset (if any).
*
* @var integer
* @var array|null
*/
private $rulesetProperties = null;

Expand Down Expand Up @@ -142,12 +142,11 @@ public function process(File $phpcsFile, $stackPtr)
}
}

$requiredSpacing = $this->spacing;
$errorCode = 'After';
if ($isLast === true) {
$requiredSpacing = $this->spacingAfterLast;
$errorCode = 'AfterLast';
} else {
$requiredSpacing = $this->spacing;
$errorCode = 'After';
}

$foundLines = 0;
Expand All @@ -164,7 +163,7 @@ public function process(File $phpcsFile, $stackPtr)
// should be done by an EOF sniff.
$foundLines = $requiredSpacing;
} else {
$foundLines += ($tokens[$nextContent]['line'] - $tokens[$nextLineToken]['line']);
$foundLines = ($tokens[$nextContent]['line'] - $tokens[$nextLineToken]['line']);
}
}

Expand Down Expand Up @@ -202,7 +201,7 @@ public function process(File $phpcsFile, $stackPtr)
*/

$prevLineToken = null;
for ($i = $stackPtr; $i > 0; $i--) {
for ($i = $stackPtr; $i >= 0; $i--) {
if (strpos($tokens[$i]['content'], $phpcsFile->eolChar) === false) {
continue;
} else {
Expand Down Expand Up @@ -251,7 +250,7 @@ public function process(File $phpcsFile, $stackPtr)
return;
}
} else if ($tokens[$i]['code'] === T_FUNCTION) {
// Found another interface function.
// Found another interface or abstract function.
return;
}

Expand All @@ -271,12 +270,11 @@ public function process(File $phpcsFile, $stackPtr)
}//end while
}//end if

$requiredSpacing = $this->spacing;
$errorCode = 'Before';
if ($isFirst === true) {
$requiredSpacing = $this->spacingBeforeFirst;
$errorCode = 'BeforeFirst';
} else {
$requiredSpacing = $this->spacing;
$errorCode = 'Before';
}

if ($foundLines !== $requiredSpacing) {
Expand Down

0 comments on commit 080bfb3

Please sign in to comment.