Completed
Push — develop ( 9193e7...62056c )
by Jaap
12:45 queued 02:43
created

Descriptor/Builder/Reflector/ArgumentAssembler.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
12
namespace phpDocumentor\Descriptor\Builder\Reflector;
13
14
use phpDocumentor\Descriptor\ArgumentDescriptor;
15
use phpDocumentor\Reflection\DocBlock\Type\Collection;
16
use phpDocumentor\Descriptor\Tag\ParamDescriptor;
17
use phpDocumentor\Reflection\FunctionReflector\ArgumentReflector;
18
use phpDocumentor\Reflection\Php\Argument;
19
20
/**
21
 * Assembles an ArgumentDescriptor using an ArgumentReflector and ParamDescriptors.
22
 */
23
class ArgumentAssembler extends AssemblerAbstract
24
{
25
    /**
26
     * Creates a Descriptor from the provided data.
27
     *
28
     * @param Argument $data
29
     * @param ParamDescriptor[] $params
30
     *
31
     * @return ArgumentDescriptor
32
     */
33
    public function create($data, $params = array())
34
    {
35
        $argumentDescriptor = new ArgumentDescriptor();
36
        $argumentDescriptor->setName($data->getName());
37
        $argumentDescriptor->setTypes($data->getTypes());
0 ignored issues
show
$data->getTypes() is of type array<integer,string>, but the function expects a object<phpDocumentor\Descriptor\Collection>.

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...
38
39
        foreach ($params as $paramDescriptor) {
40
            $this->overwriteTypeAndDescriptionFromParamTag($data, $paramDescriptor, $argumentDescriptor);
41
        }
42
43
        $argumentDescriptor->setDefault($data->getDefault());
44
        $argumentDescriptor->setByReference($data->isByReference());
45
46
        return $argumentDescriptor;
47
    }
48
49
    /**
50
     * Overwrites the type and description in the Argument Descriptor with that from the tag if the names match.
51
     *
52
     * @param Argument  $argument
53
     * @param ParamDescriptor    $paramDescriptor
54
     * @param ArgumentDescriptor $argumentDescriptor
55
     *
56
     * @return void
57
     */
58
    protected function overwriteTypeAndDescriptionFromParamTag(
59
        Argument  $argument,
60
        ParamDescriptor    $paramDescriptor,
61
        ArgumentDescriptor $argumentDescriptor
62
    ) {
63
        if ($paramDescriptor->getVariableName() != $argument->getName()) {
64
            return;
65
        }
66
67
        $argumentDescriptor->setDescription($paramDescriptor->getDescription());
68
        $argumentDescriptor->setTypes($paramDescriptor->getTypes());
69
    }
70
}
71