Completed
Push — develop ( 2993ce...48a3ec )
by Mike
09:32
created

ArgumentAssembler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 16 2
A overwriteTypeAndDescriptionFromParamTag() 0 12 2
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 3
    public function create($data, $params = [])
36
    {
37 3
        $argumentDescriptor = new ArgumentDescriptor();
38 3
        $argumentDescriptor->setName($data->getName());
39 3
        $argumentDescriptor->setType($data->getType());
40
41 3
        foreach ($params as $paramDescriptor) {
42 2
            $this->overwriteTypeAndDescriptionFromParamTag($data, $paramDescriptor, $argumentDescriptor);
43
        }
44
45 3
        $argumentDescriptor->setDefault($data->getDefault());
46 3
        $argumentDescriptor->setByReference($data->isByReference());
47 3
        $argumentDescriptor->setVariadic($data->isVariadic());
48
49 3
        return $argumentDescriptor;
50
    }
51
52
    /**
53
     * Overwrites the type and description in the Argument Descriptor with that from the tag if the names match.
54
     */
55 1
    protected function overwriteTypeAndDescriptionFromParamTag(
56
        Argument  $argument,
57
        ParamDescriptor    $paramDescriptor,
58
        ArgumentDescriptor $argumentDescriptor
59
    ): void {
60 1
        if ($paramDescriptor->getVariableName() !== $argument->getName()) {
61
            return;
62
        }
63
64 1
        $argumentDescriptor->setDescription($paramDescriptor->getDescription());
65 1
        $argumentDescriptor->setType($paramDescriptor->getType());
66 1
    }
67
}
68