Completed
Push — master ( d917c4...8e6dfe )
by Peter
02:04
created

Namer   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 8
Bugs 1 Features 0
Metric Value
wmc 13
c 8
b 1
f 0
lcom 1
cbo 3
dl 0
loc 79
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B __get() 0 12 5
A method() 0 6 1
A _method() 0 4 1
A property() 0 6 1
A _property() 0 4 1
A __callStatic() 0 4 1
A _type() 0 4 1
A __toString() 0 5 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
	protected $className = '';
36
	protected $info = null;
37
38
	/**
39
	 *
40
	 * @var ApiLink
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);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Maslosoft\Zamm\ApiUrl($className) of type object<Maslosoft\Zamm\ApiUrl> is incompatible with the declared type object<Maslosoft\Zamm\ApiLink> of property $link.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
	}
50
51
	public function __get($name)
52
	{
53
		// This is to get class name formatted, without invoking property()
54
		if ($name === 'md' || $name === 'html' || $name === 'short')
55
		{
56
			if (!$this->info->hasProperty($name))
57
			{
58
				return (new InlineWrapper($this->_type(), (string) $this->link))->$name;
59
			}
60
		}
61
		return $this->_get($name);
62
	}
63
64
	public function method($name)
65
	{
66
		assert($this->info->hasMethod($name));
67
		$link = $this->link->method($name, $name);
68
		return new InlineWrapper($this->_method($name), $link);
69
	}
70
71
	protected function _method($name)
72
	{
73
		return sprintf('%s::%s()', $this->className, $name);
74
	}
75
76
	public function property($name)
77
	{
78
		assert($this->info->hasProperty($name));
79
		$link = $this->link->property($name);
80
		return new InlineWrapper($this->_property($name), $link);
81
	}
82
83
	protected function _property($name)
84
	{
85
		return sprintf('%s::%s', $this->className, $name);
86
	}
87
88
	public static function __callStatic($name, $arguments)
89
	{
90
		return new InlineWrapper(sprintf('%s', $name));
91
	}
92
93
	protected function _type()
94
	{
95
		return $this->className;
96
	}
97
98
	public function __toString()
99
	{
100
		$link = (string) $this->link;
101
		return (string) new InlineWrapper($this->_type(), $link);
102
	}
103
104
}
105