From de8aa9f4402c7e83a3575a6143eb26b45ea13461 Mon Sep 17 00:00:00 2001 From: Romain Canon Date: Thu, 15 Sep 2022 20:39:40 +0200 Subject: [PATCH] misc: remove unused code --- src/Type/Types/ArrayKeyType.php | 34 +----------------- tests/Unit/Type/Types/ArrayKeyTypeTest.php | 41 ---------------------- 2 files changed, 1 insertion(+), 74 deletions(-) diff --git a/src/Type/Types/ArrayKeyType.php b/src/Type/Types/ArrayKeyType.php index 107621e..5b765f7 100644 --- a/src/Type/Types/ArrayKeyType.php +++ b/src/Type/Types/ArrayKeyType.php @@ -5,15 +5,13 @@ declare(strict_types=1); namespace CuyZ\Valinor\Type\Types; use CuyZ\Valinor\Type\IntegerType; -use CuyZ\Valinor\Type\ScalarType; use CuyZ\Valinor\Type\StringType; use CuyZ\Valinor\Type\Type; -use CuyZ\Valinor\Type\Types\Exception\CannotCastValue; use function is_int; /** @internal */ -final class ArrayKeyType implements ScalarType +final class ArrayKeyType implements Type { private static self $integer; @@ -101,36 +99,6 @@ final class ArrayKeyType implements ScalarType return false; } - public function canCast($value): bool - { - foreach ($this->types as $type) { - if ($type->canCast($value)) { - return true; - } - } - - return false; - } - - /** - * @return int|string - */ - public function cast($value) - { - if ($this->accepts($value)) { - /** @var int|string $value */ - return $value; - } - - foreach ($this->types as $type) { - if ($type->canCast($value)) { - return $type->cast($value); - } - } - - throw new CannotCastValue($value, $this); - } - public function toString(): string { return $this->signature; diff --git a/tests/Unit/Type/Types/ArrayKeyTypeTest.php b/tests/Unit/Type/Types/ArrayKeyTypeTest.php index a8bdff4..f838812 100644 --- a/tests/Unit/Type/Types/ArrayKeyTypeTest.php +++ b/tests/Unit/Type/Types/ArrayKeyTypeTest.php @@ -6,7 +6,6 @@ namespace CuyZ\Valinor\Tests\Unit\Type\Types; use CuyZ\Valinor\Tests\Fake\Type\FakeType; use CuyZ\Valinor\Type\Types\ArrayKeyType; -use CuyZ\Valinor\Type\Types\Exception\CannotCastValue; use PHPUnit\Framework\TestCase; use stdClass; @@ -74,44 +73,4 @@ final class ArrayKeyTypeTest extends TestCase { self::assertFalse(ArrayKeyType::default()->matches(new FakeType())); } - - public function test_can_cast_correct_values(): void - { - $arrayKeyDefault = ArrayKeyType::default(); - $arrayKeyInteger = ArrayKeyType::integer(); - $arrayKeyString = ArrayKeyType::string(); - - self::assertTrue($arrayKeyDefault->canCast(42)); - self::assertTrue($arrayKeyDefault->canCast('foo')); - - self::assertTrue($arrayKeyInteger->canCast(42)); - self::assertFalse($arrayKeyInteger->canCast('foo')); - - self::assertTrue($arrayKeyString->canCast(42)); - self::assertTrue($arrayKeyString->canCast('foo')); - } - - public function test_cast_value_returns_correct_value(): void - { - $arrayKeyDefault = ArrayKeyType::default(); - $arrayKeyInteger = ArrayKeyType::integer(); - $arrayKeyString = ArrayKeyType::string(); - - self::assertSame(42, $arrayKeyDefault->cast(42)); - self::assertSame('foo', $arrayKeyDefault->cast('foo')); - - self::assertSame(42, $arrayKeyInteger->cast('42')); - - self::assertSame(42, $arrayKeyString->cast(42)); - self::assertSame('foo', $arrayKeyString->cast('foo')); - } - - public function test_cast_unsupported_value_throws_exception(): void - { - $this->expectException(CannotCastValue::class); - $this->expectExceptionCode(1603216198); - $this->expectExceptionMessage('Cannot cast object(stdClass) to `array-key`.'); - - ArrayKeyType::default()->cast(new stdClass()); - } }