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

AbstractFactory::doCreate()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 1
1
<?php
2
3
namespace phpDocumentor\Reflection\Php\Factory;
4
5
use phpDocumentor\Reflection\Element;
6
use phpDocumentor\Reflection\Php\StrategyContainer;
7
use phpDocumentor\Reflection\Types\Context;
8
use PhpParser\Comment\Doc;
9
use PhpParser\Node;
10
11
abstract class AbstractFactory
12
{
13
    abstract public function matches($object);
14
15 42
    public final function create($object, StrategyContainer $strategies, Context $context = null)
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
16
    {
17 42
        if (! $this->matches($object)) {
18 8
            throw new \InvalidArgumentException(
19 8
                sprintf('%s cannot handle objects with the type %s',
20 8
                    __CLASS__,
21 8
                    is_object($object) ? get_class($object) : gettype($object)
22 8
                )
23 8
            );
24
        }
25
26 34
        return $this->doCreate($object, $strategies, $context);
27
    }
28
29
    abstract protected function doCreate($object, StrategyContainer $strategies, Context $context = null);
30
31
    /**
32
     * @param Node|PropertyIterator|ClassConstantIterator $stmt
33
     * @param StrategyContainer $strategies
34
     * @param Context $context
35
     * @return Element
36
     */
37 14
    protected function createMember($stmt, StrategyContainer $strategies, Context $context = null)
38
    {
39 14
        $strategy = $strategies->findMatching($stmt);
40 14
        return $strategy->create($stmt, $strategies, $context);
41
    }
42
43
    /**
44
     * @param Doc $docBlock
45
     * @param StrategyContainer $strategies
46
     * @param Context $context
47
     * @return null|\phpDocumentor\Reflection\DocBlock
48
     */
49 28
    protected function createDocBlock(Doc $docBlock = null, StrategyContainer $strategies, Context $context = null)
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
50
    {
51 28
        if ($docBlock === null) {
52 22
            return null;
53
        }
54
55 6
        return $this->createMember($docBlock, $strategies, $context);
0 ignored issues
show
Documentation introduced by
$docBlock is of type object<PhpParser\Comment\Doc>, but the function expects a object<PhpParser\Node>|o...\ClassConstantIterator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
    }
57
}
58