|
@@ -80,13 +80,6 @@ class Tokens extends \SplFixedArray
|
|
|
*/
|
|
|
private $foundTokenKinds = [];
|
|
|
|
|
|
- /**
|
|
|
- * @var bool
|
|
|
- *
|
|
|
- * @todo remove at 3.0
|
|
|
- */
|
|
|
- private static $isLegacyMode = false;
|
|
|
-
|
|
|
/**
|
|
|
* Clone tokens collection.
|
|
|
*/
|
|
@@ -97,34 +90,6 @@ class Tokens extends \SplFixedArray
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return bool
|
|
|
- *
|
|
|
- * @internal
|
|
|
- *
|
|
|
- * @todo remove at 3.0
|
|
|
- */
|
|
|
- public static function isLegacyMode()
|
|
|
- {
|
|
|
- return self::$isLegacyMode;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param bool $isLegacy
|
|
|
- *
|
|
|
- * @internal
|
|
|
- *
|
|
|
- * @todo remove at 3.0
|
|
|
- */
|
|
|
- public static function setLegacyMode($isLegacy)
|
|
|
- {
|
|
|
- if (getenv('PHP_CS_FIXER_FUTURE_MODE') && $isLegacy) {
|
|
|
- throw new \RuntimeException('Cannot enable `legacy mode` when using `future mode`. This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.');
|
|
|
- }
|
|
|
-
|
|
|
- self::$isLegacyMode = $isLegacy;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Clear cache - one position or all of them.
|
|
|
*
|
|
@@ -328,12 +293,6 @@ class Tokens extends \SplFixedArray
|
|
|
public function clearChanged()
|
|
|
{
|
|
|
$this->changed = false;
|
|
|
-
|
|
|
- if (self::isLegacyMode()) {
|
|
|
- foreach ($this as $token) {
|
|
|
- $token->clearChanged();
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -446,7 +405,7 @@ class Tokens extends \SplFixedArray
|
|
|
throw new \InvalidArgumentException(sprintf('Invalid param type: %s.', $type));
|
|
|
}
|
|
|
|
|
|
- if (!self::isLegacyMode() && isset($this->blockEndCache[$searchIndex])) {
|
|
|
+ if (isset($this->blockEndCache[$searchIndex])) {
|
|
|
return $this->blockEndCache[$searchIndex];
|
|
|
}
|
|
|
|
|
@@ -519,11 +478,9 @@ class Tokens extends \SplFixedArray
|
|
|
$elements[$kind] = [];
|
|
|
}
|
|
|
|
|
|
- if (!self::isLegacyMode()) {
|
|
|
- $possibleKinds = array_filter($possibleKinds, function ($kind) {
|
|
|
- return $this->isTokenKindFound($kind);
|
|
|
- });
|
|
|
- }
|
|
|
+ $possibleKinds = array_filter($possibleKinds, function ($kind) {
|
|
|
+ return $this->isTokenKindFound($kind);
|
|
|
+ });
|
|
|
|
|
|
if (count($possibleKinds)) {
|
|
|
for ($i = $start; $i < $end; ++$i) {
|
|
@@ -676,11 +633,9 @@ class Tokens extends \SplFixedArray
|
|
|
*/
|
|
|
public function getTokenOfKindSibling($index, $direction, array $tokens = [], $caseSensitive = true)
|
|
|
{
|
|
|
- if (!self::isLegacyMode()) {
|
|
|
- $tokens = array_filter($tokens, function ($token) {
|
|
|
- return $this->isTokenKindFound($this->extractTokenKind($token));
|
|
|
- });
|
|
|
- }
|
|
|
+ $tokens = array_filter($tokens, function ($token) {
|
|
|
+ return $this->isTokenKindFound($this->extractTokenKind($token));
|
|
|
+ });
|
|
|
|
|
|
if (!count($tokens)) {
|
|
|
return null;
|
|
@@ -838,11 +793,9 @@ class Tokens extends \SplFixedArray
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!self::isLegacyMode()) {
|
|
|
- foreach ($sequence as $token) {
|
|
|
- if (!$this->isTokenKindFound($this->extractTokenKind($token))) {
|
|
|
- return null;
|
|
|
- }
|
|
|
+ foreach ($sequence as $token) {
|
|
|
+ if (!$this->isTokenKindFound($this->extractTokenKind($token))) {
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -938,14 +891,6 @@ class Tokens extends \SplFixedArray
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- if (self::isLegacyMode()) {
|
|
|
- foreach ($this as $token) {
|
|
|
- if ($token->isChanged()) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -966,23 +911,6 @@ class Tokens extends \SplFixedArray
|
|
|
$this[$index] = new Token('');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Override token at given index and register it.
|
|
|
- *
|
|
|
- * @param int $index
|
|
|
- * @param array|string|Token $token token prototype
|
|
|
- *
|
|
|
- * @deprecated since 2.4, use offsetSet instead
|
|
|
- */
|
|
|
- public function overrideAt($index, $token)
|
|
|
- {
|
|
|
- @trigger_error(__METHOD__.' is deprecated and will be removed in 3.0, use offsetSet instead.', E_USER_DEPRECATED);
|
|
|
- self::$isLegacyMode = true;
|
|
|
-
|
|
|
- $this[$index]->override($token);
|
|
|
- $this->registerFoundToken($token);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Override tokens at given range.
|
|
|
*
|
|
@@ -1165,10 +1093,6 @@ class Tokens extends \SplFixedArray
|
|
|
*/
|
|
|
public function countTokenKind($tokenKind)
|
|
|
{
|
|
|
- if (self::isLegacyMode()) {
|
|
|
- throw new \RuntimeException(sprintf('%s is not available in legacy mode.', __METHOD__));
|
|
|
- }
|
|
|
-
|
|
|
return isset($this->foundTokenKinds[$tokenKind]) ? $this->foundTokenKinds[$tokenKind] : 0;
|
|
|
}
|
|
|
|
|
@@ -1201,21 +1125,6 @@ class Tokens extends \SplFixedArray
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if (self::isLegacyMode()) {
|
|
|
- // If code is not monolithic there is a great chance that first or last token is `T_INLINE_HTML`:
|
|
|
- if ($this[0]->isGivenKind(T_INLINE_HTML) || $this[$size - 1]->isGivenKind(T_INLINE_HTML)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- for ($index = 1; $index < $size; ++$index) {
|
|
|
- if ($this[$index]->isGivenKind([T_INLINE_HTML, T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
if ($this->isTokenKindFound(T_INLINE_HTML)) {
|
|
|
return false;
|
|
|
}
|