1: <?php
2: namespace Pharborist\Namespaces;
3:
4: use Pharborist\TokenNode;
5:
6: 7: 8: 9: 10:
11: trait IdentifierNameTrait {
12: 13: 14:
15: protected $name;
16:
17: 18: 19:
20: public function getName() {
21: return $this->name;
22: }
23:
24: 25: 26:
27: public function getNamespace() {
28: return $this->name->getNamespace();
29: }
30:
31: 32: 33: 34: 35: 36: 37:
38: public function setName($name) {
39:
40: $identifier = $this->name->firstChild();
41: $identifier->setText($name);
42: return $this;
43: }
44:
45: 46: 47: 48: 49: 50: 51: 52: 53:
54: public function inNamespace($ns) {
55: if (is_string($ns)) {
56: $namespace_node = $this->name->getNamespace();
57: $namespace = $namespace_node === NULL ? '' : $namespace_node->getName()->getAbsolutePath();
58: return $ns === $namespace;
59: }
60: elseif ($ns instanceof NamespaceNode) {
61: return $this->name->getNamespace() === $ns;
62: }
63: else {
64: throw new \InvalidArgumentException();
65: }
66: }
67: }
68: