Node   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 2
cbo 1
dl 0
loc 76
ccs 16
cts 16
cp 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getType() 0 4 1
A getName() 0 4 1
A getNameForArray() 0 4 1
A getNameForObject() 0 4 1
A getSanitizedName() 0 4 1
A isArray() 0 4 1
A isObject() 0 4 1
A getElements() 0 4 1
1
<?php
2
/**
3
 * Copyright (C) 2013-2020
4
 * Piotr Olaszewski <[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24
namespace WSDL\Parser;
25
26
use Ouzo\Utilities\Inflector;
27
28
/**
29
 * Node
30
 *
31
 * @author Piotr Olaszewski <[email protected]>
32
 */
33
class Node
34
{
35
    /**
36
     * @var string
37
     */
38
    private $type;
39
    /**
40
     * @var string
41
     */
42
    private $name;
43
    /**
44
     * @var bool
45
     */
46
    private $isArray;
47
    /**
48
     * @var Node[]
49
     */
50
    private $elements;
51
52
    /**
53
     * @param string $type
54
     * @param string $name
55
     * @param bool $isArray
56
     * @param Node[] $elements
57
     */
58 37
    public function __construct(string $type, string $name, bool $isArray, array $elements = [])
59
    {
60 37
        $this->type = $type;
61 37
        $this->name = $name;
62 37
        $this->isArray = (bool)$isArray;
63 37
        $this->elements = $elements;
64 37
    }
65
66
    public function getType(): string
67
    {
68
        return $this->type;
69 10
    }
70
71 10
    public function getName(): string
72
    {
73
        return $this->name;
74
    }
75
76
    public function getNameForArray(): string
77 2
    {
78
        return 'ArrayOf' . ucfirst($this->getSanitizedName());
79 2
    }
80
81
    public function getNameForObject(): string
82
    {
83
        return Inflector::singularize(ucfirst($this->getSanitizedName()));
84
    }
85 6
86
    public function getSanitizedName(): string
87 6
    {
88
        return str_replace('$', '', $this->name);
89
    }
90
91
    public function isArray(): bool
92
    {
93 8
        return $this->isArray;
94
    }
95 8
96
    public function isObject(): bool
97
    {
98
        return $this->type == Parser::OBJECT_TYPE;
99
    }
100
101 14
    /**
102
     * @return Node[]
103 14
     */
104
    public function getElements(): array
105
    {
106
        return $this->elements;
107
    }
108
}
109