Skip to content

Commit 997b194

Browse files
committed
Fix phpcs issues in the sniff
1 parent cbce2c9 commit 997b194

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

Universal/Sniffs/DeclareStatements/DeclareStatementsStyleSniff.php

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function process(File $phpcsFile, $stackPtr)
101101
{
102102
$tokens = $phpcsFile->getTokens();
103103

104-
$openParenPtr = $tokens[$stackPtr]['parenthesis_opener'];
104+
$openParenPtr = $tokens[$stackPtr]['parenthesis_opener'];
105105
$closeParenPtr = $tokens[$stackPtr]['parenthesis_closer'];
106106

107107
if (isset($openParenPtr, $closeParenPtr) === false) {
@@ -158,12 +158,23 @@ public function process(File $phpcsFile, $stackPtr)
158158
* throw an error.
159159
*/
160160
if (!in_array($tokens[$codePtr]['code'], [\T_SEMICOLON, \T_CLOSE_TAG, \T_OPEN_CURLY_BRACKET, \T_COLON], true)) {
161-
$phpcsFile->addError('Unexpected code found after opening the declare statement without closing it.', $stackPtr, 'UnexpectedCodeFound');
161+
$phpcsFile->addError(
162+
'Unexpected code found after opening the declare statement without closing it.',
163+
$stackPtr,
164+
'UnexpectedCodeFound'
165+
);
162166
return;
163167
}
164168

165-
if ($this->declareStyle === 'requireBraces' && $hasScopeOpenerCloser === false && in_array('strict_types', $directiveStrings, true)) {
166-
$phpcsFile->addError('strict_types declaration is not compatible with requireBraces option.', $stackPtr, 'IncompatibleCurlyBracesRequirement');
169+
if ($this->declareStyle === 'requireBraces' &&
170+
$hasScopeOpenerCloser === false &&
171+
in_array('strict_types', $directiveStrings, true)
172+
) {
173+
$phpcsFile->addError(
174+
'strict_types declaration is not compatible with requireBraces option.',
175+
$stackPtr,
176+
'IncompatibleCurlyBracesRequirement'
177+
);
167178
return;
168179
}
169180

@@ -173,30 +184,56 @@ public function process(File $phpcsFile, $stackPtr)
173184
}
174185

175186
if (in_array('ticks', $this->directiveType, true)) {
176-
if ($this->declareStyle === 'requireBraces' && $hasScopeOpenerCloser === false && in_array('ticks', $directiveStrings, true)) {
177-
$phpcsFile->addError('Declare statement for found without curly braces', $stackPtr, 'MissingCurlyBracesTicks');
187+
if ($this->declareStyle === 'requireBraces' &&
188+
$hasScopeOpenerCloser === false &&
189+
in_array('ticks', $directiveStrings, true)
190+
) {
191+
$phpcsFile->addError(
192+
'Declare statement for found without curly braces',
193+
$stackPtr,
194+
'MissingCurlyBracesTicks'
195+
);
178196
return;
179197
}
180198

181199
if ($this->declareStyle === 'disallowBraces' && $hasScopeOpenerCloser !== false) {
182-
$phpcsFile->addError('Declare statement found using curly braces', $stackPtr, 'DisallowedCurlyBracesTicks');
200+
$phpcsFile->addError(
201+
'Declare statement found using curly braces',
202+
$stackPtr,
203+
'DisallowedCurlyBracesTicks'
204+
);
183205
return;
184206
}
185207
}
186208

187209
if (in_array('encoding', $this->directiveType, true)) {
188-
if ($this->declareStyle === 'requireBraces' && $hasScopeOpenerCloser === false && in_array('encoding', $directiveStrings, true)) {
189-
$phpcsFile->addError('Declare statement found without curly braces', $stackPtr, 'MissingCurlyBracesEncoding');
210+
if ($this->declareStyle === 'requireBraces' &&
211+
$hasScopeOpenerCloser === false &&
212+
in_array('encoding', $directiveStrings, true)
213+
) {
214+
$phpcsFile->addError(
215+
'Declare statement found without curly braces',
216+
$stackPtr,
217+
'MissingCurlyBracesEncoding'
218+
);
190219
return;
191220
}
192221

193222
if ($this->declareStyle === 'disallowBraces' && $hasScopeOpenerCloser !== false) {
194-
$phpcsFile->addError('Declare statement found using curly braces', $stackPtr, 'DisallowedCurlyBracesEncoding');
223+
$phpcsFile->addError(
224+
'Declare statement found using curly braces',
225+
$stackPtr,
226+
'DisallowedCurlyBracesEncoding'
227+
);
195228
return;
196229
}
197230
}
198231

199-
if ($this->declareStyle === 'requireBraces' && $hasScopeOpenerCloser === false && empty($this->directiveType) && !in_array('strict_types', $directiveStrings, true)) {
232+
if ($this->declareStyle === 'requireBraces' &&
233+
$hasScopeOpenerCloser === false &&
234+
empty($this->directiveType) &&
235+
!in_array('strict_types', $directiveStrings, true)
236+
) {
200237
$phpcsFile->addError('Declare statement found without curly braces', $stackPtr, 'MissingCurlyBraces');
201238
return;
202239
}

0 commit comments

Comments
 (0)