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

QualifiedNamePart   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
c 1
b 1
f 0
lcom 1
cbo 1
dl 0
loc 62
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setNamespace() 0 5 1
A setQualifiedName() 0 13 2
A getNamespace() 0 3 1
A getQualifiedName() 0 7 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