Test Failed
Push — master ( da2c9c...d0cc4d )
by Kirill
02:03
created

Type::isValid()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 9.8666
c 0
b 0
f 0
cc 3
nc 2
nop 1
crap 12

1 Method

Rating   Name   Duplication   Size   Complexity  
A Type::__toString() 0 4 1
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\Reflection;
11
12
use Railt\Reflection\Common\Serializable;
13
use Railt\Reflection\Contracts\Type as TypeInterface;
14
15
/**
16
 * Class Type
17
 */
18
class Type implements TypeInterface
19
{
20
    use Serializable;
21
22
    /**
23
     * @var Type[]
24
     */
25
    private static $instances = [];
26
27
    /**
28
     * @var array[]|string[][]
29
     */
30
    private static $inheritance = [];
31
32
    /**
33
     * @var string
34
     */
35
    protected $name;
36
37
    /**
38
     * BaseType constructor.
39
     * @param string $name
40
     */
41
    private function __construct(string $name)
42
    {
43
        \assert(\in_array($name, \array_merge(static::DEPENDENT_TYPES, static::ROOT_TYPES), true));
44
45
        $this->name = $name;
46
47
        if (self::$inheritance === []) {
48
            $this->bootInheritance();
0 ignored issues
show
Unused Code introduced by
The call to the method Railt\Reflection\Type::bootInheritance() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
49
        }
50
    }
51
52
    /**
53
     * @var
54
     */
55
    private function bootInheritance(): void
56
    {
57
58
    }
59
60
    /**
61
     * @param string $type
62
     * @return Type
63
     */
64
    public static function of(string $type): Type
65
    {
66
        return self::$instances[$type] ?? (self::$instances[$type] = new static($type));
67
    }
68
69
    /**
70
     * @return bool
71
     */
72
    public function isDependent(): bool
73
    {
74
        return \in_array($this->name, static::DEPENDENT_TYPES, true);
75
    }
76
77
    /**
78
     * @param TypeInterface $type
79
     * @return bool
80
     */
81
    public function instanceOf(TypeInterface $type): bool
82
    {
83
        return $this instanceof $type;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function __toString(): string
90
    {
91
        return $this->getName();
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getName(): string
98
    {
99
        return $this->name;
100
    }
101
}
102