Completed
Push — develop ( 9dbd4b...3bc77a )
by Jaap
16s
created

Descriptor/Builder/Reflector/ArgumentAssembler.php (2 issues)

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
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    Mike van Riel <[email protected]>
11
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
12
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
13
 * @link      http://phpdoc.org
14
 */
15
16
namespace phpDocumentor\Descriptor\Builder\Reflector;
17
18
use phpDocumentor\Descriptor\ArgumentDescriptor;
19
use phpDocumentor\Descriptor\Tag\ParamDescriptor;
20
use phpDocumentor\Reflection\Php\Argument;
21
22
/**
23
 * Assembles an ArgumentDescriptor using an ArgumentReflector and ParamDescriptors.
24
 */
25
class ArgumentAssembler extends AssemblerAbstract
26
{
27
    /**
28
     * Creates a Descriptor from the provided data.
29
     *
30
     * @param Argument $data
31
     * @param ParamDescriptor[] $params
32
     *
33
     * @return ArgumentDescriptor
34
     */
35 2
    public function create($data, $params = [])
36
    {
37 2
        $argumentDescriptor = new ArgumentDescriptor();
38 2
        $argumentDescriptor->setName($data->getName());
39 2
        $argumentDescriptor->setTypes($data->getTypes());
0 ignored issues
show
$data->getTypes() is of type array<integer,*>, 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...
40
41 2
        foreach ($params as $paramDescriptor) {
42 1
            $this->overwriteTypeAndDescriptionFromParamTag($data, $paramDescriptor, $argumentDescriptor);
43
        }
44
45 2
        $argumentDescriptor->setDefault($data->getDefault());
46 2
        $argumentDescriptor->setByReference($data->isByReference());
47
48 2
        return $argumentDescriptor;
49
    }
50
51
    /**
52
     * Overwrites the type and description in the Argument Descriptor with that from the tag if the names match.
53
     */
54 1
    protected function overwriteTypeAndDescriptionFromParamTag(
55
        Argument  $argument,
56
        ParamDescriptor    $paramDescriptor,
57
        ArgumentDescriptor $argumentDescriptor
58
    ): void {
59 1
        if ($paramDescriptor->getVariableName() !== $argument->getName()) {
60
            return;
61
        }
62
63 1
        $argumentDescriptor->setDescription($paramDescriptor->getDescription());
64 1
        $argumentDescriptor->setTypes($paramDescriptor->getTypes());
0 ignored issues
show
$paramDescriptor->getTypes() is of type object<phpDocumentor\Reflection\Type>, 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...
65 1
    }
66
}
67