Passed
Push — master ( 327a11...1a5769 )
by Valentin
58s
created

Extractor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A extract() 0 10 1
A hasCloneMethod() 0 14 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Cycle\ORM\Promise\Declaration;
5
6
final class Extractor
7
{
8
    /** @var Extractor\Methods */
9
    private $methods;
10
11
    /** @var Extractor\Properties */
12
    private $properties;
13
14
    /** @var Extractor\Constants */
15
    private $constants;
16
17
    public function __construct(Extractor\Constants $constants, Extractor\Properties $properties, Extractor\Methods $methods)
18
    {
19
        $this->constants = $constants;
20
        $this->properties = $properties;
21
        $this->methods = $methods;
22
    }
23
24
    public function extract(\ReflectionClass $reflection): Structure
25
    {
26
        return Structure::create(
27
            $this->constants->getConstants($reflection),
28
            $this->properties->getProperties($reflection),
29
            $this->methods->getMethods($reflection),
30
            $reflection->getConstructor() !== null,
31
            $this->hasCloneMethod($reflection)
32
        );
33
    }
34
35
    private function hasCloneMethod(\ReflectionClass $reflection): bool
36
    {
37
        if (!$reflection->hasMethod('__clone')) {
38
            return false;
39
        }
40
41
        try {
42
            $cloneMethod = $reflection->getMethod('__clone');
43
        } catch (\ReflectionException $exception) {
44
            return false;
45
        }
46
47
        return !$cloneMethod->isPrivate();
48
    }
49
}