Test Failed
Push — master ( e3b5b4...43c430 )
by Kirill
04:55
created

BaseType   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A is() 0 4 1
A instanceOf() 0 4 2
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Frontend\Type;
11
12
/**
13
 * Class BaseType
14
 */
15
abstract class BaseType implements TypeInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    private $name;
21
22
    /**
23
     * @var TypeInterface
24
     */
25
    private $parent;
26
27
    /**
28
     * BaseType constructor.
29
     * @param string $name
30
     * @param TypeInterface $parent
31
     */
32
    public function __construct(string $name, TypeInterface $parent)
33
    {
34
        $this->name = $name;
35
        $this->parent = $parent;
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getName(): string
42
    {
43
        return $this->name;
44
    }
45
46
    /**
47
     * @param TypeInterface $type
48
     * @return bool
49
     */
50
    public function is(TypeInterface $type): bool
51
    {
52
        return $type->getName() === $this->getName();
53
    }
54
55
    /**
56
     * @param TypeInterface $type
57
     * @return bool
58
     */
59
    public function instanceOf(TypeInterface $type): bool
60
    {
61
        return $this->is($type) || $this->parent->instanceOf($type);
62
    }
63
}
64