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

ClassTreeBuilder::execute()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 10
nc 8
nop 1
dl 0
loc 19
rs 8.8571
c 0
b 0
f 0
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-2017 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\Compiler\Pass;
14
15
use phpDocumentor\Compiler\CompilerPassInterface;
16
use phpDocumentor\Descriptor\ClassDescriptor;
17
use phpDocumentor\Descriptor\ProjectDescriptor;
18
use phpDocumentor\Reflection\Fqsen;
19
20
final class ClassTreeBuilder implements CompilerPassInterface
21
{
22
    const COMPILER_PRIORITY = 9000;
23
24
    /**
25
     * Returns a textual description of what this pass does for output purposes.
26
     *
27
     * Please note that the command line will be truncated to 68 characters (<message> .. 000.000s) so longer
28
     * descriptions won't have much use.
29
     *
30
     * @return string
31
     */
32
    public function getDescription()
33
    {
34
        return "Adding Parents to child classes";
35
    }
36
37
    /**
38
     * Executes a compiler pass.
39
     *
40
     * This method will execute the business logic associated with a given compiler pass and allow it to manipulate
41
     * or consumer the Object Graph using the ProjectDescriptor object.
42
     *
43
     * @param ProjectDescriptor $project Representation of the Object Graph that can be manipulated.
44
     *
45
     * @return mixed
46
     */
47
    public function execute(ProjectDescriptor $project)
48
    {
49
        foreach ($project->getFiles() as $file) {
50
            /** @var ClassDescriptor $class */
51
            foreach ($file->getClasses()->getAll() as $class) {
52
                if ($class->getParent() instanceof Fqsen) {
53
                    $parent = $project->getIndexes()->get('classes')->get((string)$class->getParent());
54
                    if ($parent instanceof ClassDescriptor) {
55
                        $class->setParent($parent);
56
                    }
57
                }
58
59
                foreach ($class->getInterfaces()->getAll() as $interface) {
60
                    $interfaceDescriptor = $project->getIndexes()->get('interfaces')->get((string)$interface);
61
                    $class->getInterfaces()->set((string)$interface, $interfaceDescriptor);
62
                }
63
            }
64
        }
65
    }
66
}
67