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
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 @@ -520,6 +521,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