Skip to content

Commit

Permalink
Merge pull request #96 from greg0ire/remove-deprecation-layer
Browse files Browse the repository at this point in the history
Remove deprecation layer
  • Loading branch information
greg0ire authored Dec 11, 2022
2 parents 3cf140b + 8a82888 commit e6d6599
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 118 deletions.
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);
}
}

0 comments on commit e6d6599

Please sign in to comment.