Skip to content

Commit 97e4acb

Browse files
authored
Removed roave/better-reflection from other components. (#3654)
1 parent f637304 commit 97e4acb

File tree

4 files changed

+11
-64
lines changed

4 files changed

+11
-64
lines changed

src/TypesFinderManager.php

-31
This file was deleted.

tests/InjectTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ protected function getContainer(array $classes = [])
265265
ApplicationContext::setContainer($container);
266266
$path = BASE_PATH . '/runtime/scan.cache';
267267

268-
// BetterReflectionManager::initClassReflector([__DIR__ . '/Stub']);
269-
270268
$pid = pcntl_fork();
271269
if ($pid == -1) {
272270
throw new Exception('The process fork failed');

tests/InterfaceLazyProxyBuilderTest.php

+4-14
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@
1313

1414
use Hyperf\Di\LazyLoader\InterfaceLazyProxyBuilder;
1515
use Hyperf\Di\LazyLoader\PublicMethodVisitor;
16+
use Hyperf\Utils\CodeGen\PhpParser;
1617
use PhpParser\NodeTraverser;
1718
use PhpParser\NodeVisitor\NameResolver;
1819
use PhpParser\ParserFactory;
1920
use PhpParser\PrettyPrinter\Standard;
2021
use PHPUnit\Framework\TestCase;
21-
use Roave\BetterReflection\BetterReflection;
22-
use Roave\BetterReflection\Reflection\Adapter\ReflectionMethod;
23-
use Roave\BetterReflection\Reflector\ClassReflector;
24-
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator;
2522

2623
/**
2724
* @internal
@@ -79,7 +76,7 @@ public function works(bool $a, float $b = 1) : int
7976
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
8077
$ast = $parser->parse($code);
8178
$traverser = new NodeTraverser();
82-
$visitor = new PublicMethodVisitor(...$this->getStmt($code));
79+
$visitor = new PublicMethodVisitor(...$this->getStmt($ast));
8380
$nameResolver = new NameResolver();
8481
$traverser->addVisitor($nameResolver);
8582
$traverser->addVisitor($visitor);
@@ -91,16 +88,9 @@ public function works(bool $a, float $b = 1) : int
9188
$this->assertEquals($expected, $newCode);
9289
}
9390

94-
private function getStmt($code)
91+
private function getStmt($ast)
9592
{
96-
$astLocator = (new BetterReflection())->astLocator();
97-
$reflector = new ClassReflector(new StringSourceLocator($code, $astLocator));
98-
$reflectionClass = $reflector->reflect('foo\\foo');
99-
$reflectionMethods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
100-
$stmts = [];
101-
foreach ($reflectionMethods as $method) {
102-
$stmts[] = $method->getAst();
103-
}
93+
$stmts = PhpParser::getInstance()->getAllMethodsFromStmts($ast);
10494
return [$stmts, 'foo\\foo'];
10595
}
10696
}

tests/PublicMethodVisitorTest.php

+7-17
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212
namespace HyperfTest\Di;
1313

1414
use Hyperf\Di\LazyLoader\PublicMethodVisitor;
15+
use Hyperf\Utils\CodeGen\PhpParser;
1516
use PhpParser\NodeTraverser;
1617
use PhpParser\ParserFactory;
1718
use PhpParser\PrettyPrinter\Standard;
1819
use PHPUnit\Framework\TestCase;
19-
use Roave\BetterReflection\BetterReflection;
20-
use Roave\BetterReflection\Reflection\Adapter\ReflectionMethod;
21-
use Roave\BetterReflection\Reflector\ClassReflector;
22-
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator;
2320

2421
/**
2522
* @internal
@@ -48,7 +45,7 @@ public function hope(bool $a) : int
4845
{
4946
return $this->__call(__FUNCTION__, func_get_args());
5047
}
51-
public function it(\bar\ConfigInterface $a) : void
48+
public function it(ConfigInterface $a) : void
5249
{
5350
$this->__call(__FUNCTION__, func_get_args());
5451
}
@@ -64,7 +61,7 @@ public function fluent() : \foo\foo
6461
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
6562
$ast = $parser->parse($code);
6663
$traverser = new NodeTraverser();
67-
$visitor = new PublicMethodVisitor(...$this->getStmt($code));
64+
$visitor = new PublicMethodVisitor(...$this->getStmt($ast));
6865
$traverser->addVisitor($visitor);
6966
$ast = $traverser->traverse($ast);
7067
$prettyPrinter = new Standard();
@@ -103,7 +100,7 @@ public function hope(bool $a) : int
103100
{
104101
return $this->__call(__FUNCTION__, func_get_args());
105102
}
106-
public function it(\bar\ConfigInterface $a) : void
103+
public function it(ConfigInterface $a) : void
107104
{
108105
$this->__call(__FUNCTION__, func_get_args());
109106
}
@@ -119,7 +116,7 @@ public function fluent() : \foo\foo
119116
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
120117
$ast = $parser->parse($code);
121118
$traverser = new NodeTraverser();
122-
$visitor = new PublicMethodVisitor(...$this->getStmt($code));
119+
$visitor = new PublicMethodVisitor(...$this->getStmt($ast));
123120
$traverser->addVisitor($visitor);
124121
$ast = $traverser->traverse($ast);
125122
$prettyPrinter = new Standard();
@@ -128,16 +125,9 @@ public function fluent() : \foo\foo
128125
$this->assertEquals(4, count($visitor->nodes));
129126
}
130127

131-
private function getStmt($code)
128+
private function getStmt($ast)
132129
{
133-
$astLocator = (new BetterReflection())->astLocator();
134-
$reflector = new ClassReflector(new StringSourceLocator($code, $astLocator));
135-
$reflectionClass = $reflector->reflect('foo\\foo');
136-
$reflectionMethods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
137-
$stmts = [];
138-
foreach ($reflectionMethods as $method) {
139-
$stmts[] = $method->getAst();
140-
}
130+
$stmts = PhpParser::getInstance()->getAllMethodsFromStmts($ast);
141131
return [$stmts, 'foo\\foo'];
142132
}
143133
}

0 commit comments

Comments
 (0)