Skip to content

Commit

Permalink
Merge 1510a86 into 567d785
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed May 10, 2024
2 parents 567d785 + 1510a86 commit 31f983b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 1 addition & 2 deletions PHPCSUtils/AbstractSniffs/AbstractArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ abstract class AbstractArrayDeclarationSniff implements Sniff
\T_DNUMBER => \T_DNUMBER,
\T_CONSTANT_ENCAPSED_STRING => \T_CONSTANT_ENCAPSED_STRING,
\T_STRING_CONCAT => \T_STRING_CONCAT,
\T_INLINE_THEN => \T_INLINE_THEN,
\T_INLINE_ELSE => \T_INLINE_ELSE,
\T_BOOLEAN_NOT => \T_BOOLEAN_NOT,
];

Expand All @@ -143,6 +141,7 @@ final public function __construct()
$this->acceptedTokens += Tokens::$castTokens;
$this->acceptedTokens += Tokens::$bracketTokens;
$this->acceptedTokens += Tokens::$heredocTokens;
$this->acceptedTokens += Collections::ternaryOperators();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions PHPCSUtils/Tokens/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
* declaration.
* @method static array shortArrayTokens() Tokens which are used for short arrays.
* @method static array shortListTokens() Tokens which are used for short lists.
* @method static array ternaryOperators() Tokens which represent ternary operators.
* @method static array textStringStartTokens() Tokens which can start a - potentially multi-line -
* text string.
*/
Expand Down Expand Up @@ -514,6 +515,18 @@ final class Collections
\T_CLOSE_SHORT_ARRAY => \T_CLOSE_SHORT_ARRAY,
];

/**
* Tokens which represent ternary operators.
*
* @since 1.1.0 Use the {@see Collections::ternaryOperators()} method for access.
*
* @var array<int|string, int|string>
*/
private static $ternaryOperators = [
\T_INLINE_THEN => \T_INLINE_THEN,
\T_INLINE_ELSE => \T_INLINE_ELSE,
];

/**
* Tokens which can start a - potentially multi-line - text string.
*
Expand Down
3 changes: 1 addition & 2 deletions PHPCSUtils/Utils/Operators.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ final class Operators
\T_OPEN_SHORT_ARRAY => true,
\T_OPEN_CURLY_BRACKET => true,
\T_COLON => true,
\T_INLINE_THEN => true,
\T_INLINE_ELSE => true,
\T_CASE => true,
\T_FN_ARROW => true,
\T_MATCH_ARROW => true,
Expand Down Expand Up @@ -206,6 +204,7 @@ public static function isUnaryPlusMinus(File $phpcsFile, $stackPtr)
|| isset(Tokens::$booleanOperators[$tokens[$prev]['code']]) === true
|| isset(Tokens::$assignmentTokens[$tokens[$prev]['code']]) === true
|| isset(Tokens::$castTokens[$tokens[$prev]['code']]) === true
|| isset(Collections::ternaryOperators()[$tokens[$prev]['code']]) === true
|| isset(self::$extraUnaryIndicators[$tokens[$prev]['code']]) === true
) {
return true;
Expand Down
1 change: 1 addition & 0 deletions Tests/Tokens/Collections/PropertyBasedTokenArraysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static function dataPropertyBasedTokenArrays()
'propertyModifierKeywords',
'shortArrayTokens',
'shortListTokens',
'ternaryOperators',
'textStringStartTokens',
];

Expand Down

0 comments on commit 31f983b

Please sign in to comment.