Skip to content
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
18 changes: 18 additions & 0 deletions CodingStandard/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function register()
T_ELSEIF,
T_TRY,
T_CATCH,
T_FINALLY,
);
}//end register()

Expand Down Expand Up @@ -318,6 +319,7 @@ protected function checkLeadingContent(File $phpcsFile, $stackPtr)
|| $this->insideSwitchCase($phpcsFile, $leadingContent) === true
|| ($this->elseOrElseIf($phpcsFile, $stackPtr) === true && $this->ifOrElseIf($phpcsFile, $leadingContent) === true)
|| ($this->isCatch($phpcsFile, $stackPtr) === true && $this->isTryOrCatch($phpcsFile, $leadingContent) === true)
|| ($this->isFinally($phpcsFile, $stackPtr) === true && $this->isTryOrCatch($phpcsFile, $leadingContent) === true)
) {
if ($this->isFunction($phpcsFile, $leadingContent) === true) {
// The previous content is the opening brace of a function
Expand Down Expand Up @@ -503,6 +505,7 @@ protected function checkTrailingContent(File $phpcsFile, $stackPtr)
// Code on the next line after control structure scope closer.
if ($this->elseOrElseIf($phpcsFile, $trailingContent) === true
|| $this->isCatch($phpcsFile, $trailingContent) === true
|| $this->isFinally($phpcsFile, $trailingContent) === true
) {
return;
}
Expand Down Expand Up @@ -739,6 +742,21 @@ protected function isCatch(File $phpcsFile, $stackPtr)
}//end isCatch()


/**
* Detects, that it is a closing brace of FINALLY.
*
* @param File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return bool
*/
protected function isFinally(File $phpcsFile, $stackPtr)
{
return $this->isScopeCondition($phpcsFile, $stackPtr, T_FINALLY);
}//end isFinally()


/**
* Determines that a function is located at given position.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1691,4 +1691,44 @@ catch ( Exception1 $e ) {
$c = 'd';
}

// TRY/FINALLY (no blank line required before/after "finally").
try {
$a = 'b';
}
finally {
$c = 'd';
}

// TRY/CATCH/FINALLY (no blank line required before/after "finally").
try {
$a = 'b';
}
catch ( Exception $e ) {
$c = 'd';
}
finally {
$c = 'd';
}

// TRY/FINALLY (blank line before "finally" is not allowed).
try {
$a = 'b';
}

finally {
$c = 'd';
}

// TRY/CATCH/FINALLY (blank line before "finally" is not allowed).
try {
$a = 'b';
}
catch ( Exception $e ) {
$c = 'd';
}

finally {
$c = 'd';
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -1665,4 +1665,42 @@ catch ( Exception1 $e ) {
$c = 'd';
}

// TRY/FINALLY (no blank line required before/after "finally").
try {
$a = 'b';
}
finally {
$c = 'd';
}

// TRY/CATCH/FINALLY (no blank line required before/after "finally").
try {
$a = 'b';
}
catch ( Exception $e ) {
$c = 'd';
}
finally {
$c = 'd';
}

// TRY/FINALLY (blank line before "finally" is not allowed).
try {
$a = 'b';
}
finally {
$c = 'd';
}

// TRY/CATCH/FINALLY (blank line before "finally" is not allowed).
try {
$a = 'b';
}
catch ( Exception $e ) {
$c = 'd';
}
finally {
$c = 'd';
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ public function getErrorList($testFile)

// Sequential catch statements not indented right.
1690 => 1,

// Blank line before "finally" is not allowed.
1718 => 1,
1730 => 1,
);
} elseif ($testFile === 'ControlStructureSpacingUnitTest.2.inc') {
return array(
Expand Down
Loading