Completed
Pull Request — master (#10)
by
unknown
03:21
created

PropertyGroupingWriter::writeElements()   C

Complexity

Conditions 7
Paths 32

Size

Total Lines 26
Code Lines 19

Duplication

Lines 26
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 26
loc 26
rs 6.7272
cc 7
eloc 19
nc 32
nop 1
1
<?php
2
3
namespace Flagbit\Plantuml\TokenReflection;
4
5
use TokenReflection\IReflectionProperty;
6
7 View Code Duplication
class PropertyGroupingWriter extends PropertyWriter
0 ignored issues
show
Duplication introduced by
This class 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...
8
{
9
    /**
10
     * @param IReflectionProperty[] $properties
11
     * @return string
12
     */
13
    public function writeElements(array $properties)
14
    {
15
        $groups = array('other'=>[],'deprecated'=>[],'todo'=>[]);
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
}