DocContentWriter::writeParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Flagbit\Plantuml\TokenReflection;
4
5
use TokenReflection\IReflectionClass;
6
use TokenReflection\IReflectionParameter;
7
8
class DocContentWriter extends \Flagbit\Plantuml\TokenReflection\WriterAbstract
9
{
10
    /**
11
     * @param \TokenReflection\IReflectionClass $class
12
     * @return string
13
     */
14 10 View Code Duplication
    public function writeProperties(\TokenReflection\IReflectionClass $class)
0 ignored issues
show
Duplication introduced by
This method 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...
15
    {
16 10
        $written = '';
17 10
        $docComment = (string)$class->getDocComment();
18 10
        $matches = array();
19 10
        preg_match_all('/\*\h+@property(?:-read|-write|)\h+([^\h]+)\h+\$([^\s]+)\s/', (string)$docComment, $matches);
20 10
        foreach($matches[2] as $i => $name) {
21 1
            $written .= $this->writeProperty($name, $matches[1][$i]);
22 10
        }
23 10
        return $written;
24
    }
25
26
    /**
27
     * @param \TokenReflection\IReflectionMethod $method
0 ignored issues
show
Bug introduced by
There is no parameter named $method. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
28
     * @return string
29
     */
30 1
    protected function writeProperty($name, $type) {
31 1
        return $this->formatLine($this->writeVisibility() . $name
32 1
            . $this->writeType($type));
33
    }
34
35
36
    /**
37
     * @param string $type
38
     * @return string
39
     */
40 1
    public function writeType($type)
41
    {
42 1
        return ' : '.$type;
43
    }
44
45
    /**
46
     * Public by definition if in a docblock.
47
     * @return string
48
     */
49 1
    protected function writeVisibility() {
50 1
        return '+';
51
    }
52
53
    /**
54
     * @param \TokenReflection\IReflectionClass $class
55
     * @return string
56
     */
57 10 View Code Duplication
    public function writeMethods(IReflectionClass $class)
0 ignored issues
show
Duplication introduced by
This method 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...
58
    {
59 10
        $written = '';
60 10
        $docComment = (string)$class->getDocComment();
61 10
        $matches = array();
62 10
        preg_match_all('/\*\h+@method\h+([^\h]+)\h+([^(\s]+)(?:\h*\(\h*([^)]*)\h*\))?\s/', (string)$docComment, $matches);
63 10
        foreach($matches[2] as $i => $name) {
64 1
            $written .= $this->writeMethod($name, $matches[3][$i], $matches[1][$i]);
65 10
        }
66 10
        return $written;
67
    }
68
69
    /**
70
     * @param \TokenReflection\IReflectionClass $class
0 ignored issues
show
Bug introduced by
There is no parameter named $class. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
71
     * @return string
72
     */
73 1
    protected function writeMethod($name, $params, $returnType)
74
    {
75 1
        return $this->formatLine($this->writeVisibility()
76 1
            . $name . $this->writeParameters($params)
77 1
            . $this->writeReturnType($returnType));
78
    }
79
80
    /**
81
     * @param string $returnType
82
     * @return string
83
     */
84 1
    protected function writeReturnType($returnType) {
85 1
        return $this->writeType($returnType);
86
    }
87
88
89
    /**
90
     * @param string $params
91
     * @return string
92
     */
93 1
    private function writeParameters($params)
94
    {
95 1
        return '(' . $params . ')';
96
    }
97
98
}
99