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