Completed
Push — master ( ce62ef...a1e916 )
by Thomas
02:37
created

QualifiedNamePart::getQualifiedName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
namespace gossi\codegen\model\parts;
3
4
/**
5
 * Qualified name part
6
 *
7
 * For all models that have a name and namespace
8
 *
9
 * @author Thomas Gossmann
10
 */
11
trait QualifiedNamePart {
12
13
	use NamePart;
14
15
	/** @var string */
16
	private $namespace;
17
18
	/**
19
	 * Sets the namespace
20
	 *
21
	 * @param string $namespace
22
	 * @return $this
23
	 */
24 10
	public function setNamespace($namespace) {
25 10
		$this->namespace = $namespace;
26
27 10
		return $this;
28
	}
29
30
	/**
31
	 * In contrast to setName(), this method accepts the fully qualified name
32
	 * including the namespace.
33
	 *
34
	 * @param string $name
35
	 * @return $this
36
	 */
37 63
	public function setQualifiedName($name) {
38 63
		if (false !== $pos = strrpos($name, '\\')) {
39 10
			$this->namespace = trim(substr($name, 0, $pos), '\\');
40 10
			$this->name = substr($name, $pos + 1);
41
42 10
			return $this;
43
		}
44
45 59
		$this->namespace = null;
46 59
		$this->name = $name;
47
48 59
		return $this;
49
	}
50
51
	/**
52
	 * Returns the namespace
53
	 *
54
	 * @return string
55
	 */
56 24
	public function getNamespace() {
57 24
		return $this->namespace;
58
	}
59
60
	/**
61
	 * Returns the qualified name
62
	 *
63
	 * @return string
64
	 */
65 5
	public function getQualifiedName() {
66 5
		if ($this->namespace) {
67 5
			return $this->namespace . '\\' . $this->name;
68
		}
69
70 1
		return $this->name;
71
	}
72
}
73