We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 212 |
| Total Lines | 1018 |
| Duplicated Lines | 0 % |
| Coverage | 95.79% |
| Changes | 11 | ||
| Bugs | 1 | Features | 0 |
Complex classes like AnnotationParser often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AnnotationParser, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 48 | class AnnotationParser implements PreParserInterface |
||
| 49 | { |
||
| 50 | private static array $classesMap = []; |
||
| 51 | private static array $providers = []; |
||
| 52 | private static array $doctrineMapping = []; |
||
| 53 | private static array $graphClassCache = []; |
||
| 54 | |||
| 55 | private const GQL_SCALAR = 'scalar'; |
||
| 56 | private const GQL_ENUM = 'enum'; |
||
| 57 | private const GQL_TYPE = 'type'; |
||
| 58 | private const GQL_INPUT = 'input'; |
||
| 59 | private const GQL_UNION = 'union'; |
||
| 60 | private const GQL_INTERFACE = 'interface'; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @see https://facebook.github.io/graphql/draft/#sec-Input-and-Output-Types |
||
| 64 | */ |
||
| 65 | private const VALID_INPUT_TYPES = [self::GQL_SCALAR, self::GQL_ENUM, self::GQL_INPUT]; |
||
| 66 | private const VALID_OUTPUT_TYPES = [self::GQL_SCALAR, self::GQL_TYPE, self::GQL_INTERFACE, self::GQL_UNION, self::GQL_ENUM]; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * {@inheritdoc} |
||
| 70 | * |
||
| 71 | * @throws InvalidArgumentException |
||
| 72 | * @throws ReflectionException |
||
| 73 | */ |
||
| 74 | 25 | public static function preParse(SplFileInfo $file, ContainerBuilder $container, array $configs = []): void |
|
| 77 | 25 | } |
|
| 78 | |||
| 79 | /** |
||
| 80 | * @throws InvalidArgumentException |
||
| 81 | * @throws ReflectionException |
||
| 82 | */ |
||
| 83 | 25 | public static function parse(SplFileInfo $file, ContainerBuilder $container, array $configs = []): array |
|
| 84 | { |
||
| 85 | 25 | return self::processFile($file, $container, $configs, false); |
|
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @internal |
||
| 90 | */ |
||
| 91 | 63 | public static function reset(): void |
|
| 92 | { |
||
| 93 | 63 | self::$classesMap = []; |
|
| 94 | 63 | self::$providers = []; |
|
| 95 | 63 | self::$graphClassCache = []; |
|
| 96 | 63 | } |
|
| 97 | |||
| 98 | /** |
||
| 99 | * Process a file. |
||
| 100 | * |
||
| 101 | * @throws InvalidArgumentException|ReflectionException|AnnotationException |
||
| 102 | */ |
||
| 103 | 25 | private static function processFile(SplFileInfo $file, ContainerBuilder $container, array $configs, bool $preProcess): array |
|
| 104 | { |
||
| 105 | 25 | self::$doctrineMapping = $configs['doctrine']['types_mapping']; |
|
| 106 | 25 | $container->addResource(new FileResource($file->getRealPath())); |
|
| 107 | |||
| 108 | try { |
||
| 109 | 25 | $className = $file->getBasename('.php'); |
|
| 110 | 25 | if (preg_match('#namespace (.+);#', file_get_contents($file->getRealPath()), $matches)) { |
|
| 111 | 25 | $className = trim($matches[1]).'\\'.$className; |
|
| 112 | } |
||
| 113 | |||
| 114 | 25 | $gqlTypes = []; |
|
| 115 | 25 | $graphClass = self::getGraphClass($className); |
|
| 116 | |||
| 117 | 25 | foreach ($graphClass->getAnnotations() as $classAnnotation) { |
|
| 118 | 25 | $gqlTypes = self::classAnnotationsToGQLConfiguration( |
|
| 119 | 25 | $graphClass, |
|
| 120 | $classAnnotation, |
||
| 121 | $configs, |
||
| 122 | $gqlTypes, |
||
| 123 | $preProcess |
||
| 124 | ); |
||
| 125 | } |
||
| 126 | |||
| 127 | 25 | return $preProcess ? self::$classesMap : $gqlTypes; |
|
| 128 | 10 | } catch (\InvalidArgumentException $e) { |
|
| 129 | 10 | throw new InvalidArgumentException(sprintf('Failed to parse GraphQL annotations from file "%s".', $file), $e->getCode(), $e); |
|
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | 25 | private static function classAnnotationsToGQLConfiguration( |
|
| 134 | GraphClass $graphClass, |
||
| 135 | object $classAnnotation, |
||
| 136 | array $configs, |
||
| 137 | array $gqlTypes, |
||
| 138 | bool $preProcess |
||
| 139 | ): array { |
||
| 140 | 25 | $gqlConfiguration = $gqlType = $gqlName = null; |
|
| 141 | |||
| 142 | switch (true) { |
||
| 143 | 25 | case $classAnnotation instanceof GQL\Type: |
|
| 144 | 25 | $gqlType = self::GQL_TYPE; |
|
| 145 | 25 | $gqlName = $classAnnotation->name ?? $graphClass->getShortName(); |
|
| 146 | 25 | if (!$preProcess) { |
|
| 147 | 25 | $gqlConfiguration = self::typeAnnotationToGQLConfiguration($graphClass, $classAnnotation, $gqlName, $configs); |
|
| 148 | |||
| 149 | 25 | if ($classAnnotation instanceof GQL\Relay\Connection) { |
|
| 150 | 24 | if (!$graphClass->implementsInterface(ConnectionInterface::class)) { |
|
| 151 | throw new InvalidArgumentException(sprintf('The annotation @Connection on class "%s" can only be used on class implementing the ConnectionInterface.', $graphClass->getName())); |
||
| 152 | } |
||
| 153 | |||
| 154 | 24 | if (!(isset($classAnnotation->edge) xor isset($classAnnotation->node))) { |
|
| 155 | throw new InvalidArgumentException(sprintf('The annotation @Connection on class "%s" is invalid. You must define either the "edge" OR the "node" attribute, but not both.', $graphClass->getName())); |
||
| 156 | } |
||
| 157 | |||
| 158 | 24 | $edgeType = $classAnnotation->edge ?? false; |
|
| 159 | 24 | if (!$edgeType) { |
|
| 160 | 24 | $edgeType = $gqlName.'Edge'; |
|
| 161 | 24 | $gqlTypes[$edgeType] = [ |
|
| 162 | 24 | 'type' => 'object', |
|
| 163 | 'config' => [ |
||
| 164 | 'builders' => [ |
||
| 165 | 24 | ['builder' => 'relay-edge', 'builderConfig' => ['nodeType' => $classAnnotation->node]], |
|
| 166 | ], |
||
| 167 | ], |
||
| 168 | ]; |
||
| 169 | } |
||
| 170 | |||
| 171 | 24 | if (!isset($gqlConfiguration['config']['builders'])) { |
|
| 172 | 24 | $gqlConfiguration['config']['builders'] = []; |
|
| 173 | } |
||
| 174 | |||
| 175 | 24 | array_unshift($gqlConfiguration['config']['builders'], ['builder' => 'relay-connection', 'builderConfig' => ['edgeType' => $edgeType]]); |
|
| 176 | } |
||
| 177 | } |
||
| 178 | 25 | break; |
|
| 179 | |||
| 180 | 24 | case $classAnnotation instanceof GQL\Input: |
|
| 181 | 24 | $gqlType = self::GQL_INPUT; |
|
| 182 | 24 | $gqlName = $classAnnotation->name ?? self::suffixName($graphClass->getShortName(), 'Input'); |
|
| 183 | 24 | if (!$preProcess) { |
|
| 184 | 24 | $gqlConfiguration = self::inputAnnotationToGQLConfiguration($graphClass, $classAnnotation); |
|
| 185 | } |
||
| 186 | 24 | break; |
|
| 187 | |||
| 188 | 24 | case $classAnnotation instanceof GQL\Scalar: |
|
| 189 | 24 | $gqlType = self::GQL_SCALAR; |
|
| 190 | 24 | if (!$preProcess) { |
|
| 191 | 24 | $gqlConfiguration = self::scalarAnnotationToGQLConfiguration($graphClass, $classAnnotation); |
|
| 192 | } |
||
| 193 | 24 | break; |
|
| 194 | |||
| 195 | 24 | case $classAnnotation instanceof GQL\Enum: |
|
| 196 | 24 | $gqlType = self::GQL_ENUM; |
|
| 197 | 24 | if (!$preProcess) { |
|
| 198 | 24 | $gqlConfiguration = self::enumAnnotationToGQLConfiguration($graphClass, $classAnnotation); |
|
| 199 | } |
||
| 200 | 24 | break; |
|
| 201 | |||
| 202 | 24 | case $classAnnotation instanceof GQL\Union: |
|
| 203 | 24 | $gqlType = self::GQL_UNION; |
|
| 204 | 24 | if (!$preProcess) { |
|
| 205 | 24 | $gqlConfiguration = self::unionAnnotationToGQLConfiguration($graphClass, $classAnnotation); |
|
| 206 | } |
||
| 207 | 24 | break; |
|
| 208 | |||
| 209 | 24 | case $classAnnotation instanceof GQL\TypeInterface: |
|
| 210 | 24 | $gqlType = self::GQL_INTERFACE; |
|
| 211 | 24 | if (!$preProcess) { |
|
| 212 | 24 | $gqlConfiguration = self::typeInterfaceAnnotationToGQLConfiguration($graphClass, $classAnnotation); |
|
| 213 | } |
||
| 214 | 24 | break; |
|
| 215 | |||
| 216 | 24 | case $classAnnotation instanceof GQL\Provider: |
|
| 217 | 24 | if ($preProcess) { |
|
| 218 | 24 | self::$providers[] = ['metadata' => $graphClass, 'annotation' => $classAnnotation]; |
|
| 219 | } |
||
| 220 | |||
| 221 | 24 | return []; |
|
| 222 | } |
||
| 223 | |||
| 224 | 25 | if (null !== $gqlType) { |
|
| 225 | 25 | if (!$gqlName) { |
|
| 226 | 24 | $gqlName = isset($classAnnotation->name) ? $classAnnotation->name : $graphClass->getShortName(); |
|
| 227 | } |
||
| 228 | |||
| 229 | 25 | if ($preProcess) { |
|
| 230 | 25 | if (isset(self::$classesMap[$gqlName])) { |
|
| 231 | 1 | throw new InvalidArgumentException(sprintf('The GraphQL type "%s" has already been registered in class "%s"', $gqlName, self::$classesMap[$gqlName]['class'])); |
|
| 232 | } |
||
| 233 | 25 | self::$classesMap[$gqlName] = ['type' => $gqlType, 'class' => $graphClass->getName()]; |
|
| 234 | } else { |
||
| 235 | 25 | $gqlTypes = [$gqlName => $gqlConfiguration] + $gqlTypes; |
|
| 236 | } |
||
| 237 | } |
||
| 238 | |||
| 239 | 25 | return $gqlTypes; |
|
| 240 | } |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @throws ReflectionException |
||
| 244 | */ |
||
| 245 | 25 | private static function getGraphClass(string $className): GraphClass |
|
| 246 | { |
||
| 247 | 25 | self::$graphClassCache[$className] ??= new GraphClass($className); |
|
| 248 | |||
| 249 | 25 | return self::$graphClassCache[$className]; |
|
| 250 | } |
||
| 251 | |||
| 252 | 25 | private static function typeAnnotationToGQLConfiguration( |
|
| 253 | GraphClass $graphClass, |
||
| 254 | GQL\Type $classAnnotation, |
||
| 255 | string $gqlName, |
||
| 256 | array $configs |
||
| 257 | ): array { |
||
| 258 | 25 | $isMutation = $isDefault = $isRoot = false; |
|
| 259 | 25 | if (isset($configs['definitions']['schema'])) { |
|
| 260 | 24 | $defaultSchemaName = isset($configs['definitions']['schema']['default']) ? 'default' : array_key_first($configs['definitions']['schema']); |
|
| 261 | 24 | foreach ($configs['definitions']['schema'] as $schemaName => $schema) { |
|
| 262 | 24 | $schemaQuery = $schema['query'] ?? null; |
|
| 263 | 24 | $schemaMutation = $schema['mutation'] ?? null; |
|
| 264 | |||
| 265 | 24 | if ($gqlName === $schemaQuery) { |
|
| 266 | 24 | $isRoot = true; |
|
| 267 | 24 | if ($defaultSchemaName === $schemaName) { |
|
| 268 | 24 | $isDefault = true; |
|
| 269 | } |
||
| 270 | 24 | } elseif ($gqlName === $schemaMutation) { |
|
| 271 | 24 | $isMutation = true; |
|
| 272 | 24 | $isRoot = true; |
|
| 273 | 24 | if ($defaultSchemaName === $schemaName) { |
|
| 274 | 24 | $isDefault = true; |
|
| 275 | } |
||
| 276 | } |
||
| 277 | } |
||
| 278 | } |
||
| 279 | |||
| 280 | 25 | $currentValue = $isRoot ? sprintf("service('%s')", self::formatNamespaceForExpression($graphClass->getName())) : 'value'; |
|
| 281 | |||
| 282 | 25 | $gqlConfiguration = self::graphQLTypeConfigFromAnnotation($graphClass, $classAnnotation, $currentValue); |
|
| 283 | |||
| 284 | 25 | $providerFields = self::getGraphQLFieldsFromProviders($graphClass, $isMutation ? GQL\Mutation::class : GQL\Query::class, $gqlName, $isDefault); |
|
| 285 | 25 | $gqlConfiguration['config']['fields'] = array_merge($gqlConfiguration['config']['fields'], $providerFields); |
|
| 286 | |||
| 287 | 25 | if ($classAnnotation instanceof GQL\Relay\Edge) { |
|
| 288 | 24 | if (!$graphClass->implementsInterface(EdgeInterface::class)) { |
|
| 289 | throw new InvalidArgumentException(sprintf('The annotation @Edge on class "%s" can only be used on class implementing the EdgeInterface.', $graphClass->getName())); |
||
| 290 | } |
||
| 291 | 24 | if (!isset($gqlConfiguration['config']['builders'])) { |
|
| 292 | 24 | $gqlConfiguration['config']['builders'] = []; |
|
| 293 | } |
||
| 294 | 24 | array_unshift($gqlConfiguration['config']['builders'], ['builder' => 'relay-edge', 'builderConfig' => ['nodeType' => $classAnnotation->node]]); |
|
| 295 | } |
||
| 296 | |||
| 297 | 25 | return $gqlConfiguration; |
|
| 298 | } |
||
| 299 | |||
| 300 | 25 | private static function graphQLTypeConfigFromAnnotation(GraphClass $graphClass, GQL\Type $typeAnnotation, string $currentValue): array |
|
| 301 | { |
||
| 302 | 25 | $typeConfiguration = []; |
|
| 303 | 25 | $fieldsFromProperties = self::getGraphQLTypeFieldsFromAnnotations($graphClass, $graphClass->getPropertiesExtended(), GQL\Field::class, $currentValue); |
|
| 304 | 25 | $fieldsFromMethods = self::getGraphQLTypeFieldsFromAnnotations($graphClass, $graphClass->getMethods(), GQL\Field::class, $currentValue); |
|
| 305 | |||
| 306 | 25 | $typeConfiguration['fields'] = array_merge($fieldsFromProperties, $fieldsFromMethods); |
|
| 307 | 25 | $typeConfiguration = self::getDescriptionConfiguration($graphClass->getAnnotations()) + $typeConfiguration; |
|
| 308 | |||
| 309 | 25 | if (isset($typeAnnotation->interfaces)) { |
|
| 310 | 24 | $typeConfiguration['interfaces'] = $typeAnnotation->interfaces; |
|
| 311 | } else { |
||
| 312 | 25 | $interfaces = array_keys(self::searchClassesMapBy(function ($gqlType, $configuration) use ($graphClass) { |
|
| 313 | 24 | ['class' => $interfaceClassName] = $configuration; |
|
| 314 | |||
| 315 | 24 | $interfaceMetadata = self::getGraphClass($interfaceClassName); |
|
| 316 | 24 | if ($interfaceMetadata->isInterface() && $graphClass->implementsInterface($interfaceMetadata->getName())) { |
|
| 317 | 24 | return true; |
|
| 318 | } |
||
| 319 | |||
| 320 | 24 | return $graphClass->isSubclassOf($interfaceClassName); |
|
| 321 | 25 | }, self::GQL_INTERFACE)); |
|
| 322 | |||
| 323 | 25 | sort($interfaces); |
|
| 324 | 25 | $typeConfiguration['interfaces'] = $interfaces; |
|
| 325 | } |
||
| 326 | |||
| 327 | 25 | if (isset($typeAnnotation->resolveField)) { |
|
| 328 | 24 | $typeConfiguration['resolveField'] = self::formatExpression($typeAnnotation->resolveField); |
|
| 329 | } |
||
| 330 | |||
| 331 | 25 | if (isset($typeAnnotation->builders) && !empty($typeAnnotation->builders)) { |
|
| 332 | 24 | $typeConfiguration['builders'] = array_map(function ($fieldsBuilderAnnotation) { |
|
| 333 | 24 | return ['builder' => $fieldsBuilderAnnotation->builder, 'builderConfig' => $fieldsBuilderAnnotation->builderConfig]; |
|
| 334 | 24 | }, $typeAnnotation->builders); |
|
| 335 | } |
||
| 336 | |||
| 337 | 25 | if (isset($typeAnnotation->isTypeOf)) { |
|
| 338 | 24 | $typeConfiguration['isTypeOf'] = $typeAnnotation->isTypeOf; |
|
| 339 | } |
||
| 340 | |||
| 341 | 25 | $publicAnnotation = self::getFirstAnnotationMatching($graphClass->getAnnotations(), GQL\IsPublic::class); |
|
| 342 | 25 | if (null !== $publicAnnotation) { |
|
| 343 | 24 | $typeConfiguration['fieldsDefaultPublic'] = self::formatExpression($publicAnnotation->value); |
|
| 344 | } |
||
| 345 | |||
| 346 | 25 | $accessAnnotation = self::getFirstAnnotationMatching($graphClass->getAnnotations(), GQL\Access::class); |
|
| 347 | 25 | if (null !== $accessAnnotation) { |
|
| 348 | 24 | $typeConfiguration['fieldsDefaultAccess'] = self::formatExpression($accessAnnotation->value); |
|
| 349 | } |
||
| 350 | |||
| 351 | 25 | return ['type' => $typeAnnotation->isRelay ? 'relay-mutation-payload' : 'object', 'config' => $typeConfiguration]; |
|
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Create a GraphQL Interface type configuration from annotations on properties. |
||
| 356 | */ |
||
| 357 | 24 | private static function typeInterfaceAnnotationToGQLConfiguration(GraphClass $graphClass, GQL\TypeInterface $interfaceAnnotation): array |
|
| 358 | { |
||
| 359 | 24 | $interfaceConfiguration = []; |
|
| 360 | |||
| 361 | 24 | $fieldsFromProperties = self::getGraphQLTypeFieldsFromAnnotations($graphClass, $graphClass->getPropertiesExtended()); |
|
| 362 | 24 | $fieldsFromMethods = self::getGraphQLTypeFieldsFromAnnotations($graphClass, $graphClass->getMethods()); |
|
| 363 | |||
| 364 | 24 | $interfaceConfiguration['fields'] = array_merge($fieldsFromProperties, $fieldsFromMethods); |
|
| 365 | 24 | $interfaceConfiguration = self::getDescriptionConfiguration($graphClass->getAnnotations()) + $interfaceConfiguration; |
|
| 366 | |||
| 367 | 24 | $interfaceConfiguration['resolveType'] = self::formatExpression($interfaceAnnotation->resolveType); |
|
| 368 | |||
| 369 | 24 | return ['type' => 'interface', 'config' => $interfaceConfiguration]; |
|
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Create a GraphQL Input type configuration from annotations on properties. |
||
| 374 | */ |
||
| 375 | 24 | private static function inputAnnotationToGQLConfiguration(GraphClass $graphClass, GQL\Input $inputAnnotation): array |
|
| 376 | { |
||
| 377 | 24 | $inputConfiguration = array_merge([ |
|
| 378 | 24 | 'fields' => self::getGraphQLInputFieldsFromAnnotations($graphClass, $graphClass->getPropertiesExtended()), |
|
| 379 | 24 | ], self::getDescriptionConfiguration($graphClass->getAnnotations())); |
|
| 380 | |||
| 381 | 24 | return ['type' => $inputAnnotation->isRelay ? 'relay-mutation-input' : 'input-object', 'config' => $inputConfiguration]; |
|
| 382 | } |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Get a GraphQL scalar configuration from given scalar annotation. |
||
| 386 | */ |
||
| 387 | 24 | private static function scalarAnnotationToGQLConfiguration(GraphClass $graphClass, GQL\Scalar $scalarAnnotation): array |
|
| 388 | { |
||
| 389 | 24 | $scalarConfiguration = []; |
|
| 390 | |||
| 391 | 24 | if (isset($scalarAnnotation->scalarType)) { |
|
| 392 | 24 | $scalarConfiguration['scalarType'] = self::formatExpression($scalarAnnotation->scalarType); |
|
| 393 | } else { |
||
| 394 | $scalarConfiguration = [ |
||
| 395 | 24 | 'serialize' => [$graphClass->getName(), 'serialize'], |
|
| 396 | 24 | 'parseValue' => [$graphClass->getName(), 'parseValue'], |
|
| 397 | 24 | 'parseLiteral' => [$graphClass->getName(), 'parseLiteral'], |
|
| 398 | ]; |
||
| 399 | } |
||
| 400 | |||
| 401 | 24 | $scalarConfiguration = self::getDescriptionConfiguration($graphClass->getAnnotations()) + $scalarConfiguration; |
|
| 402 | |||
| 403 | 24 | return ['type' => 'custom-scalar', 'config' => $scalarConfiguration]; |
|
| 404 | } |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Get a GraphQL Enum configuration from given enum annotation. |
||
| 408 | */ |
||
| 409 | 24 | private static function enumAnnotationToGQLConfiguration(GraphClass $graphClass, GQL\Enum $enumAnnotation): array |
|
| 410 | { |
||
| 411 | 24 | $enumValues = $enumAnnotation->values ?? []; |
|
| 412 | |||
| 413 | 24 | $values = []; |
|
| 414 | |||
| 415 | 24 | foreach ($graphClass->getConstants() as $name => $value) { |
|
| 416 | 24 | $valueAnnotation = current(array_filter($enumValues, fn ($enumValueAnnotation) => $enumValueAnnotation->name == $name)); |
|
| 417 | 24 | $valueConfig = []; |
|
| 418 | 24 | $valueConfig['value'] = $value; |
|
| 419 | |||
| 420 | 24 | if ($valueAnnotation && isset($valueAnnotation->description)) { |
|
| 421 | 24 | $valueConfig['description'] = $valueAnnotation->description; |
|
| 422 | } |
||
| 423 | |||
| 424 | 24 | if ($valueAnnotation && isset($valueAnnotation->deprecationReason)) { |
|
| 425 | 24 | $valueConfig['deprecationReason'] = $valueAnnotation->deprecationReason; |
|
| 426 | } |
||
| 427 | |||
| 428 | 24 | $values[$name] = $valueConfig; |
|
| 429 | } |
||
| 430 | |||
| 431 | 24 | $enumConfiguration = ['values' => $values]; |
|
| 432 | 24 | $enumConfiguration = self::getDescriptionConfiguration($graphClass->getAnnotations()) + $enumConfiguration; |
|
| 433 | |||
| 434 | 24 | return ['type' => 'enum', 'config' => $enumConfiguration]; |
|
| 435 | } |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Get a GraphQL Union configuration from given union annotation. |
||
| 439 | */ |
||
| 440 | 24 | private static function unionAnnotationToGQLConfiguration(GraphClass $graphClass, GQL\Union $unionAnnotation): array |
|
| 478 | } |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @phpstan-param ReflectionMethod|ReflectionProperty $reflector |
||
| 482 | * @phpstan-param class-string<GQL\Field> $fieldAnnotationName |
||
| 483 | * |
||
| 484 | * @throws AnnotationException |
||
| 485 | */ |
||
| 486 | 24 | private static function getTypeFieldConfigurationFromReflector(GraphClass $graphClass, Reflector $reflector, string $fieldAnnotationName, string $currentValue = 'value'): array |
|
| 609 | } |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Create GraphQL input fields configuration based on annotations. |
||
| 613 | * |
||
| 614 | * @param ReflectionProperty[] $reflectors |
||
| 615 | * |
||
| 616 | * @throws AnnotationException |
||
| 617 | */ |
||
| 618 | 24 | private static function getGraphQLInputFieldsFromAnnotations(GraphClass $graphClass, array $reflectors): array |
|
| 619 | { |
||
| 620 | 24 | $fields = []; |
|
| 621 | |||
| 622 | 24 | foreach ($reflectors as $reflector) { |
|
| 623 | 24 | $annotations = $graphClass->getAnnotations($reflector); |
|
| 624 | |||
| 625 | /** @var GQL\Field|null $fieldAnnotation */ |
||
| 626 | 24 | $fieldAnnotation = self::getFirstAnnotationMatching($annotations, GQL\Field::class); |
|
| 627 | |||
| 628 | // No field annotation found |
||
| 629 | 24 | if (null === $fieldAnnotation) { |
|
| 630 | 24 | continue; |
|
| 631 | } |
||
| 632 | |||
| 633 | // Ignore field with resolver when the type is an Input |
||
| 634 | 24 | if (isset($fieldAnnotation->resolve)) { |
|
| 635 | return []; |
||
| 636 | } |
||
| 637 | |||
| 638 | 24 | $fieldName = $reflector->getName(); |
|
| 639 | 24 | if (isset($fieldAnnotation->type)) { |
|
| 640 | 24 | $fieldType = $fieldAnnotation->type; |
|
| 641 | } else { |
||
| 642 | try { |
||
| 643 | 24 | $fieldType = self::guessType($graphClass, $reflector, self::VALID_INPUT_TYPES); |
|
| 644 | } catch (Exception $e) { |
||
| 645 | throw new InvalidArgumentException(sprintf('The attribute "type" on GraphQL annotation "@%s" is missing on property "%s" and cannot be auto-guessed as there is no type hint or Doctrine annotation.', GQL\Field::class, $reflector->getName())); |
||
| 646 | } |
||
| 647 | } |
||
| 648 | 24 | $fieldConfiguration = []; |
|
| 649 | 24 | if ($fieldType) { |
|
| 650 | // Resolve a PHP class from a GraphQL type |
||
| 651 | 24 | $resolvedType = self::$classesMap[$fieldType] ?? null; |
|
| 652 | // We found a type but it is not allowed |
||
| 653 | 24 | if (null !== $resolvedType && !in_array($resolvedType['type'], self::VALID_INPUT_TYPES)) { |
|
| 654 | throw new InvalidArgumentException(sprintf('The type "%s" on "%s" is a "%s" not valid on an Input @Field. Only Input, Scalar and Enum are allowed.', $fieldType, $reflector->getName(), $resolvedType['type'])); |
||
| 655 | } |
||
| 656 | |||
| 657 | 24 | $fieldConfiguration['type'] = $fieldType; |
|
| 658 | } |
||
| 659 | |||
| 660 | 24 | $fieldConfiguration = array_merge(self::getDescriptionConfiguration($annotations, true), $fieldConfiguration); |
|
| 661 | 24 | $fields[$fieldName] = $fieldConfiguration; |
|
| 662 | } |
||
| 663 | |||
| 664 | 24 | return $fields; |
|
| 665 | } |
||
| 666 | |||
| 667 | /** |
||
| 668 | * Create GraphQL type fields configuration based on annotations. |
||
| 669 | * |
||
| 670 | * @phpstan-param class-string<GQL\Field> $fieldAnnotationName |
||
| 671 | * |
||
| 672 | * @param ReflectionProperty[]|ReflectionMethod[] $reflectors |
||
| 673 | * |
||
| 674 | * @throws AnnotationException |
||
| 675 | */ |
||
| 676 | 25 | private static function getGraphQLTypeFieldsFromAnnotations(GraphClass $graphClass, array $reflectors, string $fieldAnnotationName = GQL\Field::class, string $currentValue = 'value'): array |
|
| 685 | } |
||
| 686 | |||
| 687 | /** |
||
| 688 | * @phpstan-param class-string<GQL\Query|GQL\Mutation> $expectedAnnotation |
||
| 689 | * |
||
| 690 | * Return fields config from Provider methods. |
||
| 691 | * Loop through configured provider and extract fields targeting the targetType. |
||
| 692 | */ |
||
| 693 | 25 | private static function getGraphQLFieldsFromProviders(GraphClass $graphClass, string $expectedAnnotation, string $targetType, bool $isDefaultTarget = false): array |
|
| 694 | { |
||
| 695 | 25 | $fields = []; |
|
| 696 | 25 | foreach (self::$providers as ['metadata' => $providerMetadata, 'annotation' => $providerAnnotation]) { |
|
| 697 | 24 | $defaultAccessAnnotation = self::getFirstAnnotationMatching($providerMetadata->getAnnotations(), GQL\Access::class); |
|
| 698 | 24 | $defaultIsPublicAnnotation = self::getFirstAnnotationMatching($providerMetadata->getAnnotations(), GQL\IsPublic::class); |
|
| 699 | |||
| 700 | 24 | $defaultAccess = $defaultAccessAnnotation ? self::formatExpression($defaultAccessAnnotation->value) : false; |
|
| 701 | 24 | $defaultIsPublic = $defaultIsPublicAnnotation ? self::formatExpression($defaultIsPublicAnnotation->value) : false; |
|
| 702 | |||
| 703 | 24 | $methods = []; |
|
| 704 | // First found the methods matching the targeted type |
||
| 705 | 24 | foreach ($providerMetadata->getMethods() as $method) { |
|
| 706 | 24 | $annotations = $providerMetadata->getAnnotations($method); |
|
| 707 | |||
| 708 | 24 | $annotation = self::getFirstAnnotationMatching($annotations, [GQL\Mutation::class, GQL\Query::class]); |
|
| 709 | 24 | if (null === $annotation) { |
|
| 710 | continue; |
||
| 711 | } |
||
| 712 | |||
| 713 | 24 | $annotationTargets = $annotation->targetType ?? null; |
|
| 714 | |||
| 715 | 24 | if (null === $annotationTargets) { |
|
| 716 | 24 | if ($annotation instanceof GQL\Mutation && isset($providerAnnotation->targetTypeMutation)) { |
|
| 717 | 24 | $annotationTargets = $providerAnnotation->targetTypeMutation; |
|
| 718 | } |
||
| 719 | 24 | if ($annotation instanceof GQL\Query && isset($providerAnnotation->targetTypeQuery)) { |
|
| 720 | 24 | $annotationTargets = $providerAnnotation->targetTypeQuery; |
|
| 721 | } |
||
| 722 | } |
||
| 723 | |||
| 724 | 24 | if (null === $annotationTargets) { |
|
| 725 | 24 | if ($isDefaultTarget) { |
|
| 726 | 24 | $annotationTargets = [$targetType]; |
|
| 727 | 24 | if (!$annotation instanceof $expectedAnnotation) { |
|
| 728 | 24 | continue; |
|
| 729 | } |
||
| 730 | } else { |
||
| 731 | 24 | continue; |
|
| 732 | } |
||
| 733 | } |
||
| 734 | |||
| 735 | 24 | if (!in_array($targetType, $annotationTargets)) { |
|
| 736 | 24 | continue; |
|
| 737 | } |
||
| 738 | |||
| 739 | 24 | if (!$annotation instanceof $expectedAnnotation) { |
|
| 740 | 2 | if (GQL\Mutation::class === $expectedAnnotation) { |
|
| 741 | 1 | $message = sprintf('The provider "%s" try to add a query field on type "%s" (through @Query on method "%s") but "%s" is a mutation.', $providerMetadata->getName(), $targetType, $method->getName(), $targetType); |
|
| 742 | } else { |
||
| 743 | 1 | $message = sprintf('The provider "%s" try to add a mutation on type "%s" (through @Mutation on method "%s") but "%s" is not a mutation.', $providerMetadata->getName(), $targetType, $method->getName(), $targetType); |
|
| 744 | } |
||
| 745 | |||
| 746 | 2 | throw new InvalidArgumentException($message); |
|
| 747 | } |
||
| 748 | 24 | $methods[$method->getName()] = $method; |
|
| 749 | } |
||
| 750 | |||
| 751 | 24 | $currentValue = sprintf("service('%s')", self::formatNamespaceForExpression($providerMetadata->getName())); |
|
| 752 | 24 | $providerFields = self::getGraphQLTypeFieldsFromAnnotations($graphClass, $methods, $expectedAnnotation, $currentValue); |
|
| 753 | 24 | foreach ($providerFields as $fieldName => $fieldConfig) { |
|
| 754 | 24 | if (isset($providerAnnotation->prefix)) { |
|
| 755 | 24 | $fieldName = sprintf('%s%s', $providerAnnotation->prefix, $fieldName); |
|
| 756 | } |
||
| 757 | |||
| 758 | 24 | if ($defaultAccess && !isset($fieldConfig['access'])) { |
|
| 759 | 24 | $fieldConfig['access'] = $defaultAccess; |
|
| 760 | } |
||
| 761 | |||
| 762 | 24 | if ($defaultIsPublic && !isset($fieldConfig['public'])) { |
|
| 763 | 24 | $fieldConfig['public'] = $defaultIsPublic; |
|
| 764 | } |
||
| 765 | |||
| 766 | 24 | $fields[$fieldName] = $fieldConfig; |
|
| 767 | } |
||
| 768 | } |
||
| 769 | |||
| 770 | 25 | return $fields; |
|
| 771 | } |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Get the config for description & deprecation reason. |
||
| 775 | */ |
||
| 776 | 25 | private static function getDescriptionConfiguration(array $annotations, bool $withDeprecation = false): array |
|
| 777 | { |
||
| 778 | 25 | $config = []; |
|
| 779 | 25 | $descriptionAnnotation = self::getFirstAnnotationMatching($annotations, GQL\Description::class); |
|
| 780 | 25 | if (null !== $descriptionAnnotation) { |
|
| 781 | 24 | $config['description'] = $descriptionAnnotation->value; |
|
| 782 | } |
||
| 783 | |||
| 784 | 25 | if ($withDeprecation) { |
|
| 785 | 24 | $deprecatedAnnotation = self::getFirstAnnotationMatching($annotations, GQL\Deprecated::class); |
|
| 786 | 24 | if (null !== $deprecatedAnnotation) { |
|
| 787 | 24 | $config['deprecationReason'] = $deprecatedAnnotation->value; |
|
| 788 | } |
||
| 789 | } |
||
| 790 | |||
| 791 | 25 | return $config; |
|
| 792 | } |
||
| 793 | |||
| 794 | /** |
||
| 795 | * Format an array of args to a list of arguments in an expression. |
||
| 796 | */ |
||
| 797 | 24 | private static function formatArgsForExpression(array $args): string |
|
| 798 | { |
||
| 799 | 24 | $mapping = []; |
|
| 800 | 24 | foreach ($args as $name => $config) { |
|
| 801 | 24 | $mapping[] = sprintf('%s: "%s"', $name, $config['type']); |
|
| 802 | } |
||
| 803 | |||
| 804 | 24 | return sprintf('arguments({%s}, args)', implode(', ', $mapping)); |
|
| 805 | } |
||
| 806 | |||
| 807 | /** |
||
| 808 | * Format a namespace to be used in an expression (double escape). |
||
| 809 | */ |
||
| 810 | 24 | private static function formatNamespaceForExpression(string $namespace): string |
|
| 811 | { |
||
| 812 | 24 | return str_replace('\\', '\\\\', $namespace); |
|
| 813 | } |
||
| 814 | |||
| 815 | /** |
||
| 816 | * Get the first annotation matching given class. |
||
| 817 | * |
||
| 818 | * @phpstan-template T of object |
||
| 819 | * @phpstan-param class-string<T>|class-string<T>[] $annotationClass |
||
| 820 | * @phpstan-return T|null |
||
| 821 | * |
||
| 822 | * @param string|array $annotationClass |
||
| 823 | * |
||
| 824 | * @return object|null |
||
| 825 | */ |
||
| 826 | 25 | private static function getFirstAnnotationMatching(array $annotations, $annotationClass) |
|
| 827 | { |
||
| 828 | 25 | if (is_string($annotationClass)) { |
|
| 829 | 25 | $annotationClass = [$annotationClass]; |
|
| 830 | } |
||
| 831 | |||
| 832 | 25 | foreach ($annotations as $annotation) { |
|
| 833 | 25 | foreach ($annotationClass as $class) { |
|
| 834 | 25 | if ($annotation instanceof $class) { |
|
| 835 | 24 | return $annotation; |
|
| 836 | } |
||
| 837 | } |
||
| 838 | } |
||
| 839 | |||
| 840 | 25 | return null; |
|
| 841 | } |
||
| 842 | |||
| 843 | /** |
||
| 844 | * Format an expression (ie. add "@=" if not set). |
||
| 845 | */ |
||
| 846 | 24 | private static function formatExpression(string $expression): string |
|
| 847 | { |
||
| 848 | 24 | return '@=' === substr($expression, 0, 2) ? $expression : sprintf('@=%s', $expression); |
|
| 849 | } |
||
| 850 | |||
| 851 | /** |
||
| 852 | * Suffix a name if it is not already. |
||
| 853 | */ |
||
| 854 | 24 | private static function suffixName(string $name, string $suffix): string |
|
| 855 | { |
||
| 856 | 24 | return substr($name, -strlen($suffix)) === $suffix ? $name : sprintf('%s%s', $name, $suffix); |
|
| 857 | } |
||
| 858 | |||
| 859 | /** |
||
| 860 | * Try to guess a field type base on his annotations. |
||
| 861 | * |
||
| 862 | * @throws RuntimeException |
||
| 863 | */ |
||
| 864 | 24 | private static function guessType(GraphClass $graphClass, ReflectionProperty $reflector, array $filterGraphQLTypes = []): string |
|
| 865 | { |
||
| 866 | 24 | if ($reflector->hasType()) { |
|
|
|
|||
| 867 | try { |
||
| 868 | // @phpstan-ignore-next-line |
||
| 869 | 24 | return self::resolveGraphQLTypeFromReflectionType($reflector->getType(), $filterGraphQLTypes); |
|
| 870 | 24 | } catch (Exception $e) { |
|
| 871 | } |
||
| 872 | } |
||
| 873 | |||
| 874 | 24 | $annotations = $graphClass->getAnnotations($reflector); |
|
| 875 | 24 | $columnAnnotation = self::getFirstAnnotationMatching($annotations, Column::class); |
|
| 876 | 24 | if (null !== $columnAnnotation) { |
|
| 877 | 24 | $type = self::resolveTypeFromDoctrineType($columnAnnotation->type); |
|
| 878 | 24 | $nullable = $columnAnnotation->nullable; |
|
| 879 | 24 | if ($type) { |
|
| 880 | 24 | return $nullable ? $type : sprintf('%s!', $type); |
|
| 881 | } else { |
||
| 882 | 1 | throw new RuntimeException(sprintf('Unable to auto-guess GraphQL type from Doctrine type "%s"', $columnAnnotation->type)); |
|
| 883 | } |
||
| 884 | } |
||
| 885 | |||
| 886 | $associationAnnotations = [ |
||
| 887 | 24 | OneToMany::class => true, |
|
| 888 | OneToOne::class => false, |
||
| 889 | ManyToMany::class => true, |
||
| 890 | ManyToOne::class => false, |
||
| 891 | ]; |
||
| 892 | |||
| 893 | 24 | $associationAnnotation = self::getFirstAnnotationMatching($annotations, array_keys($associationAnnotations)); |
|
| 894 | 24 | if (null !== $associationAnnotation) { |
|
| 895 | 24 | $target = self::fullyQualifiedClassName($associationAnnotation->targetEntity, $graphClass->getNamespaceName()); |
|
| 896 | 24 | $type = self::resolveTypeFromClass($target, ['type']); |
|
| 897 | |||
| 898 | 24 | if ($type) { |
|
| 899 | 24 | $isMultiple = $associationAnnotations[get_class($associationAnnotation)]; |
|
| 900 | 24 | if ($isMultiple) { |
|
| 901 | 24 | return sprintf('[%s]!', $type); |
|
| 902 | } else { |
||
| 903 | 24 | $isNullable = false; |
|
| 904 | 24 | $joinColumn = self::getFirstAnnotationMatching($annotations, JoinColumn::class); |
|
| 905 | 24 | if (null !== $joinColumn) { |
|
| 906 | 24 | $isNullable = $joinColumn->nullable; |
|
| 907 | } |
||
| 908 | |||
| 909 | 24 | return sprintf('%s%s', $type, $isNullable ? '' : '!'); |
|
| 910 | } |
||
| 911 | } else { |
||
| 912 | 1 | throw new RuntimeException(sprintf('Unable to auto-guess GraphQL type from Doctrine target class "%s" (check if the target class is a GraphQL type itself (with a @GQL\Type annotation).', $target)); |
|
| 913 | } |
||
| 914 | } |
||
| 915 | |||
| 916 | throw new InvalidArgumentException(sprintf('No Doctrine ORM annotation found.')); |
||
| 917 | } |
||
| 918 | |||
| 919 | /** |
||
| 920 | * Resolve a FQN from classname and namespace. |
||
| 921 | * |
||
| 922 | * @internal |
||
| 923 | */ |
||
| 924 | 24 | public static function fullyQualifiedClassName(string $className, string $namespace): string |
|
| 931 | } |
||
| 932 | |||
| 933 | /** |
||
| 934 | * Resolve a GraphQLType from a doctrine type. |
||
| 935 | */ |
||
| 936 | 24 | private static function resolveTypeFromDoctrineType(string $doctrineType): ?string |
|
| 937 | { |
||
| 938 | 24 | if (isset(self::$doctrineMapping[$doctrineType])) { |
|
| 939 | 24 | return self::$doctrineMapping[$doctrineType]; |
|
| 940 | } |
||
| 941 | |||
| 942 | switch ($doctrineType) { |
||
| 943 | 24 | case 'integer': |
|
| 944 | 1 | case 'smallint': |
|
| 945 | 1 | case 'bigint': |
|
| 946 | 24 | return 'Int'; |
|
| 947 | 1 | case 'string': |
|
| 948 | 1 | case 'text': |
|
| 949 | return 'String'; |
||
| 950 | 1 | case 'bool': |
|
| 951 | 1 | case 'boolean': |
|
| 952 | return 'Boolean'; |
||
| 953 | 1 | case 'float': |
|
| 954 | 1 | case 'decimal': |
|
| 955 | return 'Float'; |
||
| 956 | default: |
||
| 957 | 1 | return null; |
|
| 958 | } |
||
| 959 | } |
||
| 960 | |||
| 961 | /** |
||
| 962 | * Transform a method arguments from reflection to a list of GraphQL argument. |
||
| 963 | */ |
||
| 964 | 24 | private static function guessArgs(ReflectionMethod $method): array |
|
| 965 | { |
||
| 966 | 24 | $arguments = []; |
|
| 967 | 24 | foreach ($method->getParameters() as $index => $parameter) { |
|
| 968 | 24 | if (!$parameter->hasType()) { |
|
| 969 | 1 | throw new InvalidArgumentException(sprintf('Argument n°%s "$%s" on method "%s" cannot be auto-guessed as there is not type hint.', $index + 1, $parameter->getName(), $method->getName())); |
|
| 970 | } |
||
| 971 | |||
| 972 | try { |
||
| 973 | // @phpstan-ignore-next-line |
||
| 974 | 24 | $gqlType = self::resolveGraphQLTypeFromReflectionType($parameter->getType(), self::VALID_INPUT_TYPES, $parameter->isDefaultValueAvailable()); |
|
| 975 | } catch (Exception $e) { |
||
| 976 | throw new InvalidArgumentException(sprintf('Argument n°%s "$%s" on method "%s" cannot be auto-guessed : %s".', $index + 1, $parameter->getName(), $method->getName(), $e->getMessage())); |
||
| 977 | } |
||
| 978 | |||
| 979 | 24 | $argumentConfig = []; |
|
| 980 | 24 | if ($parameter->isDefaultValueAvailable()) { |
|
| 981 | 24 | $argumentConfig['defaultValue'] = $parameter->getDefaultValue(); |
|
| 982 | } |
||
| 983 | |||
| 984 | 24 | $argumentConfig['type'] = $gqlType; |
|
| 985 | |||
| 986 | 24 | $arguments[$parameter->getName()] = $argumentConfig; |
|
| 987 | } |
||
| 988 | |||
| 989 | 24 | return $arguments; |
|
| 990 | } |
||
| 991 | |||
| 992 | 24 | private static function resolveGraphQLTypeFromReflectionType(ReflectionNamedType $type, array $filterGraphQLTypes = [], bool $isOptional = false): string |
|
| 993 | { |
||
| 994 | 24 | $sType = $type->getName(); |
|
| 995 | 24 | if ($type->isBuiltin()) { |
|
| 996 | 24 | $gqlType = self::resolveTypeFromPhpType($sType); |
|
| 997 | 24 | if (null === $gqlType) { |
|
| 998 | 24 | throw new RuntimeException(sprintf('No corresponding GraphQL type found for builtin type "%s"', $sType)); |
|
| 999 | } |
||
| 1000 | } else { |
||
| 1001 | 24 | $gqlType = self::resolveTypeFromClass($sType, $filterGraphQLTypes); |
|
| 1002 | 24 | if (null === $gqlType) { |
|
| 1003 | throw new RuntimeException(sprintf('No corresponding GraphQL %s found for class "%s"', $filterGraphQLTypes ? implode(',', $filterGraphQLTypes) : 'object', $sType)); |
||
| 1004 | } |
||
| 1005 | } |
||
| 1006 | |||
| 1007 | 24 | return sprintf('%s%s', $gqlType, ($type->allowsNull() || $isOptional) ? '' : '!'); |
|
| 1008 | } |
||
| 1009 | |||
| 1010 | /** |
||
| 1011 | * Resolve a GraphQL Type from a class name. |
||
| 1012 | */ |
||
| 1013 | 24 | private static function resolveTypeFromClass(string $className, array $wantedTypes = []): ?string |
|
| 1014 | { |
||
| 1015 | 24 | foreach (self::$classesMap as $gqlType => $config) { |
|
| 1016 | 24 | if ($config['class'] === $className) { |
|
| 1017 | 24 | if (in_array($config['type'], $wantedTypes)) { |
|
| 1018 | 24 | return $gqlType; |
|
| 1019 | } |
||
| 1020 | } |
||
| 1021 | } |
||
| 1022 | |||
| 1023 | 1 | return null; |
|
| 1024 | } |
||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * Search the classes map for class by predicate. |
||
| 1028 | * |
||
| 1029 | * @return array |
||
| 1030 | */ |
||
| 1031 | 25 | private static function searchClassesMapBy(callable $predicate, string $type) |
|
| 1032 | { |
||
| 1033 | 25 | $classNames = []; |
|
| 1034 | 25 | foreach (self::$classesMap as $gqlType => $config) { |
|
| 1035 | 25 | if ($config['type'] !== $type) { |
|
| 1036 | 25 | continue; |
|
| 1037 | } |
||
| 1038 | |||
| 1039 | 24 | if ($predicate($gqlType, $config)) { |
|
| 1040 | 24 | $classNames[$gqlType] = $config; |
|
| 1041 | } |
||
| 1042 | } |
||
| 1043 | |||
| 1044 | 25 | return $classNames; |
|
| 1045 | } |
||
| 1046 | |||
| 1047 | /** |
||
| 1048 | * Convert a PHP Builtin type to a GraphQL type. |
||
| 1049 | */ |
||
| 1050 | 24 | private static function resolveTypeFromPhpType(string $phpType): ?string |
|
| 1066 | } |
||
| 1067 | } |
||
| 1068 | } |
||
| 1069 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.