1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flagbit\Plantuml\TokenReflection; |
4
|
|
|
|
5
|
|
|
use TokenReflection\IReflectionMethod; |
6
|
|
|
use TokenReflection\IReflectionParameter; |
7
|
|
|
|
8
|
|
View Code Duplication |
class MethodGroupingWriter extends MethodWriter |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param IReflectionMethod[] $methods |
12
|
|
|
* @return string |
13
|
|
|
*/ |
14
|
1 |
|
public function writeElements(array $methods) |
15
|
|
|
{ |
16
|
1 |
|
$groups = array('other'=>array() ,'deprecated'=>array() ,'todo'=>array() ); |
17
|
1 |
|
foreach ($methods as $method) { |
18
|
1 |
|
if($this->isTodo($method)){ |
19
|
1 |
|
$groups['todo'][] = $method; |
20
|
1 |
|
} else if($this->isDeprecated($method)){ |
21
|
1 |
|
$groups['deprecated'][] = $method; |
22
|
1 |
|
} else { |
23
|
1 |
|
$groups['other'][] = $method; |
24
|
|
|
} |
25
|
1 |
|
} |
26
|
1 |
|
$methodsString = $this->formatLine($this->writeSeparator()); |
27
|
1 |
|
if (!empty($groups['other'])) { |
28
|
1 |
|
$methodsString .= parent::writeElements($groups['other']); |
29
|
1 |
|
} |
30
|
1 |
|
if (!empty($groups['todo'])) { |
31
|
1 |
|
$methodsString .= $this->formatLine($this->writeTodo()); |
32
|
1 |
|
$methodsString .= parent::writeElements($groups['todo']); |
33
|
1 |
|
} |
34
|
1 |
|
if (!empty($groups['deprecated'])) { |
35
|
1 |
|
$methodsString .= $this->formatLine($this->writeDeprecated()); |
36
|
1 |
|
$methodsString .= parent::writeElements($groups['deprecated']); |
37
|
1 |
|
} |
38
|
1 |
|
return $methodsString; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param \TokenReflection\IReflectionMethod $method |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
1 |
|
private function isDeprecated(IReflectionMethod $method) |
46
|
|
|
{ |
47
|
1 |
|
$returnBool = false; |
48
|
1 |
|
preg_match('/\*\h+@deprecated/', (string) $method->getDocComment(), $matches); |
49
|
1 |
|
if (isset($matches[0])) { |
50
|
1 |
|
$returnBool = true; |
51
|
1 |
|
} |
52
|
1 |
|
return $returnBool; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param \TokenReflection\IReflectionMethod $method |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
1 |
|
private function isTodo(IReflectionMethod $method) |
60
|
|
|
{ |
61
|
1 |
|
$returnBool = false; |
62
|
1 |
|
preg_match('/\*\h+@todo/', (string) $method->getDocComment(), $matches); |
63
|
1 |
|
if (isset($matches[0])) { |
64
|
1 |
|
$returnBool = true; |
65
|
1 |
|
} |
66
|
1 |
|
return $returnBool; |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
private function writeDeprecated() |
70
|
|
|
{ |
71
|
1 |
|
return "-- deprecated --"; |
72
|
|
|
} |
73
|
|
|
|
74
|
1 |
|
private function writeTodo() |
75
|
|
|
{ |
76
|
1 |
|
return "-- todo --"; |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
private function writeSeparator() |
80
|
|
|
{ |
81
|
1 |
|
return "=="; |
82
|
|
|
} |
83
|
|
|
} |
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.