Failed Conditions
Push — master ( ecccd5...ae55c7 )
by Marco
33s
created

ObjectType::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Type;
6
7
use function is_object;
8
9
/**
10
 * @internal
11
 */
12
class ObjectType implements Type
13
{
14
    /** @var string|null */
15
    private $className;
16
17 332
    public function __construct(?string $className)
18
    {
19 332
        $this->className = $className;
20 332
    }
21
22 33
    public function describe() : string
23
    {
24 33
        if ($this->className === null) {
25 1
            return 'object';
26
        }
27
28 33
        return $this->className;
29
    }
30
31
    /**
32
     * @param mixed $value
33
     */
34 137
    public function validate($value) : bool
35
    {
36 137
        return is_object($value) && ($this->className === null || $value instanceof $this->className);
37
    }
38
}
39