Completed
Push — master ( 785c2a...666091 )
by Peter
06:01
created

Namer::defaults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/zamm
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 *
11
 */
12
13
namespace Maslosoft\Zamm;
14
15
use Maslosoft\Zamm\Helpers\InlineWrapper;
16
use Maslosoft\Zamm\Interfaces\SourceAccessorInterface;
17
use ReflectionClass;
18
19
/**
20
 * This simply return names of methods and properties.
21
 * This is helper for IDE's.
22
 * Use this together with @var type hint.
23
 *
24
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
25
 */
26
class Namer implements SourceAccessorInterface
27
{
28
29
	use Traits\SourceMagic;
30
31
	/**
32
	 * Working class name
33
	 * @var string
34
	 */
35
	protected $className = '';
36
	protected $info = null;
37
38
	/**
39
	 *
40
	 * @var ApiUrl
41
	 */
42
	protected $link = null;
43
44
	public function __construct($className = null)
45
	{
46
		$this->className = $className;
47
		$this->info = new ReflectionClass($this->className);
48
		$this->link = new ApiUrl($className);
49
	}
50
51
	/**
52
	 * Set wrapper defaults
53
	 * @return InlineWrapper
54
	 */
55
	public static function defaults()
56
	{
57
		return InlineWrapper::defaults();
58
	}
59
60
	public function __get($name)
61
	{
62
		// This is to get class name formatted, without invoking property()
63
		if ($name === 'md' || $name === 'html' || $name === 'short')
64
		{
65
			if (!$this->info->hasProperty($name))
66
			{
67
				return (new InlineWrapper($this->_type(), (string) $this->link))->$name;
68
			}
69
		}
70
		return $this->_get($name);
71
	}
72
73
	public function method($name)
74
	{
75
		assert($this->info->hasMethod($name));
76
		$link = $this->link->method($name);
77
		return new InlineWrapper($this->_method($name), $link);
78
	}
79
80
	protected function _method($name)
81
	{
82
		return sprintf('%s::%s()', $this->className, $name);
83
	}
84
85
	public function property($name)
86
	{
87
		assert($this->info->hasProperty($name));
88
		$link = $this->link->property($name);
89
		return new InlineWrapper($this->_property($name), $link);
90
	}
91
92
	protected function _property($name)
93
	{
94
		return sprintf('%s::%s', $this->className, $name);
95
	}
96
97
	public static function __callStatic($name, $arguments)
98
	{
99
		return new InlineWrapper(sprintf('%s', $name));
100
	}
101
102
	protected function _type()
103
	{
104
		return $this->className;
105
	}
106
107
	public function __toString()
108
	{
109
		$link = (string) $this->link;
110
		return (string) new InlineWrapper($this->_type(), $link);
111
	}
112
113
}
114