Code Duplication    Length = 76-76 lines in 2 locations

src/Flagbit/Plantuml/TokenReflection/MethodGroupingWriter.php 1 location

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

src/Flagbit/Plantuml/TokenReflection/PropertyGroupingWriter.php 1 location

@@ 7-82 (lines=76) @@
4
5
use TokenReflection\IReflectionProperty;
6
7
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'=>[],'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
}