Completed
Push — develop ( 9193e7...62056c )
by Jaap
12:45 queued 02:43
created

Descriptor/Builder/Reflector/FileAssembler.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;
13
14
use phpDocumentor\Descriptor\Collection;
15
use phpDocumentor\Descriptor\FileDescriptor;
16
use phpDocumentor\Descriptor\TagDescriptor;
17
use phpDocumentor\Reflection\ClassReflector;
18
use phpDocumentor\Reflection\ConstantReflector;
19
use phpDocumentor\Reflection\FileReflector;
20
use phpDocumentor\Reflection\FunctionReflector;
21
use phpDocumentor\Reflection\InterfaceReflector;
22
use phpDocumentor\Reflection\TraitReflector;
23
24
/**
25
 * Assembles an FileDescriptor using an FileReflector and ParamDescriptors.
26
 */
27
class FileAssembler extends AssemblerAbstract
28
{
29
    /**
30
     * Creates a Descriptor from the provided data.
31
     *
32
     * @param FileReflector $data
33
     *
34
     * @return FileDescriptor
35
     */
36 1
    public function create($data)
37
    {
38 1
        $fileDescriptor = new FileDescriptor($data->getHash());
39
40 1
        $fileDescriptor->setPackage(
41 1
            $this->extractPackageFromDocBlock($data->getDocBlock()) ?: $data->getDefaultPackageName()
0 ignored issues
show
$this->extractPackageFro...getDefaultPackageName() is of type string, but the function expects a object<phpDocumentor\Des...ptor\PackageDescriptor>.

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...
42 1
        );
43
44 1
        $fileDescriptor->setName(basename($data->getFilename()));
45 1
        $fileDescriptor->setPath($data->getFilename());
46 1
        if ($this->getBuilder()->getProjectDescriptor()->getSettings()->shouldIncludeSource()) {
47 1
            $fileDescriptor->setSource($data->getContents());
48 1
        }
49
        $fileDescriptor->setIncludes(new Collection($data->getIncludes()));
50 1
        $fileDescriptor->setNamespaceAliases(new Collection($data->getNamespaceAliases()));
51 1
52
        $this->assembleDocBlock($data->getDocBlock(), $fileDescriptor);
53 1
        $this->overridePackageTag($data, $fileDescriptor);
54 1
55 1
        $this->addMarkers($data->getMarkers(), $fileDescriptor);
56 1
        $this->addConstants($data->getConstants(), $fileDescriptor);
57 1
        $this->addFunctions($data->getFunctions(), $fileDescriptor);
58 1
        $this->addClasses($data->getClasses(), $fileDescriptor);
59
        $this->addInterfaces($data->getInterfaces(), $fileDescriptor);
60 1
        $this->addTraits($data->getTraits(), $fileDescriptor);
61
62
        return $fileDescriptor;
63
    }
64
65
    /**
66
     * Registers the child constants with the generated File Descriptor.
67
     *
68
     * @param ConstantReflector[] $constants
69
     * @param FileDescriptor      $fileDescriptor
70
     *
71 1
     * @return void
72
     */
73 1
    protected function addConstants($constants, $fileDescriptor)
74 1
    {
75 1
        foreach ($constants as $constant) {
76 1
            $constantDescriptor = $this->getBuilder()->buildDescriptor($constant);
77 1
            if ($constantDescriptor) {
78 1
                $constantDescriptor->setLocation($fileDescriptor, $constant->getLineNumber());
79 1
                if (count($constantDescriptor->getTags()->get('package', new Collection())) == 0) {
80 1
                    $constantDescriptor->getTags()
81
                        ->set('package', $fileDescriptor->getTags()->get('package', new Collection()));
82 1
                }
83 1
84
                $fileDescriptor->getConstants()->set(
85 1
                    $constantDescriptor->getFullyQualifiedStructuralElementName(),
86 1
                    $constantDescriptor
87 1
                );
88 1
            }
89
        }
90
    }
91
92
    /**
93
     * Registers the child functions with the generated File Descriptor.
94
     *
95
     * @param FunctionReflector[] $functions
96
     * @param FileDescriptor      $fileDescriptor
97
     *
98 1
     * @return void
99
     */
100 1
    protected function addFunctions($functions, $fileDescriptor)
101 1
    {
102 1
        foreach ($functions as $function) {
103 1
            $functionDescriptor = $this->getBuilder()->buildDescriptor($function);
104 1
            if ($functionDescriptor) {
105 1
                $functionDescriptor->setLocation($fileDescriptor, $function->getLineNumber());
106 1
                if (count($functionDescriptor->getTags()->get('package', new Collection())) == 0) {
107 1
                    $functionDescriptor->getTags()
108
                        ->set('package', $fileDescriptor->getTags()->get('package', new Collection()));
109 1
                }
110 1
111
                $fileDescriptor->getFunctions()->set(
112 1
                    $functionDescriptor->getFullyQualifiedStructuralElementName(),
113 1
                    $functionDescriptor
114 1
                );
115 1
            }
116
        }
117
    }
118
119
    /**
120
     * Registers the child classes with the generated File Descriptor.
121
     *
122
     * @param ClassReflector[] $classes
123
     * @param FileDescriptor   $fileDescriptor
124
     *
125 1
     * @return void
126
     */
127 1
    protected function addClasses($classes, $fileDescriptor)
128 1
    {
129 1
        foreach ($classes as $class) {
130 1
            $classDescriptor = $this->getBuilder()->buildDescriptor($class);
131 1
            if ($classDescriptor) {
132 1
                $classDescriptor->setLocation($fileDescriptor, $class->getLineNumber());
133 1
                if (count($classDescriptor->getTags()->get('package', new Collection())) == 0) {
134 1
                    $classDescriptor->getTags()->set(
135 1
                        'package',
136 1
                        $fileDescriptor->getTags()->get('package', new Collection())
137
                    );
138 1
                }
139 1
140
                $fileDescriptor->getClasses()->set(
141 1
                    $classDescriptor->getFullyQualifiedStructuralElementName(),
142 1
                    $classDescriptor
143 1
                );
144 1
            }
145
        }
146
    }
147
148
    /**
149
     * Registers the child interfaces with the generated File Descriptor.
150
     *
151
     * @param InterfaceReflector[] $interfaces
152
     * @param FileDescriptor   $fileDescriptor
153
     *
154 1
     * @return void
155
     */
156 1
    protected function addInterfaces($interfaces, $fileDescriptor)
157 1
    {
158 1
        foreach ($interfaces as $interface) {
159 1
            $interfaceDescriptor = $this->getBuilder()->buildDescriptor($interface);
160 1
            if ($interfaceDescriptor) {
161 1
                $interfaceDescriptor->setLocation($fileDescriptor, $interface->getLineNumber());
162 1
                if (count($interfaceDescriptor->getTags()->get('package', new Collection())) == 0) {
163 1
                    $interfaceDescriptor->getTags()
164
                        ->set('package', $fileDescriptor->getTags()->get('package', new Collection()));
165 1
                }
166 1
167
                $fileDescriptor->getInterfaces()->set(
168 1
                    $interfaceDescriptor->getFullyQualifiedStructuralElementName(),
169 1
                    $interfaceDescriptor
170 1
                );
171 1
            }
172
        }
173
    }
174
175
    /**
176
     * Registers the child traits with the generated File Descriptor.
177
     *
178
     * @param TraitReflector[] $traits
179
     * @param FileDescriptor   $fileDescriptor
180
     *
181 1
     * @return void
182
     */
183 1
    protected function addTraits($traits, $fileDescriptor)
184 1
    {
185 1
        foreach ($traits as $trait) {
186 1
            $traitDescriptor = $this->getBuilder()->buildDescriptor($trait);
187 1
            if ($traitDescriptor) {
188 1
                $traitDescriptor->setLocation($fileDescriptor, $trait->getLineNumber());
189 1
                if (count($traitDescriptor->getTags()->get('package', new Collection())) == 0) {
190 1
                    $traitDescriptor->getTags()
191
                        ->set('package', $fileDescriptor->getTags()->get('package', new Collection()));
192 1
                }
193 1
194
                $fileDescriptor->getTraits()->set(
195 1
                    $traitDescriptor->getFullyQualifiedStructuralElementName(),
196 1
                    $traitDescriptor
197 1
                );
198 1
            }
199
        }
200
    }
201
202
    /**
203
     * Registers the markers that were found in a File with the File Descriptor.
204
     *
205
     * @param string[]       $markers
206
     * @param FileDescriptor $fileDescriptor
207
     *
208 1
     * @return void
209
     */
210 1
    protected function addMarkers($markers, $fileDescriptor)
211 1
    {
212 1
        foreach ($markers as $marker) {
213
            list($type, $message, $line) = $marker;
214 1
            $fileDescriptor->getMarkers()->add(
215 1
                array(
216 1
                    'type'    => $type,
217
                    'message' => $message,
218 1
                    'line'    => $line,
219 1
                )
220 1
            );
221
        }
222
    }
223
224
    /**
225
     * @param $data
226 1
     * @param $fileDescriptor
227
     */
228 1
    protected function overridePackageTag($data, $fileDescriptor)
229 1
    {
230 1
        $packages = new Collection();
231 1
        $package  = $this->extractPackageFromDocBlock($data->getDocBlock());
232 1
        if (! $package) {
233 1
            $package = $data->getDefaultPackageName();
234 1
        }
235 1
        $tag = new TagDescriptor('package');
236 1
        $tag->setDescription($package);
237 1
        $packages->add($tag);
238
        $fileDescriptor->getTags()->set('package', $packages);
239
    }
240
}
241