Completed
Push — master ( 84373a...27696b )
by Maxim
03:25 queued 24s
created

ClassData   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
dl 0
loc 56
ccs 8
cts 12
cp 0.6667
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addProperty() 0 3 1
A getAllMethods() 0 11 3
A __construct() 0 3 1
A getAllProperties() 0 3 1
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
    public function __construct(\ReflectionClass $reflection)
32
    {
33 1
        $this->reflection = $reflection;
34
    }
35 1
36 1
    /**
37
     * Adds property information to class data.
38
     *
39
     * @param string $name name of the property
40
     * @param PropertyData $propertyData property data
41
     */
42
    public function addProperty(string $name, PropertyData $propertyData)
43
    {
44 1
        $this->properties[$name] = $propertyData;
45
    }
46 1
47 1
    /**
48
     * Returns all Axessors properties.
49
     *
50
     * @return PropertyData[] class' properties
51
     */
52
    public function getAllProperties(): array
53
    {
54
        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
    public function getAllMethods(bool $skipPrivate = false): array
64
    {
65
        $methods = [];
66
        foreach ($this->properties as $propertyData) {
67
            $propertyMethods = $propertyData->getMethods();
68
            if ($skipPrivate) {
69
                unset($propertyMethods['private']);
70 52
            }
71
            $methods = array_merge_recursive($methods, $propertyMethods);
72 52
        }
73
        return $methods;
74
    }
75
}
76