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

MethodGroupingWriter::writeElements()   C

Complexity

Conditions 7
Paths 32

Size

Total Lines 26
Code Lines 19

Duplication

Lines 26
Ratio 100 %

Code Coverage

Tests 23
CRAP Score 7

Importance

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