Commit acba9e5b by Carsten Brandt

fix crash when setter w/o arguments is defined

fixes #5623
parent 292a9ff5
...@@ -4,7 +4,7 @@ Yii Framework 2 apidoc extension Change Log ...@@ -4,7 +4,7 @@ Yii Framework 2 apidoc extension Change Log
2.0.1 under development 2.0.1 under development
----------------------- -----------------------
- no changes in this release. - Bug #5623: Fixed crash when a class contains a setter that has no arguments e.g. `setXyz()` (cebe)
2.0.0 October 12, 2014 2.0.0 October 12, 2014
......
...@@ -271,7 +271,7 @@ class Context extends Component ...@@ -271,7 +271,7 @@ class Context extends Component
if ($method->isStatic) { if ($method->isStatic) {
continue; continue;
} }
if (!strncmp($name, 'get', 3) && strlen($name) > 3 && $this->paramsOptional($method)) { if (!strncmp($name, 'get', 3) && strlen($name) > 3 && $this->hasNonOptionalParams($method)) {
$propertyName = '$' . lcfirst(substr($method->name, 3)); $propertyName = '$' . lcfirst(substr($method->name, 3));
if (isset($class->properties[$propertyName])) { if (isset($class->properties[$propertyName])) {
$property = $class->properties[$propertyName]; $property = $class->properties[$propertyName];
...@@ -299,7 +299,7 @@ class Context extends Component ...@@ -299,7 +299,7 @@ class Context extends Component
]); ]);
} }
} }
if (!strncmp($name, 'set', 3) && strlen($name) > 3 && $this->paramsOptional($method, 1)) { if (!strncmp($name, 'set', 3) && strlen($name) > 3 && $this->hasNonOptionalParams($method, 1)) {
$propertyName = '$' . lcfirst(substr($method->name, 3)); $propertyName = '$' . lcfirst(substr($method->name, 3));
if (isset($class->properties[$propertyName])) { if (isset($class->properties[$propertyName])) {
$property = $class->properties[$propertyName]; $property = $class->properties[$propertyName];
...@@ -331,18 +331,20 @@ class Context extends Component ...@@ -331,18 +331,20 @@ class Context extends Component
} }
/** /**
* Check whether a method has `$number` non-optional parameters.
* @param MethodDoc $method * @param MethodDoc $method
* @param integer $number number of not optional parameters * @param integer $number number of not optional parameters
* @return bool * @return bool
*/ */
private function paramsOptional($method, $number = 0) private function hasNonOptionalParams($method, $number = 0)
{ {
$count = 0;
foreach ($method->params as $param) { foreach ($method->params as $param) {
if (!$param->isOptional && $number-- <= 0) { if (!$param->isOptional) {
return false; $count++;
} }
} }
return true; return $count == $number;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment