Type   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 65
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A type() 0 4 1
A isNullable() 0 4 1
A isScalar() 0 14 1
1
<?php
2
3
namespace Leaditin\Code;
4
5
/**
6
 * @package Leaditin\Code
7
 * @author Igor Vuckovic <[email protected]>
8
 * @license MIT
9
 */
10
class Type
11
{
12
    public const TYPE_BOOL = 'bool';
13
    public const TYPE_INT = 'int';
14
    public const TYPE_FLOAT = 'float';
15
    public const TYPE_STRING = 'string';
16
    public const TYPE_ARRAY = 'array';
17
    public const TYPE_CALLABLE = 'callable';
18
    public const TYPE_MIXED = 'mixed';
19
    public const TYPE_VOID = 'void';
20
21
    /**
22
     * @var string
23
     */
24
    protected $type;
25
26
    /**
27
     * @var bool
28
     */
29
    protected $isNullable;
30
31
    /**
32
     * @param string $type
33
     * @param bool $isNullable
34
     */
35 2
    public function __construct(string $type, bool $isNullable = false)
36
    {
37 2
        $this->type = $type;
38 2
        $this->isNullable = $isNullable;
39 2
    }
40
41
    /**
42
     * @return string
43
     */
44 2
    public function type(): string
45
    {
46 2
        return $this->type;
47
    }
48
49
    /**
50
     * @return bool
51
     */
52 2
    public function isNullable(): bool
53
    {
54 2
        return $this->isNullable;
55
    }
56
57
    /**
58
     * @return bool
59
     */
60 2
    public function isScalar(): bool
61
    {
62 2
        return in_array(
63 2
            $this->type,
64
            [
65 2
                self::TYPE_BOOL,
66 2
                self::TYPE_INT,
67 2
                self::TYPE_STRING,
68 2
                self::TYPE_FLOAT,
69 2
                self::TYPE_ARRAY,
70
            ],
71 2
            false
72
        );
73
    }
74
}
75