Skip to content

Commit fd404a8

Browse files
committed
Parameters: added hasDefaultValue() as replacement of isOptional()
1 parent 0f10fe2 commit fd404a8

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/PhpGenerator/Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function __toString()
115115
. ($param->isReference() ? '&' : '')
116116
. ($variadic ? '...' : '')
117117
. '$' . $param->getName()
118-
. ($param->isOptional() && !$variadic ? ' = ' . Helpers::dump($param->defaultValue) : '');
118+
. ($param->hasDefaultValue() && !$variadic ? ' = ' . Helpers::dump($param->defaultValue) : '');
119119
}
120120
$uses = [];
121121
foreach ($this->uses as $param) {

src/PhpGenerator/Parameter.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Parameter
2727
private $typeHint;
2828

2929
/** @var bool */
30-
private $optional = FALSE;
30+
private $hasDefaultValue = FALSE;
3131

3232
/** @var mixed */
3333
public $defaultValue;
@@ -55,7 +55,7 @@ public static function from(\ReflectionParameter $from)
5555
}
5656
}
5757
}
58-
$param->optional = $from->isDefaultValueAvailable();
58+
$param->hasDefaultValue = $from->isDefaultValueAvailable();
5959
$param->defaultValue = $from->isDefaultValueAvailable() ? $from->getDefaultValue() : NULL;
6060
return $param;
6161
}
@@ -133,17 +133,18 @@ public function getTypeHint()
133133
*/
134134
public function setOptional($state = TRUE)
135135
{
136-
$this->optional = (bool) $state;
136+
$this->hasDefaultValue = (bool) $state;
137137
return $this;
138138
}
139139

140140

141141
/**
142+
* @deprecated use hasDefaultValue()
142143
* @return bool
143144
*/
144145
public function isOptional()
145146
{
146-
return $this->optional;
147+
return $this->hasDefaultValue;
147148
}
148149

149150

@@ -165,4 +166,13 @@ public function getDefaultValue()
165166
return $this->defaultValue;
166167
}
167168

169+
170+
/**
171+
* @return bool
172+
*/
173+
public function hasDefaultValue()
174+
{
175+
return $this->hasDefaultValue;
176+
}
177+
168178
}

0 commit comments

Comments
 (0)