Completed
Pull Request — master (#11)
by
unknown
05:00
created

PropertyGroupingWriter   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 76
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 14
c 2
b 0
f 2
lcom 1
cbo 1
dl 76
loc 76
ccs 43
cts 43
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
C writeElements() 26 26 7
A isDeprecated() 9 9 2
A isTodo() 9 9 2
A writeDeprecated() 4 4 1
A writeTodo() 4 4 1
A writeSeparator() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}
83