Passed
Push — master ( d09870...716959 )
by Luis
02:38
created

Summary   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 141
ccs 67
cts 67
cp 1
rs 10
c 0
b 0
f 0
wmc 23

20 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A protectedAttributeCount() 0 3 1
A protectedFunctionCount() 0 3 1
A typedAttributeCount() 0 3 1
A attributesSummary() 0 11 1
A attributeCount() 0 3 1
A classCount() 0 3 1
A publicAttributeCount() 0 3 1
A attributesPerClass() 0 3 1
A publicTypedAttributes() 0 3 1
A publicFunctionCount() 0 3 1
A privateAttributeCount() 0 3 1
A from() 0 11 4
A privateTypedAttributes() 0 3 1
A functionCount() 0 3 1
A functionsPerClass() 0 3 1
A methodsSummary() 0 5 1
A protectedTypedAttributes() 0 3 1
A interfaceCount() 0 3 1
A privateFunctionCount() 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
/**
11
 * It creates a summary of the classes, interfaces, methods, and attributes of a codebase
12
 */
13
class Summary
14
{
15
    private $interfaceCount;
16
    private $classCount;
17
    private $publicFunctionCount;
18
    private $publicAttributeCount;
19
    private $publicTypedAttributes;
20
    private $protectedFunctionCount;
21
    private $protectedAttributeCount;
22
    private $protectedTypedAttributes;
23
    private $privateFunctionCount;
24
    private $privateAttributeCount;
25
    private $privateTypedAttributes;
26
27 12
    public function __construct()
28
    {
29 12
        $this->interfaceCount = 0;
30 12
        $this->classCount = 0;
31 12
        $this->publicFunctionCount = 0;
32 12
        $this->publicAttributeCount = 0;
33 12
        $this->publicTypedAttributes = 0;
34 12
        $this->protectedFunctionCount = 0;
35 12
        $this->protectedAttributeCount = 0;
36 12
        $this->protectedTypedAttributes = 0;
37 12
        $this->privateFunctionCount = 0;
38 12
        $this->privateAttributeCount = 0;
39 12
        $this->privateTypedAttributes = 0;
40 12
    }
41
42 12
    public function from(Structure $structure): void
43
    {
44 12
        foreach ($structure->definitions() as $definition) {
45 12
            if ($definition instanceof InterfaceDefinition) {
46 3
                $this->interfaceCount++;
47
            }
48 12
            if ($definition instanceof ClassDefinition) {
49 12
                $this->classCount++;
50 12
                $this->attributesSummary($definition);
51
            }
52 12
            $this->methodsSummary($definition);
53
        }
54 12
    }
55
56 12
    private function attributesSummary(ClassDefinition $definition): void
57
    {
58
        // Attributes count
59 12
        $this->publicAttributeCount += $definition->countAttributesByVisibility(Visibility::public());
60 12
        $this->protectedAttributeCount += $definition->countAttributesByVisibility(Visibility::protected());
61 12
        $this->privateAttributeCount += $definition->countAttributesByVisibility(Visibility::private());
62
63
        // Typed attributes count
64 12
        $this->publicTypedAttributes += $definition->countTypedAttributesByVisibility(Visibility::public());
65 12
        $this->protectedTypedAttributes += $definition->countTypedAttributesByVisibility(Visibility::protected());
66 12
        $this->privateTypedAttributes += $definition->countTypedAttributesByVisibility(Visibility::private());
67 12
    }
68
69 12
    private function methodsSummary(Definition $definition): void
70
    {
71 12
        $this->publicFunctionCount += $definition->countMethodsByVisibility(Visibility::public());
72 12
        $this->protectedFunctionCount += $definition->countMethodsByVisibility(Visibility::protected());
73 12
        $this->privateFunctionCount += $definition->countMethodsByVisibility(Visibility::private());
74 12
    }
75
76 12
    public function interfaceCount(): int
77
    {
78 12
        return $this->interfaceCount;
79
    }
80
81 12
    public function classCount(): int
82
    {
83 12
        return $this->classCount;
84
    }
85
86 12
    public function publicFunctionCount(): int
87
    {
88 12
        return $this->publicFunctionCount;
89
    }
90
91 12
    public function publicAttributeCount(): int
92
    {
93 12
        return $this->publicAttributeCount;
94
    }
95
96 3
    public function publicTypedAttributes(): int
97
    {
98 3
        return $this->publicTypedAttributes;
99
    }
100
101 12
    public function protectedFunctionCount(): int
102
    {
103 12
        return $this->protectedFunctionCount;
104
    }
105
106 12
    public function protectedAttributeCount(): int
107
    {
108 12
        return $this->protectedAttributeCount;
109
    }
110
111 3
    public function protectedTypedAttributes(): int
112
    {
113 3
        return $this->protectedTypedAttributes;
114
    }
115
116 12
    public function privateFunctionCount(): int
117
    {
118 12
        return $this->privateFunctionCount;
119
    }
120
121 12
    public function privateAttributeCount(): int
122
    {
123 12
        return $this->privateAttributeCount;
124
    }
125
126 3
    public function privateTypedAttributes(): int
127
    {
128 3
        return $this->privateTypedAttributes;
129
    }
130
131 12
    public function functionCount(): int
132
    {
133 12
        return $this->publicFunctionCount + $this->protectedFunctionCount + $this->privateFunctionCount;
134
    }
135
136 12
    public function attributeCount(): int
137
    {
138 12
        return $this->publicAttributeCount + $this->protectedAttributeCount + $this->privateAttributeCount;
139
    }
140
141 12
    public function typedAttributeCount(): int
142
    {
143 12
        return $this->publicTypedAttributes + $this->protectedTypedAttributes + $this->privateTypedAttributes;
144
    }
145
146 12
    public function attributesPerClass(): float
147
    {
148 12
        return round($this->attributeCount() / $this->classCount, 2);
149
    }
150
151 12
    public function functionsPerClass(): float
152
    {
153 12
        return round($this->functionCount() / $this->classCount, 2);
154
    }
155
}
156