Skip to content

Commit b0482ce

Browse files
committed
Parameter::setDefaultValue() automatically sets setOptional(), setOptional is deprecated (BC break)
1 parent b357b90 commit b0482ce

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

src/PhpGenerator/Factory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ public function fromParameterReflection(\ReflectionParameter $from)
107107
$param->setTypeHint($from->hasType() ? (string) $from->getType() : NULL);
108108
$param->setNullable($from->hasType() && $from->getType()->allowsNull());
109109
if ($from->isDefaultValueAvailable()) {
110-
$param->setOptional(TRUE);
111110
$param->setDefaultValue($from->isDefaultValueConstant()
112111
? new PhpLiteral($from->getDefaultValueConstantName())
113112
: $from->getDefaultValue());

src/PhpGenerator/Parameter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function getTypeHint()
7777

7878

7979
/**
80+
* @deprecated just use setDefaultValue()
8081
* @param bool
8182
* @return static
8283
*/
@@ -93,6 +94,7 @@ public function setOptional($state = TRUE)
9394
*/
9495
public function isOptional()
9596
{
97+
trigger_error(__METHOD__ . '() is deprecated, use hasDefaultValue()', E_USER_DEPRECATED);
9698
return $this->hasDefaultValue;
9799
}
98100

@@ -123,6 +125,7 @@ public function isNullable()
123125
public function setDefaultValue($val)
124126
{
125127
$this->defaultValue = $val;
128+
$this->hasDefaultValue = TRUE;
126129
return $this;
127130
}
128131

src/PhpGenerator/Traits/FunctionLike.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function addParameter($name, $defaultValue = NULL)
107107
{
108108
$param = new Parameter($name);
109109
if (func_num_args() > 1) {
110-
$param->setOptional(TRUE)->setDefaultValue($defaultValue);
110+
$param->setDefaultValue($defaultValue);
111111
}
112112
return $this->parameters[$name] = $param;
113113
}

0 commit comments

Comments
 (0)