Passed
Push — master ( c39fb6...9e9a0d )
by Rafael
04:42
created

DoctrineORMNodeChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 5
cts 7
cp 0.7143
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 1
A parse() 0 6 3
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Definition\Loader\Annotation;
12
13
use Doctrine\ORM\Mapping\Entity;
14
use Ynlo\GraphQLBundle\Annotation;
15
use Ynlo\GraphQLBundle\Definition\Registry\Endpoint;
16
use Ynlo\GraphQLBundle\Model\NodeInterface;
17
18
/**
19
 * DoctrineORMNodeChecker
20
 */
21
class DoctrineORMNodeChecker implements AnnotationParserInterface
22
{
23
    use AnnotationReaderAwareTrait;
24
25
    /**
26
     * {@inheritDoc}
27
     */
28 1
    public function supports($annotation): bool
29
    {
30 1
        return $annotation instanceof Entity;
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 1
    public function parse($annotation, \ReflectionClass $refClass, Endpoint $endpoint)
37
    {
38 1
        if ($objectType = $this->reader->getClassAnnotation($refClass, Annotation\ObjectType::class)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $objectType is dead and can be removed.
Loading history...
39 1
            if (!$refClass->implementsInterface(NodeInterface::class)) {
40
                $error = sprintf('Invalid object "%s". All entities used as GraphQL object must implements %s', $refClass->getName(), NodeInterface::class);
41
                throw new \LogicException($error);
42
            }
43
        }
44 1
    }
45
}
46