NamespaceTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setNamespace() 0 3 1
A getNamespace() 0 3 1
A getNamespaceLast() 0 5 2
A getNamespaceString() 0 5 2
1
<?php
2
3
/**
4
 * This file is part of PhpUnitGen.
5
 *
6
 * (c) 2017-2018 Paul Thébaud <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhpUnitGen\Model\PropertyTrait;
13
14
use Respect\Validation\Validator;
15
16
/**
17
 * Trait NamespaceTrait.
18
 *
19
 * @author     Paul Thébaud <[email protected]>.
20
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
21
 * @license    https://opensource.org/licenses/MIT The MIT license.
22
 * @link       https://github.com/paul-thebaud/phpunit-generator
23
 * @since      Class available since Release 2.0.0.
24
 */
25
trait NamespaceTrait
26
{
27
    /**
28
     * @var string[] $namespace A string[] describing a namespace.
29
     */
30
    protected $namespace = [];
31
32
    /**
33
     * @param string[] $namespace The new namespace to be set.
34
     */
35
    public function setNamespace(array $namespace): void
36
    {
37
        $this->namespace = $namespace;
38
    }
39
40
    /**
41
     * @return string[] The current namespace.
42
     */
43
    public function getNamespace(): array
44
    {
45
        return $this->namespace;
46
    }
47
48
    /**
49
     * @return string|null The concat namespace parts.
50
     */
51
    public function getNamespaceString(): ?string
52
    {
53
        return Validator::notEmpty()->validate($this->namespace)?
54
            implode('\\', $this->namespace) :
55
            null;
56
    }
57
58
    /**
59
     * @return string|null The last namespace part.
60
     */
61
    public function getNamespaceLast(): ?string
62
    {
63
        return Validator::notEmpty()->validate($this->namespace)?
64
            $this->namespace[(count($this->namespace) - 1)] :
65
            null;
66
    }
67
}
68