Completed
Push — master ( 2bf5e3...78cbc9 )
by Thomas
04:42
created

ParamDocblockGeneratorTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 73.33%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 0
cbo 1
dl 0
loc 28
ccs 11
cts 15
cp 0.7333
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateParamDocblock() 0 22 3
1
<?php
2
namespace gossi\codegen\model\parts;
3
4
use gossi\docblock\tags\ParamTag;
5
6
trait ParamDocblockGeneratorTrait {
7
	
8
	/**
9
	 * Generates docblock for params
10
	 */
11 13
	protected function generateParamDocblock() {
12 13
		$docblock = $this->getDocblock();
0 ignored issues
show
Bug introduced by
It seems like getDocblock() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
13 13
		$tags = $docblock->getTags('param');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
14 13
		foreach ($this->parameters as $param) {
15 6
			$ptag = $param->getDocblockTag();
16
				
17 6
			$tag = $tags->find($ptag, function(ParamTag $tag, ParamTag $ptag) {
18
				return $tag->getVariable() == $ptag->getVariable();
19 6
			});
20
					
21
			// try to update existing docblock first
22 6
			if ($tag !== null) {
23
				$tag->setDescription($ptag->getDescription());
24
				$tag->setType($ptag->getType());
25
			}
26
				
27
			// ... append if it doesn't exist
28
			else {
29 6
				$docblock->appendTag($ptag);
30
			}
31 13
		}
32
	}
33
}