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

MethodGroupingWriter::isTodo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 9
loc 9
rs 9.6666
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Flagbit\Plantuml\TokenReflection;
4
5
use TokenReflection\IReflectionMethod;
6
use TokenReflection\IReflectionParameter;
7
8 View Code Duplication
class MethodGroupingWriter extends MethodWriter
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...
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
}