Skip to content

Commit 7cbccff

Browse files
✨ Add PSR12 restictrions for controles stuctures
1 parent b266f4b commit 7cbccff

19 files changed

+95
-53
lines changed

SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ public function processMultiLineArray(File $phpcsFile, int $stackPtr, int $start
287287
$nextToken = $tokens[$nextToken]['scope_closer'];
288288
continue 2;
289289
case T_OPEN_PARENTHESIS:
290-
if (!isset($tokens[$nextToken]['parenthesis_owner'])
290+
if (
291+
!isset($tokens[$nextToken]['parenthesis_owner'])
291292
|| $tokens[$nextToken]['parenthesis_owner'] !== $stackPtr
292293
) {
293294
$nextToken = $tokens[$nextToken]['parenthesis_closer'];
@@ -296,7 +297,8 @@ public function processMultiLineArray(File $phpcsFile, int $stackPtr, int $start
296297
break;
297298
}
298299

299-
if (!in_array($tokens[$nextToken]['code'], [T_DOUBLE_ARROW, T_COMMA])
300+
if (
301+
!in_array($tokens[$nextToken]['code'], [T_DOUBLE_ARROW, T_COMMA])
300302
&& $nextToken !== $end - 1
301303
) {
302304
continue;
@@ -347,7 +349,8 @@ public function processMultiLineArray(File $phpcsFile, int $stackPtr, int $start
347349
$indices[] = ['value' => $valueContent];
348350
}
349351

350-
if (T_COMMA === $tokens[$nextToken]['code']
352+
if (
353+
T_COMMA === $tokens[$nextToken]['code']
351354
&& T_WHITESPACE === $tokens[$nextToken - 1]['code']
352355
) {
353356
if ($tokens[$nextToken - 1]['content'] === $phpcsFile->eolChar) {

SymfonyCustom/Sniffs/Commenting/DocCommentSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public function process(File $phpcsFile, $stackPtr): void
3131
{
3232
$tokens = $phpcsFile->getTokens();
3333

34-
if (!isset($tokens[$stackPtr]['comment_closer'])
34+
if (
35+
!isset($tokens[$stackPtr]['comment_closer'])
3536
|| ('' === $tokens[$tokens[$stackPtr]['comment_closer']]['content']
3637
&& $phpcsFile->numTokens - 1 === $tokens[$stackPtr]['comment_closer'])
3738
) {

SymfonyCustom/Sniffs/Commenting/VariableCommentSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public function processMemberVar(File $phpcsFile, $stackPtr): void
3232
];
3333

3434
$commentEnd = $phpcsFile->findPrevious($ignore, $stackPtr - 1, null, true);
35-
if (false === $commentEnd
35+
if (
36+
false === $commentEnd
3637
|| (T_DOC_COMMENT_CLOSE_TAG !== $tokens[$commentEnd]['code']
3738
&& T_COMMENT !== $tokens[$commentEnd]['code'])
3839
) {

SymfonyCustom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public function process(File $phpcsFile, $stackPtr): void
6767
if ($fix) {
6868
$phpcsFile->fixer->beginChangeset();
6969
$i = 1;
70-
while (T_WHITESPACE === $tokens[$stackPtr - $i]['code']
70+
while (
71+
T_WHITESPACE === $tokens[$stackPtr - $i]['code']
7172
|| $this->isComment($tokens[$stackPtr - $i])
7273
) {
7374
$i++;

SymfonyCustom/Sniffs/Formatting/ConditionalReturnOrThrowSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public function process(File $phpcsFile, $stackPtr): void
3131
$tokens = $phpcsFile->getTokens();
3232
$opener = $phpcsFile->findPrevious([T_IF, T_CASE], $stackPtr);
3333

34-
if (false !== $opener
34+
if (
35+
false !== $opener
3536
&& isset($tokens[$opener]['scope_closer'])
3637
&& $stackPtr <= $tokens[$opener]['scope_closer']
3738
) {

SymfonyCustom/Sniffs/Formatting/YodaConditionSniff.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ public function process(File $phpcsFile, $stackPtr): void
5454
}
5555

5656
// If this is a function call or something, we are OK.
57-
if (in_array(
58-
$tokens[$i]['code'],
59-
[T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS, T_OPEN_PARENTHESIS, T_RETURN],
60-
true
61-
)
57+
if (
58+
in_array(
59+
$tokens[$i]['code'],
60+
[T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS, T_OPEN_PARENTHESIS, T_RETURN],
61+
true
62+
)
6263
) {
6364
return;
6465
}

SymfonyCustom/Sniffs/Functions/ScopeOrderSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public function process(File $phpcsFile, $stackPtr): void
6363
$tokens[$function]['parenthesis_opener']
6464
);
6565

66-
if ($scope
66+
if (
67+
$scope
6768
&& $name
6869
&& !in_array(
6970
$tokens[$name]['content'],

SymfonyCustom/Sniffs/Namespaces/AlphabeticallySortedUseSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ private function getUseStatements(File $phpcsFile, int $scopePtr): array
9090

9191
$use = $phpcsFile->findNext(T_USE, $start + 1, $end);
9292
while (false !== $use && T_USE === $tokens[$use]['code']) {
93-
if (!SniffHelper::isGlobalUse($phpcsFile, $use)
93+
if (
94+
!SniffHelper::isGlobalUse($phpcsFile, $use)
9495
|| (null !== $end
9596
&& (!isset($tokens[$use]['conditions'][$scopePtr])
9697
|| $tokens[$use]['level'] !== $tokens[$scopePtr]['level'] + 1))

SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public function process(File $phpcsFile, $stackPtr): void
5555
}
5656

5757
$comma = $phpcsFile->findNext(T_COMMA, $from + 1, $to);
58-
if (false === $comma
58+
if (
59+
false === $comma
5960
|| !$phpcsFile->findNext(Tokens::$emptyTokens, $comma + 1, $to, true)
6061
) {
6162
$fix = $phpcsFile->addFixableError(
@@ -159,7 +160,8 @@ public function process(File $phpcsFile, $stackPtr): void
159160
$from = $stackPtr;
160161
} else {
161162
$from = $phpcsFile->findNext(Tokens::$emptyTokens, $prev + 1, null, true);
162-
if (T_STRING === $tokens[$from]['code']
163+
if (
164+
T_STRING === $tokens[$from]['code']
163165
&& in_array(strtolower($tokens[$from]['content']), ['const', 'function'], true)
164166
) {
165167
$from = $phpcsFile->findNext(Tokens::$emptyTokens, $from + 1, null, true);
@@ -192,7 +194,8 @@ private function removeUse(File $phpcsFile, int $from, int $to): void
192194
$phpcsFile->fixer->beginChangeset();
193195

194196
// Remote whitespaces before in the same line
195-
if (T_WHITESPACE === $tokens[$from - 1]['code']
197+
if (
198+
T_WHITESPACE === $tokens[$from - 1]['code']
196199
&& $tokens[$from - 1]['line'] === $tokens[$from]['line']
197200
&& $tokens[$from - 2]['line'] !== $tokens[$from]['line']
198201
) {
@@ -243,7 +246,8 @@ private function isClassUsed(File $phpcsFile, int $usePtr, int $classPtr): bool
243246

244247
$type = 'class';
245248
$next = $phpcsFile->findNext(Tokens::$emptyTokens, $usePtr + 1, null, true);
246-
if (T_STRING === $tokens[$next]['code']
249+
if (
250+
T_STRING === $tokens[$next]['code']
247251
&& in_array(strtolower($tokens[$next]['content']), ['const', 'function'], true)
248252
) {
249253
$type = strtolower($tokens[$next]['content']);
@@ -309,7 +313,8 @@ private function isClassUsed(File $phpcsFile, int $usePtr, int $classPtr): bool
309313

310314
$match = null;
311315

312-
if (($isStringToken
316+
if (
317+
($isStringToken
313318
&& (('const' !== $type && strtolower($tokens[$classUsed]['content']) === $searchName)
314319
|| ('const' === $type && $tokens[$classUsed]['content'] === $searchName)))
315320
|| ('class' === $type
@@ -346,7 +351,8 @@ private function isClassUsed(File $phpcsFile, int $usePtr, int $classPtr): bool
346351
return true;
347352
}
348353
} elseif (T_DOC_COMMENT_STRING === $tokens[$classUsed]['code']) {
349-
if (T_DOC_COMMENT_TAG === $tokens[$beforeUsage]['code']
354+
if (
355+
T_DOC_COMMENT_TAG === $tokens[$beforeUsage]['code']
350356
&& in_array($tokens[$beforeUsage]['content'], SniffHelper::TAGS_WITH_TYPE, true)
351357
) {
352358
return true;
@@ -406,19 +412,23 @@ private function determineType(File $phpcsFile, int $beforePtr, int $ptr): ?stri
406412

407413
$beforeCode = $tokens[$beforePtr]['code'];
408414

409-
if (in_array(
410-
$beforeCode,
411-
[T_NS_SEPARATOR, T_OBJECT_OPERATOR, T_DOUBLE_COLON, T_FUNCTION, T_CONST, T_AS, T_INSTEADOF],
412-
true
413-
)) {
415+
if (
416+
in_array(
417+
$beforeCode,
418+
[T_NS_SEPARATOR, T_OBJECT_OPERATOR, T_DOUBLE_COLON, T_FUNCTION, T_CONST, T_AS, T_INSTEADOF],
419+
true
420+
)
421+
) {
414422
return null;
415423
}
416424

417-
if (in_array(
418-
$beforeCode,
419-
[T_NEW, T_NULLABLE, T_EXTENDS, T_IMPLEMENTS, T_INSTANCEOF],
420-
true
421-
)) {
425+
if (
426+
in_array(
427+
$beforeCode,
428+
[T_NEW, T_NULLABLE, T_EXTENDS, T_IMPLEMENTS, T_INSTANCEOF],
429+
true
430+
)
431+
) {
422432
return 'class';
423433
}
424434

@@ -459,17 +469,20 @@ private function determineType(File $phpcsFile, int $beforePtr, int $ptr): ?stri
459469
return 'function';
460470
}
461471

462-
if (in_array(
463-
$afterCode,
464-
[T_DOUBLE_COLON, T_VARIABLE, T_ELLIPSIS, T_NS_SEPARATOR, T_OPEN_CURLY_BRACKET],
465-
true
466-
)) {
472+
if (
473+
in_array(
474+
$afterCode,
475+
[T_DOUBLE_COLON, T_VARIABLE, T_ELLIPSIS, T_NS_SEPARATOR, T_OPEN_CURLY_BRACKET],
476+
true
477+
)
478+
) {
467479
return 'class';
468480
}
469481

470482
if (T_COLON === $beforeCode) {
471483
$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, $beforePtr - 1, null, true);
472-
if (false !== $prev
484+
if (
485+
false !== $prev
473486
&& T_CLOSE_PARENTHESIS === $tokens[$prev]['code']
474487
&& isset($tokens[$prev]['parenthesis_owner'])
475488
&& T_FUNCTION === $tokens[$tokens[$prev]['parenthesis_owner']]['code']

SymfonyCustom/Sniffs/WhiteSpace/DocCommentTagSpacingSniff.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public function process(File $phpcsFile, $stackPtr): void
3131
{
3232
$tokens = $phpcsFile->getTokens();
3333

34-
if (isset($tokens[$stackPtr - 1])
34+
if (
35+
isset($tokens[$stackPtr - 1])
3536
&& $tokens[$stackPtr]['line'] === $tokens[$stackPtr - 1]['line']
3637
) {
3738
if (T_DOC_COMMENT_WHITESPACE !== $tokens[$stackPtr - 1]['code']) {
@@ -66,7 +67,8 @@ public function process(File $phpcsFile, $stackPtr): void
6667
}
6768
}
6869

69-
if (isset($tokens[$stackPtr + 1])
70+
if (
71+
isset($tokens[$stackPtr + 1])
7072
&& $tokens[$stackPtr]['line'] === $tokens[$stackPtr + 1]['line']
7173
&& T_DOC_COMMENT_WHITESPACE === $tokens[$stackPtr + 1]['code']
7274
&& 1 < $tokens[$stackPtr + 1]['length']

0 commit comments

Comments
 (0)