Completed
Push — develop ( 49ed8e...8c2a0b )
by Jaap
09:55
created

Builder/Reflector/Tags/MethodAssembler.php (1 issue)

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\Tags;
13
14
use phpDocumentor\Descriptor\ArgumentDescriptor;
15
use phpDocumentor\Descriptor\Builder\Reflector\AssemblerAbstract;
16
use phpDocumentor\Descriptor\Tag\MethodDescriptor;
17
use phpDocumentor\Descriptor\Tag\ReturnDescriptor;
18
use phpDocumentor\Reflection\DocBlock\Tag\MethodTag;
19
use phpDocumentor\Reflection\DocBlock\Type\Collection;
20
21
/**
22
 * Constructs a new descriptor from the Reflector for an `@method` tag.
23
 *
24
 * This object will read the reflected information for the `@method` tag and create a {@see MethodDescriptor} object
25
 * that can be used in the rest of the application and templates.
26
 */
27
class MethodAssembler extends AssemblerAbstract
28
{
29
    /**
30
     * Creates a new Descriptor from the given Reflector.
31
     *
32
     * @param MethodTag $data
33
     *
34
     * @return MethodDescriptor
35
     */
36
    public function create($data)
37
    {
38
        $descriptor = new MethodDescriptor($data->getName());
39
        $descriptor->setDescription($data->getDescription());
40
        $descriptor->setMethodName($data->getMethodName());
41
        $descriptor->setStatic($data->isStatic());
42
43
        $response = new ReturnDescriptor('return');
44
        $response->setTypes($this->builder->buildDescriptor(new Collection($data->getTypes())));
45
        $descriptor->setResponse($response);
46
47
        foreach ($data->getArguments() as $argument) {
48
            $argumentDescriptor = $this->createArgumentDescriptorForMagicMethod($argument);
49
            $descriptor->getArguments()->set($argumentDescriptor->getName(), $argumentDescriptor);
50
        }
51
52
        return $descriptor;
53
    }
54
55
    /**
56
     * Construct an argument descriptor given the array representing an argument with a Method Tag in the Reflection
57
     * component.
58
     *
59
     * @param string[] $argument
60
     *
61
     * @return ArgumentDescriptor
62
     */
63
    private function createArgumentDescriptorForMagicMethod($argument)
0 ignored issues
show
This operation has 1020 execution paths which exceeds the configured maximum of 200.

A high number of execution paths generally suggests many nested conditional statements and make the code less readible. This can usually be fixed by splitting the method into several smaller methods.

You can also find more information in the “Code” section of your repository.

Loading history...
64
    {
65
        $argumentType = null;
66
        $argumentName = null;
67
        $argumentDefault = false; // false means we have not encountered the '=' yet.
68
        foreach ($argument as $part) {
69
            $part = trim($part);
70
            if (!$part) {
71
                continue;
72
            }
73
74
            // Type should not be assigned after name
75
            if (!$argumentName && !$argumentType && $part{0} != '$') {
76
                $argumentType = $part;
77
            } elseif (!$argumentName && $part{0} == '$') {
78
                $argumentName = $part;
79
            } elseif ($part == '=') {
80
                $argumentDefault = null;
81
            } elseif ($argumentDefault === null) {
82
                $argumentDefault = $part;
83
            }
84
        }
85
        if ($argumentDefault === false) {
86
            $argumentDefault = null;
87
        }
88
89
        // if no name is set but a type is then the input is malformed and we correct for it
90
        if ($argumentType && !$argumentName) {
91
            $argumentName = $argumentType;
92
            $argumentType = null;
93
        }
94
95
        // if there is no type then we assume it is 'mixed'
96
        if (!$argumentType) {
97
            $argumentType = 'mixed';
98
        }
99
100
        $argumentDescriptor = new ArgumentDescriptor();
101
        $argumentDescriptor->setTypes($this->builder->buildDescriptor(new Collection(array($argumentType))));
102
        $argumentDescriptor->setName($argumentName[0] == '$' ? $argumentName : '$' . $argumentName);
103
        $argumentDescriptor->setDefault($argumentDefault);
104
105
        return $argumentDescriptor;
106
    }
107
}
108