Method   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 10
c 0
b 0
f 0
ccs 29
cts 29
cp 1
wmc 8
lcom 1
cbo 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 0 4 1
A doCreate() 0 33 4
A buildVisibility() 0 10 3
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
 * @copyright 2010-2018 Mike van Riel<[email protected]>
11
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
12
 * @link      http://phpdoc.org
13
 */
14
15
namespace phpDocumentor\Reflection\Php\Factory;
16
17
use phpDocumentor\Reflection\Location;
18
use phpDocumentor\Reflection\Php\Method as MethodDescriptor;
19
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
20
use phpDocumentor\Reflection\Php\StrategyContainer;
21
use phpDocumentor\Reflection\Php\Visibility;
22
use phpDocumentor\Reflection\TypeResolver;
23
use phpDocumentor\Reflection\Types\Context;
24
use PhpParser\Node\NullableType;
25
use PhpParser\Node\Stmt\ClassMethod;
26
27
/**
28
 * Strategy to create MethodDescriptor and arguments when applicable.
29
 */
30
final class Method extends AbstractFactory implements ProjectFactoryStrategy
31
{
32 1
    public function matches($object): bool
33
    {
34 1
        return $object instanceof ClassMethod;
35
    }
36
37
    /**
38
     * Creates an MethodDescriptor out of the given object including its child elements.
39
     *
40
     * @param ClassMethod $object object to convert to an MethodDescriptor
41
     * @param StrategyContainer $strategies used to convert nested objects.
42
     * @param Context $context of the created object
43
     * @return MethodDescriptor
44
     */
45 6
    protected function doCreate($object, StrategyContainer $strategies, ?Context $context = null)
46
    {
47 6
        $docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context);
48
49 6
        $returnType = null;
50 6
        if ($object->getReturnType() !== null) {
51 2
            $typeResolver = new TypeResolver();
52 2
            if ($object->getReturnType() instanceof NullableType) {
53 1
                $typeString = '?' . $object->getReturnType()->type;
54
            } else {
55 1
                $typeString = (string) $object->getReturnType();
56
            }
57
58 2
            $returnType = $typeResolver->resolve($typeString, $context);
59
        }
60
61 6
        $method = new MethodDescriptor(
62 6
            $object->fqsen,
63 6
            $this->buildVisibility($object),
64 6
            $docBlock,
65 6
            $object->isAbstract(),
66 6
            $object->isStatic(),
67 6
            $object->isFinal(),
68 6
            new Location($object->getLine()),
69 6
            $returnType
70
        );
71
72 6
        foreach ($object->params as $param) {
73 1
            $method->addArgument($this->createMember($param, $strategies, $context));
0 ignored issues
show
Documentation introduced by
$this->createMember($par... $strategies, $context) is of type object<phpDocumentor\Reflection\Element>, but the function expects a object<phpDocumentor\Reflection\Php\Argument>.

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...
74
        }
75
76 6
        return $method;
77
    }
78
79
    /**
80
     * Converts the visibility of the method to a valid Visibility object.
81
     */
82 6
    private function buildVisibility(ClassMethod $node): Visibility
83
    {
84 6
        if ($node->isPrivate()) {
85 4
            return new Visibility(Visibility::PRIVATE_);
86 2
        } elseif ($node->isProtected()) {
87 1
            return new Visibility(Visibility::PROTECTED_);
88
        }
89
90 1
        return new Visibility(Visibility::PUBLIC_);
91
    }
92
}
93