Project   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 89
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 2
cbo 3

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getName() 0 4 1
A getFiles() 0 4 1
A addFile() 0 4 1
A getNamespaces() 0 4 1
A addNamespace() 0 4 1
A getRootNamespace() 0 4 1
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
 * @copyright 2010-2018 Mike van Riel<[email protected]>
11
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
12
 * @link      http://phpdoc.org
13
 */
14
15
namespace phpDocumentor\Reflection\Php;
16
17
use phpDocumentor\Reflection\Fqsen;
18
use phpDocumentor\Reflection\Project as ProjectInterface;
19
20
/**
21
 * Represents the entire project with its files, namespaces and indexes.
22
 */
23
final class Project implements ProjectInterface
24
{
25
    /**
26
     * @var string
27
     */
28
    private $name = '';
29
30
    /**
31
     * @var Namespace_|null
32
     */
33
    private $rootNamespace;
34
35
    /**
36
     * @var File[]
37
     */
38
    private $files = [];
39
40
    /**
41
     * @var Namespace_[]
42
     */
43
    private $namespaces = [];
44
45
    /**
46
     * Initializes this descriptor.
47
     *
48
     * @param string $name Name of the current project.
49
     * @param null|Namespace_ $namespace Root namespace of the project.
50
     */
51 2
    public function __construct(string $name, ?Namespace_ $namespace = null)
52
    {
53 2
        $this->name = $name;
54 2
        $this->rootNamespace = $namespace;
55 2
        if ($this->rootNamespace === null) {
56 2
            $this->rootNamespace = new Namespace_(new Fqsen('\\'));
57
        }
58 2
    }
59
60
    /**
61
     * Returns the name of this project.
62
     */
63 1
    public function getName(): string
64
    {
65 1
        return $this->name;
66
    }
67
68
    /**
69
     * Returns all files with their sub-elements.
70
     *
71
     * @return File[]
72
     */
73 1
    public function getFiles(): array
74
    {
75 1
        return $this->files;
76
    }
77
78
    /**
79
     * Add a file to this project.
80
     */
81 1
    public function addFile(File $file): void
82
    {
83 1
        $this->files[$file->getPath()] = $file;
84 1
    }
85
86
    /**
87
     * Returns all namespaces with their sub-elements.
88
     *
89
     * @return Namespace_[]
90
     */
91 1
    public function getNamespaces(): array
92
    {
93 1
        return $this->namespaces;
94
    }
95
96
    /**
97
     * Add a namespace to the project.
98
     */
99 1
    public function addNamespace(Namespace_ $namespace): void
100
    {
101 1
        $this->namespaces[(string) $namespace->getFqsen()] = $namespace;
102 1
    }
103
104
    /**
105
     * Returns the root (global) namespace.
106
     */
107 1
    public function getRootNamespace(): ?Namespace_
108
    {
109 1
        return $this->rootNamespace;
110
    }
111
}
112