Completed
Pull Request — develop (#91)
by Jaap
04:27
created

AbstractFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 6
c 4
b 1
f 0
lcom 0
cbo 2
dl 0
loc 48
ccs 17
cts 17
cp 1
rs 10

5 Methods

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