Skip to content

Commit 50a5486

Browse files
authored
Remove MyCLabs\Enum support (#727) (#794)
PHP 8.1 native enums are the standard going forward. Security support for PHP 8.0 has long passed and ends for 8.1 at the end of this year, so there is no reason to continue supporting the myclabs/php-enum library. - Delete MyCLabsEnumTypeMapper, MyCLabsEnumType and the @EnumType annotation - Drop the MyCLabsEnumTypeMapper wiring from SchemaFactory and test harnesses - Remove the getEnumTypeAnnotation() helper from AnnotationReader - Drop myclabs/php-enum from require-dev - Convert TestEnum and ProductTypeEnum fixtures to native backed enums - Prune MyCLabs docs from current website/docs/ (versioned docs kept intact)
1 parent d86d694 commit 50a5486

19 files changed

+23
-445
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"doctrine/coding-standard": "^13.0",
3232
"ecodev/graphql-upload": "^7.0",
3333
"laminas/laminas-diactoros": "^3.5",
34-
"myclabs/php-enum": "^1.6.6",
3534
"php-coveralls/php-coveralls": "^2.7",
3635
"phpstan/extension-installer": "^1.4",
3736
"phpstan/phpstan": "^2.0",

src/AnnotationReader.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use ReflectionProperty;
1111
use TheCodingMachine\GraphQLite\Annotations\AbstractRequest;
1212
use TheCodingMachine\GraphQLite\Annotations\Decorate;
13-
use TheCodingMachine\GraphQLite\Annotations\EnumType;
1413
use TheCodingMachine\GraphQLite\Annotations\Exceptions\ClassNotFoundException;
1514
use TheCodingMachine\GraphQLite\Annotations\Exceptions\InvalidParameterException;
1615
use TheCodingMachine\GraphQLite\Annotations\ExtendType;
@@ -196,11 +195,6 @@ public function getExtendTypeAnnotation(ReflectionClass $refClass): ExtendType|n
196195
return $extendType;
197196
}
198197

