Test Failed
Push — graphviz-refactoring ( 3f1b14 )
by Luis
02:18
created

plPhpTypeDeclaration   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 __construct() 0 3 1
A isPresent() 0 3 1
A __toString() 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
class plPhpTypeDeclaration
9
{
10
    /** @var string[] All valid types for PHP 7.1 */
11
    private static $builtInTypes = [
12
        'int', 'bool', 'string', 'array', 'float', 'callable', 'iterable'
13
    ];
14
15
    /** @var string */
16
    private $name;
17
18
    public function __construct(?string $name)
19
    {
20
        $this->name = $name;
21
    }
22
23
    public function isPresent(): bool
24
    {
25
        return $this->name !== null;
26
    }
27
28
    /**
29
     * This will help when building the relationships between classes/interfaces since built-in
30
     * types are not part of a UML class diagram
31
     */
32
    public function isBuiltIn(): bool
33
    {
34
        return !empty($this->name) && in_array($this->name, self::$builtInTypes, true);
35
    }
36
37
    public function __toString()
38
    {
39
        return (string)$this->name;
40
    }
41
}
42