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

DoctrineORMNodeChecker::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.576

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 3
dl 0
loc 6
ccs 3
cts 5
cp 0.6
crap 3.576
rs 9.4285
c 0
b 0
f 0
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