Completed
Push — master ( 3f1b14...d7a449 )
by Luis
14:49 queued 04:53
created

TypeDeclaration::isPresent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
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