Skip to content

Commit 739f5f2

Browse files
committed
Update FunctionDeclarationParser.php
1 parent 756b526 commit 739f5f2

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

app/Parsers/FunctionDeclarationParser.php

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,30 @@
22

33
namespace App\Parsers;
44

5+
use App\Contexts\AbstractContext;
6+
use App\Contexts\MethodDefinition;
57
use Microsoft\PhpParser\Node\QualifiedName;
68
use Microsoft\PhpParser\Node\Statement\FunctionDeclaration;
79
use Microsoft\PhpParser\Token;
810

911
class FunctionDeclarationParser extends AbstractParser
1012
{
11-
use InitsNewContext;
13+
/**
14+
* @var MethodDefinition
15+
*/
16+
protected AbstractContext $context;
1217

1318
public function parse(FunctionDeclaration $node)
1419
{
15-
$this->context->methodDefinition = array_map(
16-
fn (Token $part) => $part->getText($node->getRoot()->getFullText()),
17-
$node->getNameParts(),
18-
);
19-
20-
if ($node->parameters) {
21-
foreach ($node->parameters->getElements() as $element) {
22-
$param = [
23-
'types' => [],
24-
'name' => $element->getName(),
25-
];
26-
27-
if ($element->typeDeclarationList) {
28-
foreach ($element->typeDeclarationList->getValues() as $type) {
29-
if ($type instanceof Token) {
30-
$param['types'][] = $type->getText($node->getRoot()->getFullText());
31-
} elseif ($type instanceof QualifiedName) {
32-
$param['types'][] = (string) $type->getResolvedName();
33-
} else {
34-
$this->debug('unknown type', $type::class);
35-
}
36-
}
37-
}
38-
39-
$this->context->methodDefinitionParams[] = $param;
40-
}
41-
}
20+
$this->context->methodName = collect($node->getNameParts())->map(
21+
fn(Token $part) => $part->getText($node->getRoot()->getFullText())
22+
)->join('\\');
4223

4324
return $this->context;
4425
}
26+
27+
public function initNewContext(): ?AbstractContext
28+
{
29+
return new MethodDefinition;
30+
}
4531
}

0 commit comments

Comments
 (0)