Completed
Pull Request — develop (#91)
by Jaap
02:52
created

AbstractFactory::createMember()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4286
nc 1
cc 1
eloc 3
nop 3
crap 1
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