Skip to content

Commit 95f78b2

Browse files
committed
make method parameter type PhpTypeExcepression.
1 parent 538407f commit 95f78b2

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

src/Php/PhpMethod.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ class PhpMethod {
1717
protected PhpAccessModifier $accessModifier;
1818

1919
public function __construct(ClassMethod $method, PhpClass $class) {
20-
$params = array_map(function($x) use ($class){
21-
$type = $class->findTypeByTypeParts($x, 'type');
20+
$docString = '';
21+
$doc = $method->getDocComment();
22+
if ( ! empty($doc)) {
23+
$docString = $doc->getText();
24+
}
25+
$params = array_map(function($x) use ($class, $docString){
26+
// $type = $class->findTypeByTypeParts($x, 'type');
27+
$type = PhpTypeExpression::buildByMethodParam($x, $class->getNamespace(), $docString, $x->var->name, $class->getUses());
2228
return new PhpMethodParameter($x->var->name, $type);
2329
}, $method->getParams());
2430
$this->name = $method->name->toString();

src/Php/PhpMethodParameter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
class PhpMethodParameter {
55
private string $name;
6-
private PhpType $type;
6+
private PhpTypeExpression $type;
77

8-
public function __construct(string $name, PhpType $type) {
8+
public function __construct(string $name, PhpTypeExpression $type) {
99
$this->name = $name;
1010
$this->type = $type;
1111
}
@@ -14,7 +14,7 @@ public function getName(): string {
1414
return $this->name;
1515
}
1616

17-
public function getType(): PhpType {
17+
public function getType(): PhpTypeExpression {
1818
return $this->type;
1919
}
2020
}

test/PhpReflectionTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@ public function testNullable(): void {
224224
$this->assertSame('Tag', $data->getMethods()[0]->getType()->getName(), 'return type.');
225225
$this->assertSame(['hoge', 'fuga', 'product', 'tags'], $data->getMethods()[0]->getType()->getNamespace(), 'return type namespace.');
226226
$this->assertSame('name', $data->getMethods()[0]->getParams()[0]->getName(), 'parameter name.');
227-
$this->assertSame('Name', $data->getMethods()[0]->getParams()[0]->getType()->getName(), 'parameter type.');
228-
$this->assertSame(['hoge', 'fuga', 'product'], $data->getMethods()[0]->getParams()[0]->getType()->getNamespace(), 'parameter type namespace.');
227+
$this->assertSame('?Name', $data->getMethods()[0]->getParams()[0]->getType()->getName(), 'parameter type.');
228+
$this->assertSame(['hoge', 'fuga', 'product'], $data->getMethods()[0]->getParams()[0]->getType()->getTypes()[0]->getNamespace(), 'parameter type namespace.');
229229
$this->assertSame('tag', $data->getMethods()[0]->getParams()[1]->getName(), 'parameter name. tag');
230230
$this->assertSame('Tag', $data->getMethods()[0]->getParams()[1]->getType()->getName(), 'parameter type. tag');
231-
$this->assertSame(['hoge', 'fuga', 'product', 'tags'], $data->getMethods()[0]->getParams()[1]->getType()->getNamespace(), 'parameter type namespace. tag');
231+
$this->assertSame(['hoge', 'fuga', 'product', 'tags'], $data->getMethods()[0]->getParams()[1]->getType()->getTypes()[0]->getNamespace(), 'parameter type namespace. tag');
232232
}
233233
public function testNullableWithoutNamespace(): void {
234234
$options = new Options([]);
@@ -243,8 +243,8 @@ public function testNullableWithoutNamespace(): void {
243243
$this->assertSame('Name', $data->getMethods()[0]->getType()->getName(), 'return type.');
244244
$this->assertSame(['hoge', 'fuga', 'product'], $data->getMethods()[0]->getType()->getNamespace(), 'return type namespace.');
245245
$this->assertSame('name', $data->getMethods()[0]->getParams()[0]->getName(), 'parameter name.');
246-
$this->assertSame('Name', $data->getMethods()[0]->getParams()[0]->getType()->getName(), 'parameter type.');
247-
$this->assertSame(['hoge', 'fuga', 'product'], $data->getMethods()[0]->getParams()[0]->getType()->getNamespace(), 'parameter type namespace.');
246+
$this->assertSame('?Name', $data->getMethods()[0]->getParams()[0]->getType()->getName(), 'parameter type.');
247+
$this->assertSame(['hoge', 'fuga', 'product'], $data->getMethods()[0]->getParams()[0]->getType()->getTypes()[0]->getNamespace(), 'parameter type namespace.');
248248
}
249249
public function testFullyQualified(): void {
250250
$options = new Options([]);
@@ -262,7 +262,7 @@ public function testFullyQualified(): void {
262262
$this->assertSame([], $data->getMethods()[0]->getType()->getNamespace(), 'return type namespace.');
263263
$this->assertSame('e', $data->getMethods()[0]->getParams()[0]->getName(), 'parameter name.');
264264
$this->assertSame('Exception', $data->getMethods()[0]->getParams()[0]->getType()->getName(), 'parameter type.');
265-
$this->assertSame([], $data->getMethods()[0]->getParams()[0]->getType()->getNamespace(), 'parameter type namespace.');
265+
$this->assertSame([], $data->getMethods()[0]->getParams()[0]->getType()->getTypes()[0]->getNamespace(), 'parameter type namespace.');
266266
$this->assertSame('external', $data->getMethods()[1]->getName(), 'method name.');
267267
$this->assertSame('Exception', $data->getMethods()[1]->getType()->getName(), 'return type.');
268268
$this->assertSame(['external'], $data->getMethods()[1]->getType()->getNamespace(), 'return type namespace.');

test/dummy/PhpMethodDummy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
PhpMethod,
66
PhpAccessModifier,
77
PhpMethodParameter,
8+
PhpTypeExpression,
89
};
910

1011
require_once(__DIR__ . '/PhpAccessModifierDummy.php');
@@ -18,7 +19,7 @@ class PhpMethodDummy extends PhpMethod {
1819

1920
public function __construct(\stdClass $method) {
2021
$params = array_map(function($x){
21-
return new PhpMethodParameter($x->name, new PhpType([], '', $x->type->name));
22+
return new PhpMethodParameter($x->name, PhpTypeExpression::buildByPhpType(new PhpType([], '', $x->type->name)));
2223
}, $method->params);
2324
$this->name = $method->name;
2425
$this->type = new PhpType($method->type->namespace, 'Stmt_Class', $method->type->name);

0 commit comments

Comments
 (0)