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

DocBlock::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
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Zamm;
10
11
use Exception;
12
use Maslosoft\Zamm\Decorators\AnnotationRemover;
13
use Maslosoft\Zamm\Decorators\DocTagRemover;
14
use Maslosoft\Zamm\Decorators\StarRemover;
15
use Maslosoft\Zamm\Interfaces\SourceAccessorInterface;
16
use ReflectionClass;
17
18
/**
19
 * DocBlock
20
 *
21
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
22
 */
23
class DocBlock implements SourceAccessorInterface
24
{
25
26
	use Traits\SourceMagic;
27
28
	/**
29
	 *
30
	 * @var ReflectionClass
31
	 */
32
	private $info = null;
33
34
	public function __construct($className = null)
35
	{
36
		$this->info = new ReflectionClass($className);
37
	}
38
39
	public function method($name)
40
	{
41
		assert($this->info->hasMethod($name));
42
		return $this->decorate($this->info->getMethod($name)->getDocComment());
43
	}
44
45
	public function property($name)
46
	{
47
		assert($this->info->hasProperty($name));
48
		return $this->decorate($this->info->getProperty($name)->getDocComment());
49
	}
50
51
	public static function __callStatic($name, $arguments)
52
	{
53
		
54
	}
55
56
	public function __toString()
57
	{
58
		return $this->decorate($this->info->getDocComment());
59
	}
60
61
	private function decorate($docBlock)
62
	{
63
64
		try
65
		{
66
			$decorators = [
67
				new StarRemover(),
68
				new DocTagRemover(),
69
				new AnnotationRemover()
70
			];
71
			foreach ($decorators as $decorator)
72
			{
73
				$decorator->decorate($docBlock);
74
			}
75
		}
76
		catch (Exception $ex)
77
		{
78
			return $ex->getMessage();
79
		}
80
		return $docBlock;
81
	}
82
83
}
84