Skip to content

Commit 47d455d

Browse files
committed
fix code generator
1 parent e926453 commit 47d455d

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

generator/src/Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function getParams(): array
9191
}
9292
}
9393

94-
$params[] = new Parameter($param, $phpStanFunction);
94+
$params[] = new Parameter($param, $phpStanFunction, $i-2);
9595
}
9696
$this->params = $params;
9797
}

generator/src/Parameter.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class Parameter
1616
*/
1717
private $type;
1818

19-
public function __construct(\SimpleXMLElement $parameter, ?PhpStanFunction $phpStanFunction)
19+
public function __construct(\SimpleXMLElement $parameter, ?PhpStanFunction $phpStanFunction, int $position)
2020
{
2121
$this->parameter = $parameter;
22-
$phpStanParam = $phpStanFunction ? $phpStanFunction->getParameter($this->getParameter()) : null;
22+
$phpStanParam = $phpStanFunction ? $phpStanFunction->getParameter($this->getParameter(), $position) : null;
2323

2424
$this->type = $phpStanParam ? $phpStanParam->getType() : new PhpStanType($this->parameter->type->__toString());
2525
}
@@ -42,9 +42,6 @@ public function getDocBlockType(): string
4242

4343
public function getParameter(): string
4444
{
45-
if ($this->isVariadic()) {
46-
return 'params';
47-
}
4845
// The db2_bind_param method has parameters with a dash in it... yep... (patch submitted)
4946
return \str_replace('-', '_', $this->parameter->parameter->__toString());
5047
}
@@ -62,7 +59,7 @@ public function isByReference(): bool
6259
*/
6360
public function isOptionalWithNoDefault(): bool
6461
{
65-
if (((string)$this->parameter['choice']) !== 'opt') {
62+
if (((string)$this->parameter['choice']) !== 'opt' && !$this->isVariadic()) {
6663
return false;
6764
}
6865
if (!$this->hasDefaultValue()) {
@@ -71,15 +68,15 @@ public function isOptionalWithNoDefault(): bool
7168

7269
$initializer = $this->getInitializer();
7370
// Some default value have weird values. For instance, first parameter of "mb_internal_encoding" has default value "mb_internal_encoding()"
74-
if ($initializer !== 'array()' && strpos($initializer, '(') !== false) {
71+
if ($initializer === 'null' || ($initializer !== 'array()' && strpos($initializer, '(') !== false)) {
7572
return true;
7673
}
7774
return false;
7875
}
7976

8077
public function isVariadic(): bool
8178
{
82-
return $this->parameter->parameter->__toString() === '...';
79+
return ((string)$this->parameter['rep']) === 'repeat';
8380
}
8481

8582
public function isNullable(): bool

generator/src/PhpStanFunctions/PhpStanFunction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public function getParameters(): array
4040
return $this->parameters;
4141
}
4242

43-
public function getParameter(string $name): ?PhpStanParameter
43+
public function getParameter(string $name, int $position): ?PhpStanParameter
4444
{
45-
return $this->parameters[$name] ?? null;
45+
return $this->parameters[$name] ?? array_values($this->parameters)[$position] ?? null;
4646
}
4747
}

0 commit comments

Comments
 (0)