Skip to content
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

Remove deprecation layer #96

Merged
merged 1 commit into from
Dec 11, 2022
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
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ awareness about deprecated code.
- Use of our low-overhead runtime deprecation API, details:
https://github.com/doctrine/deprecations/

# Upgrade to 3.0.0

`Doctrine\Common\Lexer\Token` no longer implements `ArrayAccess`.

# Upgrade to 2.0.0

`AbstractLexer::glimpse()` and `AbstractLexer::peek()` now return
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
],
"homepage": "https://www.doctrine-project.org/projects/lexer.html",
"require": {
"php": "^7.1 || ^8.0",
"doctrine/deprecations": "^1.0"
"php": "^7.1 || ^8.0"
},
"require-dev": {
"doctrine/coding-standard": "^9 || ^10",
Expand Down
79 changes: 2 additions & 77 deletions src/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@

namespace Doctrine\Common\Lexer;

use ArrayAccess;
use Doctrine\Deprecations\Deprecation;
use ReturnTypeWillChange;
use UnitEnum;

use function in_array;

/**
* @template T of UnitEnum|string|int
* @implements ArrayAccess<string,mixed>
*/
final class Token implements ArrayAccess
/** @template T of UnitEnum|string|int */
final class Token
{
/**
* The string value of the token in the input string
Expand Down Expand Up @@ -57,73 +51,4 @@ 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}
*
* @param array-key $offset
*
* @return mixed
*/
#[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;
}
}
12 changes: 6 additions & 6 deletions tests/AbstractLexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ public function testPeek(string $input, array $expectedTokens): void
$actualToken = $this->concreteLexer->peek();
assert($actualToken !== null);
$this->assertEquals($expectedToken, $actualToken);
$this->assertSame($expectedToken['value'], $actualToken['value']);
$this->assertSame($expectedToken['type'], $actualToken['type']);
$this->assertSame($expectedToken['position'], $actualToken['position']);
$this->assertSame($expectedToken->value, $actualToken->value);
$this->assertSame($expectedToken->type, $actualToken->type);
$this->assertSame($expectedToken->position, $actualToken->position);
}

$this->assertNull($this->concreteLexer->peek());
Expand All @@ -163,9 +163,9 @@ public function testGlimpse(string $input, array $expectedTokens): void
assert($actualToken !== null);
$this->assertEquals($expectedToken, $actualToken);
$this->assertEquals($expectedToken, $this->concreteLexer->glimpse());
$this->assertSame($expectedToken['value'], $actualToken['value']);
$this->assertSame($expectedToken['type'], $actualToken['type']);
$this->assertSame($expectedToken['position'], $actualToken['position']);
$this->assertSame($expectedToken->value, $actualToken->value);
$this->assertSame($expectedToken->type, $actualToken->type);
$this->assertSame($expectedToken->position, $actualToken->position);
$this->concreteLexer->moveNext();
}

Expand Down
33 changes: 0 additions & 33 deletions tests/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
namespace Doctrine\Tests\Common\Lexer;

use Doctrine\Common\Lexer\Token;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use PHPUnit\Framework\TestCase;

final class TokenTest extends TestCase
{
use VerifyDeprecations;

public function testIsA(): void
{
/** @var Token<'string'|'int'> $token */
Expand All @@ -21,34 +18,4 @@ public function testIsA(): void
self::assertTrue($token->isA('int', 'string'));
self::assertFalse($token->isA('int'));
}

public function testOffsetGetIsDeprecated(): void
{
$token = new Token('foo', 'string', 1);
self::expectDeprecationWithIdentifier('https://github.com/doctrine/lexer/pull/79');
self::assertSame('foo', $token['value']);
}

public function testOffsetExistsIsDeprecated(): void
{
$token = new Token('foo', 'string', 1);
self::expectDeprecationWithIdentifier('https://github.com/doctrine/lexer/pull/79');
self::assertTrue(isset($token['value']));
}

public function testOffsetSetIsDeprecated(): void
{
$token = new Token('foo', 'string', 1);
self::expectDeprecationWithIdentifier('https://github.com/doctrine/lexer/pull/79');
$token['value'] = 'bar';
self::assertSame('bar', $token->value);
}

public function testOffsetUnsetIsDeprecated(): void
{
$token = new Token('foo', 'string', 1);
self::expectDeprecationWithIdentifier('https://github.com/doctrine/lexer/pull/79');
unset($token['value']);
self::assertNull($token->value);
}
}