AbstractFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 48
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
doCreate() 0 1 ?
matches() 0 1 ?
A create() 0 14 3
A createMember() 0 5 1
A createDocBlock() 0 8 3
1
<?php
2
declare(strict_types=1);
3
4
namespace phpDocumentor\Reflection\Php\Factory;
5
6
use phpDocumentor\Reflection\DocBlock as DocBlockInstance;
7
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
8
use phpDocumentor\Reflection\Php\StrategyContainer;
9
use phpDocumentor\Reflection\Types\Context;
10
use PhpParser\Comment\Doc;
11
use PhpParser\Node;
12
13
abstract class AbstractFactory implements ProjectFactoryStrategy
14
{
15
    /**
16
     * Returns true when the strategy is able to handle the object.
17
     *
18
     * @param mixed $object object to check.
19
     */
20
    abstract public function matches($object): bool;
21
22 50
    final public function create($object, StrategyContainer $strategies, ?Context $context = null)
23
    {
24 50
        if (!$this->matches($object)) {
25 8
            throw new \InvalidArgumentException(
26 8
                sprintf(
27 8
                    '%s cannot handle objects with the type %s',
28 8
                    __CLASS__,
29 8
                    is_object($object) ? get_class($object) : gettype($object)
30
                )
31
            );
32
        }
33
34 42
        return $this->doCreate($object, $strategies, $context);
35
    }
36
37
    abstract protected function doCreate($object, StrategyContainer $strategies, ?Context $context = null);
38
39
    /**
40
     * @param Node|PropertyIterator|ClassConstantIterator|Doc $stmt
41
     * @return mixed a child of Element
42
     */
43 17
    protected function createMember($stmt, StrategyContainer $strategies, ?Context $context = null)
44
    {
45 17
        $strategy = $strategies->findMatching($stmt);
46 17
        return $strategy->create($stmt, $strategies, $context);
47
    }
48
49
    /**
50
     * @return null|DocBlockInstance
51
     */
52 35
    protected function createDocBlock(?StrategyContainer $strategies = null, ?Doc $docBlock = null, ?Context $context = null)
53
    {
54 35
        if ($docBlock === null || $strategies === null) {
55 26
            return null;
56
        }
57
58 9
        return $this->createMember($docBlock, $strategies, $context);
59
    }
60
}
61