-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace object-like array with class
The new class is templatable, which should enable us to specify that the ORM Lexer is an Lexer<self::T_*>, and in the future, define an enum called TokenType in the ORM, and switch to Lexer<TokenType>.
- Loading branch information
Showing
10 changed files
with
241 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Note about upgrading: Doctrine uses static and runtime mechanisms to raise | ||
awareness about deprecated code. | ||
|
||
- Use of `@deprecated` docblock that is detected by IDEs (like PHPStorm) or | ||
Static Analysis tools (like Psalm, phpstan) | ||
- Use of our low-overhead runtime deprecation API, details: | ||
https://github.com/doctrine/deprecations/ | ||
|
||
# Upgrade to 2.0.0 | ||
|
||
`AbstractLexer::glimpse()` and `AbstractLexer::peek()` now return | ||
instances of `Doctrine\Common\Lexer\Token`, which is an array-like class | ||
Using it as an array is deprecated in favor of using properties of that class. | ||
Using `count()` on it is deprecated with no replacement. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Common\Lexer; | ||
|
||
use ArrayAccess; | ||
use Doctrine\Deprecations\Deprecation; | ||
use ReturnTypeWillChange; | ||
|
||
use function in_array; | ||
|
||
/** | ||
* @template T of string|int | ||
* @implements ArrayAccess<string,mixed> | ||
*/ | ||
final class Token implements ArrayAccess | ||
{ | ||
/** | ||
* The string value of the token in the input string | ||
* | ||
* @readonly | ||
* @var string|int | ||
*/ | ||
public $value; | ||
|
||
/** | ||
* The type of the token (identifier, numeric, string, input parameter, none) | ||
* | ||
* @readonly | ||
* @var T|null | ||
*/ | ||
public $type; | ||
|
||
/** | ||
* The position of the token in the input string | ||
* | ||
* @readonly | ||
* @var int | ||
*/ | ||
public $position; | ||
|
||
/** | ||
* @param string|int $value | ||
* @param T|null $type | ||
*/ | ||
public function __construct($value, $type, int $position) | ||
{ | ||
$this->value = $value; | ||
$this->type = $type; | ||
$this->position = $position; | ||
} | ||
|
||
/** @param T ...$types */ | ||
public function isA(...$types): bool | ||
{ | ||
return in_array($this->type, $types, true); | ||
} | ||
|
||
/** | ||
* @deprecated Use the value, type or position property instead | ||
* {@inheritDoc} | ||
*/ | ||
public function offsetExists($offset): bool | ||
{ | ||
Deprecation::trigger( | ||
'doctrine/lexer', | ||
'https://github.com/doctrine/lexer/pull/79', | ||
'Accessing %s properties via ArrayAccess is deprecated, use the value, type or position property instead', | ||
self::class | ||
); | ||
|
||
return in_array($offset, ['value', 'type', 'position'], true); | ||
} | ||
|
||
/** | ||
* @deprecated Use the value, type or position property instead | ||
* {@inheritDoc} | ||
*/ | ||
#[ReturnTypeWillChange] | ||
public function offsetGet($offset) | ||
{ | ||
Deprecation::trigger( | ||
'doctrine/lexer', | ||
'https://github.com/doctrine/lexer/pull/79', | ||
'Accessing %s properties via ArrayAccess is deprecated, use the value, type or position property instead', | ||
self::class | ||
); | ||
|
||
return $this->$offset; | ||
} | ||
|
||
/** | ||
* @deprecated no replacement planned | ||
* {@inheritDoc} | ||
*/ | ||
public function offsetSet($offset, $value): void | ||
{ | ||
Deprecation::trigger( | ||
'doctrine/lexer', | ||
'https://github.com/doctrine/lexer/pull/79', | ||
'Setting %s properties via ArrayAccess is deprecated', | ||
self::class | ||
); | ||
|
||
$this->$offset = $value; | ||
} | ||
|
||
/** | ||
* @deprecated no replacement planned | ||
* {@inheritDoc} | ||
*/ | ||
public function offsetUnset($offset): void | ||
{ | ||
Deprecation::trigger( | ||
'doctrine/lexer', | ||
'https://github.com/doctrine/lexer/pull/79', | ||
'Setting %s properties via ArrayAccess is deprecated', | ||
self::class | ||
); | ||
|
||
$this->$offset = null; | ||
} | ||
} |
Oops, something went wrong.