Completed
Push — develop ( a89061...54507c )
by Jaap
08:53
created

Descriptor/Builder/Reflector/PropertyAssembler.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
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2018 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Descriptor\Builder\Reflector;
14
15
use phpDocumentor\Descriptor\PropertyDescriptor;
16
use phpDocumentor\Reflection\ClassReflector\PropertyReflector;
17
use phpDocumentor\Reflection\Php\Property;
18
19
/**
20
 * Assembles a PropertyDescriptor from a PropertyReflector.
21
 */
22
class PropertyAssembler extends AssemblerAbstract
23
{
24
    /**
25
     * Creates a Descriptor from the provided data.
26
     *
27
     * @param Property $data
28
     *
29
     * @return PropertyDescriptor
30
     */
31 1
    public function create($data)
32
    {
33 1
        $propertyDescriptor = new PropertyDescriptor();
34 1
        $propertyDescriptor->setNamespace(substr($data->getFqsen(), 0, -strlen($data->getName()) - 3));
35 1
        $propertyDescriptor->setFullyQualifiedStructuralElementName($data->getFqsen());
36 1
        $propertyDescriptor->setName($data->getName());
37 1
        $propertyDescriptor->setVisibility($data->getVisibility() ?: 'public');
0 ignored issues
show
It seems like $data->getVisibility() ?: 'public' can also be of type object<phpDocumentor\Reflection\Php\Visibility>; however, phpDocumentor\Descriptor...riptor::setVisibility() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
38 1
        $propertyDescriptor->setStatic($data->isStatic());
39 1
        $propertyDescriptor->setDefault($data->getDefault());
40
41 1
        $this->assembleDocBlock($data->getDocBlock(), $propertyDescriptor);
42 1
        $propertyDescriptor->setLine($data->getLocation()->getLineNumber());
43
44 1
        return $propertyDescriptor;
45
    }
46
}
47