Completed
Push — master ( ac571e...b4d025 )
by Peter
02:07
created

ShortNamer::method()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 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, without class name or short class name.
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 ShortNamer 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 View Code Duplication
	public function __get($name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
	{
46
		if ($name === 'md' || $name === 'html' || $name === 'short')
47
		{
48
			if (!$this->info->hasProperty($name))
49
			{
50
				return (new InlineWrapper($this->info->getShortName()))->$name;
51
			}
52
		}
53
		return $this->_get($name);
54
	}
55
56
	public function method($name)
57
	{
58
		assert($this->info->hasMethod($name));
59
		return new InlineWrapper(sprintf('%s()', $name));
60
	}
61
62
	public function property($name)
63
	{
64
		assert($this->info->hasProperty($name));
65
		return new InlineWrapper($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->info->getShortName();
76
	}
77
78
}
79