Completed
Push — develop ( cec1b5...82146f )
by Paul
02:04
created

ParamTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseParam() 0 7 1
1
<?php
2
3
namespace PhpUnitGen\Parser\NodeParserTrait;
4
5
use PhpParser\Node;
6
use PhpUnitGen\Model\ModelInterface\ParameterModelInterface;
7
use PhpUnitGen\Model\ParameterModel;
8
use PhpUnitGen\Model\PropertyInterface\VisibilityInterface;
9
10
/**
11
 * Trait ParamTrait.
12
 *
13
 * @author     Paul Thébaud <[email protected]>.
14
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
15
 * @license    https://opensource.org/licenses/MIT The MIT license.
16
 * @link       https://github.com/paul-thebaud/phpunit-generator
17
 * @since      Class available since Release 2.0.0.
18
 */
19
trait ParamTrait
20
{
21
    /**
22
     * Retrieve the parameter model of a param node.
23
     *
24
     * @param Node\Param $node The param node.
25
     *
26
     * @return ParameterModelInterface The parameter model.
27
     */
28
    protected function parseParam(Node\Param $node): ParameterModelInterface
29
    {
30
        /** @todo Add a typeTrait and a valueTrait */
31
        /** @todo Move in a NodeParserInterface */
32
        $parameter = new ParameterModel();
33
        $parameter->setName($node->name);
34
        $parameter->setIsVariadic($node->variadic);
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return PhpUnitGen\Model\ModelIn...ParameterModelInterface. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
35
    }
36
}
37