Completed
Pull Request — master (#67)
by
unknown
13:16
created

PhpParameter   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 92.59%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 6
dl 0
loc 92
ccs 25
cts 27
cp 0.9259
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
A __construct() 0 4 1
A setPassedByReference() 0 5 1
A isPassedByReference() 0 3 1
A getDocblockTag() 0 16 4
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\codegen\utils\TypeUtils;
25
use gossi\docblock\tags\ParamTag;
26
27
/**
28
 * Represents a PHP parameter.
29
 *
30
 * @author Johannes M. Schmitt <[email protected]>
31
 * @author Thomas Gossmann
32
 */
33
class PhpParameter extends AbstractModel implements ValueInterface {
34
35
	use NamePart;
36
	use TypePart;
37
	use ValuePart;
38
39
	private $passedByReference = false;
40
41
	/**
42
	 * Creates a new PHP parameter.
43
	 *
44
	 * @param string $name the parameter name
45
	 * @return static
46
	 */
47 18
	public static function create($name = null) {
48 18
		return new static($name);
49
	}
50
51
	/**
52
	 * Creates a new PHP parameter
53
	 *
54
	 * @param string $name the parameter name
55
	 */
56 30
	public function __construct($name = null) {
57 30
		$this->setName($name);
58 30
        $this->initTypes();
59 30
    }
60
61
	/**
62
	 * Sets whether this parameter is passed by reference
63
	 *
64
	 * @param bool $bool `true` if passed by reference and `false` if not
65
	 * @return $this
66
	 */
67 9
	public function setPassedByReference(bool $bool) {
68 9
		$this->passedByReference = $bool;
69
70 9
		return $this;
71
	}
72
73
	/**
74
	 * Returns whether this parameter is passed by reference
75
	 *
76
	 * @return bool `true` if passed by reference and `false` if not
77
	 */
78 12
	public function isPassedByReference(): bool {
79 12
		return $this->passedByReference;
80
	}
81
82
	/**
83
	 * Returns a docblock tag for this parameter
84
	 *
85
	 * @return ParamTag
86
	 */
87 7
	public function getDocblockTag(): ParamTag {
88 7
        $type = '';
89 7
        if ($this->getNullable()) {
90
            $type = 'null';
91
        }
92 7
        if ($this->getTypes()) {
93 7
            if ($type) {
94
                $type .= '|';
95
            }
96 7
            $type .= TypeUtils::typesToExpression($this->getTypes());
97
        }
98 7
		return ParamTag::create()
99 7
			->setType($type)
100 7
			->setVariable($this->getName())
101 7
			->setDescription($this->getTypeDescription());
102
	}
103
104
	/**
105
	 * Alias for setDescription()
106
	 *
107
	 * @see #setDescription
108
	 * @param string $description
109
	 * @return $this
110
	 */
111 5
	public function setTypeDescription(?string $description) {
112 5
		return $this->setDescription($description);
113
	}
114
115
	/**
116
	 * Alias for getDescription()
117
	 *
118
	 * @see #getDescription
119
	 * @return string
120
	 */
121 9
	public function getTypeDescription(): ?string {
122 9
		return $this->getDescription();
123
	}
124
}
125