-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace object-like array with class #79
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn’t this be inA() ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi mate! No it's |
||
{ | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although no BC-layer will be provided, implementing
ArrayAccess
should allow to easily make dependent packages compatible with lexer 1 and 2 at the same time.