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

Extractor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
}