Test Failed
Push — psr4-packages ( 592372 )
by Luis
02:13
created

TypeDeclaration   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 32
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isBuiltIn() 0 3 2
A __toString() 0 3 1
A __construct() 0 3 1
A isPresent() 0 3 1
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Code;
9
10
class TypeDeclaration
11
{
12
    /** @var string[] All valid types for PHP 7.1 */
13
    private static $builtInTypes = [
14
        'int', 'bool', 'string', 'array', 'float', 'callable', 'iterable'
15
    ];
16
17
    /** @var string */
18
    private $name;
19
20
    public function __construct(?string $name)
21
    {
22
        $this->name = $name;
23
    }
24
25
    public function isPresent(): bool
26
    {
27
        return $this->name !== null;
28
    }
29
30
    /**
31
     * This will help when building the relationships between classes/interfaces since built-in
32
     * types are not part of a UML class diagram
33
     */
34
    public function isBuiltIn(): bool
35
    {
36
        return !empty($this->name) && in_array($this->name, self::$builtInTypes, true);
37
    }
38
39
    public function __toString()
40
    {
41
        return (string)$this->name;
42
    }
43
}
44