Completed
Push — master ( 64c636...db7c78 )
by Peter
01:59
created

Namer   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 9
c 6
b 1
f 0
lcom 1
cbo 2
dl 0
loc 53
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __get() 0 11 4
A method() 0 5 1
A property() 0 5 1
A __callStatic() 0 4 1
A __toString() 0 4 1
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
	private $className = '';
36
	private $info = null;
37
38
	public function __construct($className = null)
39
	{
40
		$this->className = $className;
41
		$this->info = new ReflectionClass($this->className);
42
	}
43
	
44
	public function __get($name)
45
	{
46
		if($name == 'md' || $name == 'html')
47
		{
48
			if(!$this->info->hasProperty($name))
49
			{
50
				return (new InlineWrapper($this->className))->$name;
51
			}
52
		}
53
		return parent::__get($name);
54
	}
55
56
	public function method($name)
57
	{
58
		assert($this->info->hasMethod($name));
59
		return new InlineWrapper(sprintf('%s::%s()', $this->className, $name));
60
	}
61
62
	public function property($name)
63
	{
64
		assert($this->info->hasProperty($name));
65
		return new InlineWrapper(sprintf('%s::%s', $this->className, $name));
66
	}
67
68
	public static function __callStatic($name, $arguments)
69
	{
70
		return new InlineWrapper(sprintf('%s', $name));
71
	}
72
73
	public function __toString()
74
	{
75
		return $this->className;
76
	}
77
78
}
79