-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeResolver.php
46 lines (40 loc) · 1.2 KB
/
TypeResolver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Mkusher\PadawanDi;
use Parser\UseParser;
use Complete\Resolver\TypeResolveEvent;
use Entity\FQCN;
use PhpParser\Node\Arg;
use PhpParser\Node\Scalar\String_;
class TypeResolver
{
public function __construct(
UseParser $useParser
) {
$this->useParser = $useParser;
}
public function handleParentTypeEvent(TypeResolveEvent $e)
{
$this->parentType = $e->getType();
}
public function handleTypeResolveEvent(TypeResolveEvent $e)
{
$parentType = $this->parentType;
if ($parentType instanceof FQCN
&& $parentType->toString() === 'DI\\Container'
) {
/** @var \Entity\Chain\MethodCall */
$chain = $e->getChain();
if ($chain->getType() === 'method' && count($chain->getArgs()) > 0) {
$firstArg = array_pop($chain->getArgs())->value;
if ($firstArg instanceof String_) {
$className = $firstArg->value;
$fqcn = $this->useParser->parseFQCN($className);
$e->setType($fqcn);
}
}
}
}
/** @var UseParser */
private $useParser;
private $parentType;
}