199-
public function getEnumTypeAnnotation(ReflectionClass $refClass): EnumType|null
200-
{
201-
return $this->getClassAnnotation($refClass, EnumType::class);
202-
}
203-
204198
/** @param class-string<AbstractRequest> $annotationClass */
205199
public function getRequestAnnotation(ReflectionMethod $refMethod, string $annotationClass): AbstractRequest|null
206200
{

src/Annotations/EnumType.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/Mappers/Root/EnumTypeMapper.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use GraphQL\Type\Definition\NamedType;
99
use GraphQL\Type\Definition\OutputType;
1010
use GraphQL\Type\Definition\Type as GraphQLType;
11-
use MyCLabs\Enum\Enum;
1211
use phpDocumentor\Reflection\DocBlock;
1312
use phpDocumentor\Reflection\Type;
1413
use phpDocumentor\Reflection\Types\Object_;
@@ -104,16 +103,12 @@ private function mapByClassName(string $enumClass): EnumType|null
104103
if (! enum_exists($enumClass)) {
105104
return null;
106105
}
107-
/** @var class-string<Enum> $enumClass */
106+
/** @var class-string<UnitEnum> $enumClass */
108107
$enumClass = ltrim($enumClass, '\\');
109108
if (isset($this->cacheByClass[$enumClass])) {
110109
return $this->cacheByClass[$enumClass];
111110
}
112111

113-
// phpcs:disable SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
114-
/** @var class-string<UnitEnum> $enumClass */
115-
// phpcs:enable SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
116-
117112
$reflectionEnum = new ReflectionEnum($enumClass);
118113

119114
$typeAnnotation = $this->annotationReader->getTypeAnnotation($reflectionEnum);

src/Mappers/Root/MyCLabsEnumTypeMapper.php

Lines changed: 0 additions & 174 deletions
This file was deleted.

src/SchemaFactory.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Kcs\ClassFinder\FileFinder\DefaultFileFinder;
1010
use Kcs\ClassFinder\Finder\ComposerFinder;
1111
use Kcs\ClassFinder\Finder\FinderInterface;
12-
use MyCLabs\Enum\Enum;
1312
use PackageVersions\Versions;
1413
use Psr\Container\ContainerInterface;
1514
use Psr\SimpleCache\CacheInterface;
@@ -41,7 +40,6 @@
4140
use TheCodingMachine\GraphQLite\Mappers\Root\FinalRootTypeMapper;
4241
use TheCodingMachine\GraphQLite\Mappers\Root\IteratorTypeMapper;
4342
use TheCodingMachine\GraphQLite\Mappers\Root\LastDelegatingTypeMapper;
44-
use TheCodingMachine\GraphQLite\Mappers\Root\MyCLabsEnumTypeMapper;
4543
use TheCodingMachine\GraphQLite\Mappers\Root\NullableTypeMapperAdapter;
4644
use TheCodingMachine\GraphQLite\Mappers\Root\RootTypeMapperFactoryContext;
4745
use TheCodingMachine\GraphQLite\Mappers\Root\RootTypeMapperFactoryInterface;
@@ -70,7 +68,6 @@
7068
use TheCodingMachine\GraphQLite\Utils\NamespacedCache;
7169

7270
use function array_reverse;
73-
use function class_exists;
7471
use function implode;
7572
use function md5;
7673
use function substr;
@@ -406,11 +403,6 @@ public function createSchema(): Schema
406403
$rootTypeMapper = new BaseTypeMapper($errorRootTypeMapper, $recursiveTypeMapper, $topRootTypeMapper);
407404
$rootTypeMapper = new EnumTypeMapper($rootTypeMapper, $annotationReader, $docBlockFactory, $classFinder, $classFinderComputedCache);
408405

409-
if (class_exists(Enum::class)) {
410-
// Annotation support - deprecated
411-
$rootTypeMapper = new MyCLabsEnumTypeMapper($rootTypeMapper, $annotationReader, $classFinder, $classFinderComputedCache);
412-
}
413-
414406
if (! empty($this->rootTypeMapperFactories)) {
415407
$rootSchemaFactoryContext = new RootTypeMapperFactoryContext(
416408
$annotationReader,

src/Types/MyCLabsEnumType.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/AbstractQueryProvider.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
use TheCodingMachine\GraphQLite\Mappers\Root\FinalRootTypeMapper;
4848
use TheCodingMachine\GraphQLite\Mappers\Root\IteratorTypeMapper;
4949
use TheCodingMachine\GraphQLite\Mappers\Root\LastDelegatingTypeMapper;
50-
use TheCodingMachine\GraphQLite\Mappers\Root\MyCLabsEnumTypeMapper;
5150
use TheCodingMachine\GraphQLite\Mappers\Root\NullableTypeMapperAdapter;
5251
use TheCodingMachine\GraphQLite\Mappers\Root\RootTypeMapperInterface;
5352
use TheCodingMachine\GraphQLite\Mappers\Root\VoidTypeMapper;
@@ -369,14 +368,6 @@ protected function buildRootTypeMapper(): RootTypeMapperInterface
369368
$topRootTypeMapper,
370369
);
371370

372-
// Annotation support - deprecated
373-
$rootTypeMapper = new MyCLabsEnumTypeMapper(
374-
$rootTypeMapper,
375-
$this->getAnnotationReader(),
376-
new StaticClassFinder([]),
377-
new HardClassFinderComputedCache(new Psr16Cache($arrayAdapter)),
378-
);
379-
380371
$rootTypeMapper = new EnumTypeMapper(
381372
$rootTypeMapper,
382373
$this->getAnnotationReader(),

tests/FieldsBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function testQueryProvider(): void
124124
'dateTimeImmutable' => '2017-01-01 01:01:01',
125125
'dateTime' => '2017-01-01 01:01:01',
126126
'id' => 42,
127-
'enum' => TestEnum::ON(),
127+
'enum' => TestEnum::ON,
128128
];
129129

130130
$resolve = $usersQuery->resolveFn;

0 commit comments

Comments
 (0)