| @@ 121-149 (lines=29) @@ | ||
| 118 | } |
|
| 119 | }//end if |
|
| 120 | ||
| 121 | if ($this->requiredSpacesBeforeClose === 0 && $tokens[($closingBracket - 1)]['code'] === T_WHITESPACE) { |
|
| 122 | $error = 'Space found before closing bracket of FOREACH loop'; |
|
| 123 | $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeClose'); |
|
| 124 | if ($fix === true) { |
|
| 125 | $phpcsFile->fixer->replaceToken(($closingBracket - 1), ''); |
|
| 126 | } |
|
| 127 | } else if ($this->requiredSpacesBeforeClose > 0) { |
|
| 128 | $spaceBeforeClose = 0; |
|
| 129 | if ($tokens[($closingBracket - 1)]['code'] === T_WHITESPACE) { |
|
| 130 | $spaceBeforeClose = strlen($tokens[($closingBracket - 1)]['content']); |
|
| 131 | } |
|
| 132 | ||
| 133 | if ($spaceBeforeClose !== $this->requiredSpacesBeforeClose) { |
|
| 134 | $error = 'Expected %s spaces before closing bracket; %s found'; |
|
| 135 | $data = array( |
|
| 136 | $this->requiredSpacesBeforeClose, |
|
| 137 | $spaceBeforeClose, |
|
| 138 | ); |
|
| 139 | $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeClose', $data); |
|
| 140 | if ($fix === true) { |
|
| 141 | $padding = str_repeat(' ', $this->requiredSpacesBeforeClose); |
|
| 142 | if ($spaceBeforeClose === 0) { |
|
| 143 | $phpcsFile->fixer->addContentBefore($closingBracket, $padding); |
|
| 144 | } else { |
|
| 145 | $phpcsFile->fixer->replaceToken(($closingBracket - 1), $padding); |
|
| 146 | } |
|
| 147 | } |
|
| 148 | } |
|
| 149 | }//end if |
|
| 150 | ||
| 151 | $asToken = $phpcsFile->findNext(T_AS, $openingBracket); |
|
| 152 | if ($asToken === false) { |
|
| @@ 124-152 (lines=29) @@ | ||
| 121 | } |
|
| 122 | }//end if |
|
| 123 | ||
| 124 | if ($this->requiredSpacesBeforeClose === 0 && $tokens[($closingBracket - 1)]['code'] === T_WHITESPACE) { |
|
| 125 | $error = 'Space found before closing bracket of FOR loop'; |
|
| 126 | $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeClose'); |
|
| 127 | if ($fix === true) { |
|
| 128 | $phpcsFile->fixer->replaceToken(($closingBracket - 1), ''); |
|
| 129 | } |
|
| 130 | } else if ($this->requiredSpacesBeforeClose > 0) { |
|
| 131 | $spaceBeforeClose = 0; |
|
| 132 | if ($tokens[($closingBracket - 1)]['code'] === T_WHITESPACE) { |
|
| 133 | $spaceBeforeClose = strlen($tokens[($closingBracket - 1)]['content']); |
|
| 134 | } |
|
| 135 | ||
| 136 | if ($this->requiredSpacesBeforeClose !== $spaceBeforeClose) { |
|
| 137 | $error = 'Expected %s spaces before closing bracket; %s found'; |
|
| 138 | $data = array( |
|
| 139 | $this->requiredSpacesBeforeClose, |
|
| 140 | $spaceBeforeClose, |
|
| 141 | ); |
|
| 142 | $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeClose', $data); |
|
| 143 | if ($fix === true) { |
|
| 144 | $padding = str_repeat(' ', $this->requiredSpacesBeforeClose); |
|
| 145 | if ($spaceBeforeClose === 0) { |
|
| 146 | $phpcsFile->fixer->addContentBefore($closingBracket, $padding); |
|
| 147 | } else { |
|
| 148 | $phpcsFile->fixer->replaceToken(($closingBracket - 1), $padding); |
|
| 149 | } |
|
| 150 | } |
|
| 151 | } |
|
| 152 | }//end if |
|
| 153 | ||
| 154 | $firstSemicolon = $phpcsFile->findNext(T_SEMICOLON, $openingBracket, $closingBracket); |
|
| 155 | ||