Completed
Pull Request — master (#10)
by
unknown
02:45
created

PropertyGroupingWriter::writeDeprecated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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 1
    public function writeElements(array $properties)
14
    {
15 1
        $groups = array('other'=>array(),'deprecated'=>array(),'todo'=>array());
16 1
        foreach ($properties as $property) {
17 1
            if($this->isTodo($property)){
18 1
                $groups['todo'][] = $property;
19 1
            } else if($this->isDeprecated($property)){
20 1
                $groups['deprecated'][] = $property;
21 1
            } else {
22 1
                $groups['other'][] = $property;
23
            }
24 1
        }
25 1
        $propertiesString = $this->formatLine($this->writeSeparator());;
26 1
        if (!empty($groups['other'])) {
27 1
            $propertiesString .= parent::writeElements($groups['other']);
28 1
        }
29 1
        if (!empty($groups['todo'])) {
30 1
            $propertiesString .= $this->formatLine($this->writeTodo());
31 1
            $propertiesString .= parent::writeElements($groups['todo']);;        
32 1
        }
33 1
        if (!empty($groups['deprecated'])) {
34 1
            $propertiesString .= $this->formatLine($this->writeDeprecated());
35 1
            $propertiesString .= parent::writeElements($groups['deprecated']);
36 1
        }
37 1
        return $propertiesString;
38
    }
39
40
    /**
41
     * @param \TokenReflection\IReflectionProperty $property
42
     * @return string
43
     */
44 1
    private function isDeprecated(IReflectionProperty $property)
45
    {
46 1
        $returnBool = false;
47 1
        preg_match('/\*\h+@deprecated/', (string) $property->getDocComment(), $matches);
48 1
        if (isset($matches[0])) {
49 1
            $returnBool = true;
50 1
        }
51 1
        return $returnBool;
52
    }
53
54
    /**
55
     * @param \TokenReflection\IReflectionProperty $property
56
     * @return string
57
     */
58 1
    private function isTodo(IReflectionProperty $property)
59
    {
60 1
        $returnBool = false;
61 1
        preg_match('/\*\h+@todo/', (string) $property->getDocComment(), $matches);
62 1
        if (isset($matches[0])) {
63 1
            $returnBool = true;
64 1
        }
65 1
        return $returnBool;
66
    }
67
68 1
    private function writeDeprecated()
69
    {
70 1
        return "-- deprecated --";
71
    }
72
73 1
    private function writeTodo()
74
    {
75 1
        return "-- todo --";
76
    }
77
    
78 1
    private function writeSeparator()
79
    {
80 1
        return "==";
81
    }
82
}