Completed
Pull Request — develop (#91)
by Mike
10:26
created

AbstractFactory::matches()

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
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
    public function create($object, StrategyContainer $strategies, Context $context = null)
0 ignored issues
show
Unused Code introduced by
The parameter $strategies is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
16
    {
17
        if (! $this->matches($object)) {
18
            throw new \InvalidArgumentException(
19
                sprintf('%s cannot handle objects with the type %s',
20
                    __CLASS__,
21
                    is_object($object) ? get_class($object) : gettype($object)
22
                )
23
            );
24
        }
25
    }
26
27
    abstract protected function doCreate($object, StrategyContainer $strategies, Context $context = null);
28
29
    /**
30
     * @param Node|PropertyIterator|ClassConstantIterator $stmt
31
     * @param StrategyContainer $strategies
32
     * @param Context $context
33
     * @return Element
34
     */
35
    protected function createMember($stmt, StrategyContainer $strategies, Context $context = null)
36
    {
37
        $strategy = $strategies->findMatching($stmt);
38
        return $strategy->create($stmt, $strategies, $context);
39
    }
40
41
    /**
42
     * @param Doc $docBlock
43
     * @param StrategyContainer $strategies
44
     * @param Context $context
45
     * @return null|\phpDocumentor\Reflection\DocBlock
46
     */
47
    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...
48
    {
49
        if ($docBlock === null) {
50
            return null;
51
        }
52
53
        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...
54
    }
55
}
56