AbstractType::getTypeOf()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5.5021

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 6
cts 11
cp 0.5455
rs 9.2
cc 4
eloc 10
nc 4
nop 1
crap 5.5021
1
<?php
2
3
namespace Fubhy\GraphQL\Type\Definition\Types;
4
5
abstract class AbstractType extends Type implements AbstractTypeInterface {
6
7
    /**
8
     * @param mixed $value
9
     *
10
     * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType|null
11
     *
12
     * @throws \Exception
13
     */
14 9
    public function getTypeOf($value)
15
    {
16 9
        foreach ($this->getPossibleTypes() as $type) {
17 9
            if ($isTypeOf = $type->isTypeOf($value)) {
18 9
                return $type;
19
            }
20
21 9
            if (!isset($isTypeOf)) {
22
                throw new \Exception(sprintf(
23
                    'Non-Object Type %s does not implement resolveType and Object ' .
24
                    'Type %s does not implement isTypeOf. There is no way to ' .
25
                    'determine if a value is of this type.', $this->getName(), $type->getName()
26
                ));
27
            }
28 9
        }
29
30
        return NULL;
31
    }
32
}
33