ClassData   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 56
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addProperty() 0 3 1
A __construct() 0 3 1
A getAllProperties() 0 3 1
A getAllMethods() 0 11 3
1
<?php
2
/**
3
 * This file is a part of "Axessors" library.
4
 *
5
 * @author <[email protected]>
6
 * @license GPL
7
 */
8
9
namespace NoOne4rever\Axessors;
10
11
/**
12
 * Class ClassData.
13
 *
14
 * Stores the reflection of a class and Axessors properties.
15
 *
16
 * @package NoOne4rever\Axessors
17
 */
18
class ClassData
19
{
20
    /** @var \ReflectionClass class data */
21
    public $reflection;
22
23
    /** @var PropertyData[] Axessors properties */
24
    private $properties = [];
25
26
    /**
27
     * ClassData constructor.
28
     *
29
     * @param \ReflectionClass $reflection reflection of the class
30
     */
31 5
    public function __construct(\ReflectionClass $reflection)
32
    {
33 5
        $this->reflection = $reflection;
34 5
    }
35
36
    /**
37
     * Adds property information to class data.
38
     *
39
     * @param string $name name of the property
40
     * @param PropertyData $propertyData property data
41
     */
42 2
    public function addProperty(string $name, PropertyData $propertyData)
43
    {
44 2
        $this->properties[$name] = $propertyData;
45 2
    }
46
47
    /**
48
     * Returns all Axessors properties.
49
     *
50
     * @return PropertyData[] class' properties
51
     */
52 102
    public function getAllProperties(): array
53
    {
54 102
        return $this->properties;
55
    }
56
57
    /**
58
     * Returns all Axessors methods names.
59
     *
60
     * @param bool $skipPrivate a flag; indicates if private methods are skipped
61
     * @return string[] Axessors methods' names
62
     */
63 2
    public function getAllMethods(bool $skipPrivate = false): array
64
    {
65 2
        $methods = [];
66 2
        foreach ($this->properties as $propertyData) {
67 2
            $propertyMethods = $propertyData->getMethods();
68 2
            if ($skipPrivate) {
69 2
                unset($propertyMethods['private']);
70
            }
71 2
            $methods = array_merge_recursive($methods, $propertyMethods);
72
        }
73 2
        return $methods;
74
    }
75
}
76