Completed
Pull Request — master (#68)
by Cristiano
05:36
created

PhpParameter   A

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
1
<?php declare(strict_types=1);
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
18
namespace gossi\codegen\model;
19
20
use gossi\codegen\model\parts\NamePart;
21
use gossi\codegen\model\parts\TypePart;
22
use gossi\codegen\model\parts\ValuePart;
23
use gossi\docblock\tags\ParamTag;
24
25
/**
26
 * Represents a PHP parameter.
27
 *
28
 * @author Johannes M. Schmitt <[email protected]>
29
 * @author Thomas Gossmann
30
 */
31
class PhpParameter extends AbstractModel implements ValueInterface {
32
	use NamePart;
33
	use TypePart;
34
	use ValuePart;
35
36
	private bool $passedByReference = false;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
37
38
	/**
39
	 * Creates a new PHP parameter.
40
	 *
41
	 * @param string $name the parameter name
42
	 *
43
	 * @return static
44
	 */
45
	public static function create(string $name = ''): static {
46 18
		return new static($name);
47 18
	}
48
49
	/**
50
	 * Creates a new PHP parameter
51
	 *
52
	 * @param string $name the parameter name
53
	 */
54
	public function __construct(string $name = '') {
55 29
		$this->setName($name);
56 29
	}
57 29
58
	/**
59
	 * Sets whether this parameter is passed by reference
60
	 *
61
	 * @param bool $bool `true` if passed by reference and `false` if not
62
	 *
63
	 * @return $this
64
	 */
65 8
	public function setPassedByReference(bool $bool): static {
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
	 *
97
	 * @param string $description
98
	 *
99 4
	 * @return $this
100 4
	 */
101
	public function setTypeDescription(string $description): static {
102
		return $this->setDescription($description);
103
	}
104
105
	/**
106
	 * Alias for getDescription()
107
	 *
108
	 * @see #getDescription
109 9
	 *
110 9
	 * @return string
111
	 */
112
	public function getTypeDescription(): string {
113
		return $this->getDescription();
114
	}
115
}
116