Completed
Push — develop ( 0b8425...c51867 )
by Jaap
15s queued 11s
created

Descriptor/Builder/Reflector/TraitAssembler.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
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\MethodDescriptor;
19
use phpDocumentor\Descriptor\PropertyDescriptor;
20
use phpDocumentor\Descriptor\TraitDescriptor;
21
use phpDocumentor\Reflection\Php\Method;
22
use phpDocumentor\Reflection\Php\Property;
23
use phpDocumentor\Reflection\Php\Trait_;
24
25
/**
26
 * Assembles an TraitDescriptor using an TraitReflector.
27
 */
28
class TraitAssembler extends AssemblerAbstract
29
{
30
    /**
31
     * Creates a Descriptor from the provided data.
32
     *
33
     * @param Trait_ $data
34
     *
35
     * @return TraitDescriptor
36
     */
37 1
    public function create($data)
38
    {
39 1
        $traitDescriptor = new TraitDescriptor();
40
41 1
        $traitDescriptor->setFullyQualifiedStructuralElementName($data->getFqsen());
42 1
        $traitDescriptor->setName($data->getName());
43 1
        $traitDescriptor->setLine($data->getLocation()->getLineNumber());
44 1
        $traitDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: '');
0 ignored issues
show
$this->extractPackageFro...a->getDocBlock()) ?: '' 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...
45
46
        // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself
47 1
        $traitDescriptor->setNamespace(
48 1
            substr((string) $data->getFqsen(), 0, -strlen($data->getName()) - 1)
49
        );
50
51 1
        $this->assembleDocBlock($data->getDocBlock(), $traitDescriptor);
52
53 1
        $this->addProperties($data->getProperties(), $traitDescriptor);
54 1
        $this->addMethods($data->getMethods(), $traitDescriptor);
55
56 1
        return $traitDescriptor;
57
    }
58
59
    /**
60
     * Registers the child properties with the generated Trait Descriptor.
61
     *
62
     * @param Property[] $properties
63
     */
64
    protected function addProperties(array $properties, TraitDescriptor $traitDescriptor): void
65
    {
66
        foreach ($properties as $property) {
67
            $propertyDescriptor = $this->getBuilder()->buildDescriptor($property);
68
            if ($propertyDescriptor instanceof PropertyDescriptor) {
69
                $propertyDescriptor->setParent($traitDescriptor);
70
                $traitDescriptor->getProperties()->set($propertyDescriptor->getName(), $propertyDescriptor);
71
            }
72
        }
73
    }
74
75
    /**
76
     * Registers the child methods with the generated Trait Descriptor.
77
     *
78
     * @param Method[] $methods
79
     */
80
    protected function addMethods(array $methods, TraitDescriptor $traitDescriptor): void
81
    {
82
        foreach ($methods as $method) {
83
            $methodDescriptor = $this->getBuilder()->buildDescriptor($method);
84
            if ($methodDescriptor instanceof MethodDescriptor) {
85
                $methodDescriptor->setParent($traitDescriptor);
86
                $traitDescriptor->getMethods()->set($methodDescriptor->getName(), $methodDescriptor);
87
            }
88
        }
89
    }
90
}
91