PhpParameter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 81
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
A __construct() 0 3 1
A setPassedByReference() 0 5 1
A isPassedByReference() 0 3 1
A getDocblockTag() 0 6 1
A setTypeDescription() 0 3 1
A getTypeDescription() 0 3 1
1
<?php
2
/*
3
 * Copyright 2011 Johannes M. Schmitt <[email protected]>
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
declare(strict_types=1);
18
19
namespace gossi\codegen\model;
20
21
use gossi\codegen\model\parts\NamePart;
22
use gossi\codegen\model\parts\TypePart;
23
use gossi\codegen\model\parts\ValuePart;
24
use gossi\docblock\tags\ParamTag;
25
26
/**
27
 * Represents a PHP parameter.
28
 *
29
 * @author Johannes M. Schmitt <[email protected]>
30
 * @author Thomas Gossmann
31
 */
32
class PhpParameter extends AbstractModel implements ValueInterface {
33
34
	use NamePart;
35
	use TypePart;
36
	use ValuePart;
37
38
	private $passedByReference = false;
39
40
	/**
41
	 * Creates a new PHP parameter.
42
	 *
43
	 * @param string $name the parameter name
44
	 * @return static
45
	 */
46 18
	public static function create($name = null) {
47 18
		return new static($name);
48
	}
49
50
	/**
51
	 * Creates a new PHP parameter
52
	 *
53
	 * @param string $name the parameter name
54
	 */
55 29
	public function __construct($name = null) {
56 29
		$this->setName($name);
57 29
	}
58
59
	/**
60
	 * Sets whether this parameter is passed by reference
61
	 *
62
	 * @param bool $bool `true` if passed by reference and `false` if not
63
	 * @return $this
64
	 */
65 8
	public function setPassedByReference(bool $bool) {
66 8
		$this->passedByReference = $bool;
67
68 8
		return $this;
69
	}
70
71
	/**
72
	 * Returns whether this parameter is passed by reference
73
	 *
74
	 * @return bool `true` if passed by reference and `false` if not
75
	 */
76 12
	public function isPassedByReference(): bool {
77 12
		return $this->passedByReference;
78
	}
79
80
	/**
81
	 * Returns a docblock tag for this parameter
82
	 *
83
	 * @return ParamTag
84
	 */
85 7
	public function getDocblockTag(): ParamTag {
86 7
		return ParamTag::create()
87 7
			->setType($this->getType())
88 7
			->setVariable($this->getName())
89 7
			->setDescription($this->getTypeDescription());
90
	}
91
92
	/**
93
	 * Alias for setDescription()
94
	 *
95
	 * @see #setDescription
96
	 * @param string $description
97
	 * @return $this
98
	 */
99 4
	public function setTypeDescription(?string $description) {
100 4
		return $this->setDescription($description);
101
	}
102
103
	/**
104
	 * Alias for getDescription()
105
	 *
106
	 * @see #getDescription
107
	 * @return string
108
	 */
109 9
	public function getTypeDescription(): ?string {
110 9
		return $this->getDescription();
111
	}
112
}
113