|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Padawan\Domain\Project; |
|
4
|
|
|
|
|
5
|
|
|
class FQCN extends FQN { |
|
6
|
|
|
|
|
7
|
|
|
public function __get($key) { |
|
8
|
|
|
if ($key === "className") { |
|
9
|
|
|
return $this->getClassName(); |
|
10
|
|
|
} |
|
11
|
|
|
elseif ($key === "namespace") { |
|
12
|
|
|
return $this->getNamespace(); |
|
13
|
|
|
} |
|
14
|
|
|
} |
|
15
|
|
|
public function __construct($className, $namespace = "", $isArray = false) { |
|
16
|
|
|
parent::__construct($namespace); |
|
17
|
|
|
$this->_isArray = $isArray; |
|
18
|
|
|
$this->_isScalar = false; |
|
19
|
|
|
if (count($this->parts) === 0) { |
|
|
|
|
|
|
20
|
|
|
switch ($className) { |
|
21
|
|
|
case "int": |
|
22
|
|
|
case "string": |
|
23
|
|
|
case "float": |
|
24
|
|
|
case "array": |
|
25
|
|
|
case "mixed": |
|
26
|
|
|
case "void": |
|
27
|
|
|
case "object": |
|
28
|
|
|
case "bool": |
|
29
|
|
|
case "null": |
|
30
|
|
|
case "false": |
|
31
|
|
|
case "true": |
|
32
|
|
|
$this->_isScalar = true; |
|
33
|
|
|
break; |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
$this->addPart($className); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritdoc |
|
41
|
|
|
*/ |
|
42
|
|
View Code Duplication |
public function join(FQN $join) { |
|
|
|
|
|
|
43
|
|
|
$result = new self($join->getLast()); |
|
44
|
|
|
$resultParts = $this->getParts(); |
|
45
|
|
|
$joiningParts = $join->getParts(); |
|
46
|
|
|
if ($this->getLast() === $join->getFirst()) { |
|
47
|
|
|
array_shift($joiningParts); |
|
48
|
|
|
} |
|
49
|
|
|
$result->setParts(array_merge($resultParts, $joiningParts)); |
|
50
|
|
|
return $result; |
|
51
|
|
|
} |
|
52
|
|
|
public function getClassName() { |
|
53
|
|
|
return $this->getLast(); |
|
54
|
|
|
} |
|
55
|
|
|
public function getNamespace() { |
|
56
|
|
|
$parts = $this->getParts(); |
|
57
|
|
|
array_pop($parts); |
|
58
|
|
|
return implode("\\", $parts); |
|
59
|
|
|
} |
|
60
|
|
|
public function toString() { |
|
61
|
|
|
$str = parent::toString(); |
|
62
|
|
|
if ($this->isArray()) { |
|
63
|
|
|
$str .= '[]'; |
|
64
|
|
|
} |
|
65
|
|
|
return $str; |
|
66
|
|
|
} |
|
67
|
|
|
public function isArray() { |
|
68
|
|
|
return $this->_isArray; |
|
69
|
|
|
} |
|
70
|
|
|
public function isScalar() { |
|
71
|
|
|
return $this->_isScalar; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
private $_isArray; |
|
75
|
|
|
private $_isScalar; |
|
76
|
|
|
} |
|
77
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.