Skip to content

Commit

Permalink
Remove php parser (#1644)
Browse files Browse the repository at this point in the history
* Remove php parser

* composer fix-style

---------

Co-authored-by: laravel-ide-helper <[email protected]>
  • Loading branch information
barryvdh and laravel-ide-helper authored Dec 30, 2024
1 parent e509790 commit 9c6380d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 207 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"illuminate/console": "^11.15",
"illuminate/database": "^11.15",
"illuminate/filesystem": "^11.15",
"illuminate/support": "^11.15",
"nikic/php-parser": "^4.18 || ^5"
"illuminate/support": "^11.15"
},
"require-dev": {
"ext-pdo_sqlite": "*",
Expand Down
3 changes: 2 additions & 1 deletion src/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Context;
use Barryvdh\Reflection\DocBlock\ContextFactory;
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
use Barryvdh\Reflection\DocBlock\Tag\MethodTag;
use Closure;
Expand Down Expand Up @@ -82,7 +83,7 @@ public function __construct($config, $alias, $facade, $magicMethods = [], $inter

if (!empty($this->namespace)) {
try {
$this->classAliases = (new UsesResolver())->loadFromClass($this->root);
$this->classAliases = (new ContextFactory())->createFromReflector(new ReflectionClass($this->root))->getNamespaceAliases();
} catch (Throwable $e) {
$this->classAliases = [];
}
Expand Down
37 changes: 13 additions & 24 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use PhpParser\Lexer\Emulative;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Parser\Php7;
use ReflectionClass;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down Expand Up @@ -213,8 +209,10 @@ protected function getRealTimeFacades()
foreach ($realTimeFacadeFiles as $file) {
try {
$name = $this->getFullyQualifiedClassNameInFile($file);
$facades[$name] = $name;
} catch (\Exception $e) {
if ($name) {
$facades[$name] = $name;
}
} catch (\Throwable $e) {
continue;
}
}
Expand All @@ -226,26 +224,17 @@ protected function getFullyQualifiedClassNameInFile(string $path)
{
$contents = file_get_contents($path);

$parsers = new Php7(new Emulative());

$parsed = collect($parsers->parse($contents) ?: []);

$namespace = $parsed->first(function ($node) {
return $node instanceof Namespace_;
});

if ($namespace) {
$name = $namespace->name->toString();

$class = collect($namespace->stmts)->first(function ($node) {
return $node instanceof Class_;
});
// Match namespace
preg_match('/namespace\s+([^;]+);/', $contents, $namespaceMatch);
$namespace = isset($namespaceMatch[1]) ? $namespaceMatch[1] : '';

if ($class) {
$name .= '\\' . $class->name->toString();
}
// Match class name
preg_match('/class\s+([a-zA-Z0-9_]+)/', $contents, $classMatch);
$className = isset($classMatch[1]) ? $classMatch[1] : '';

return $name;
// Combine namespace and class name
if ($namespace && $className) {
return $namespace . '\\' . $className;
}
}

Expand Down
124 changes: 0 additions & 124 deletions src/UsesResolver.php

This file was deleted.

56 changes: 0 additions & 56 deletions tests/UsesResolverTest.php

This file was deleted.

0 comments on commit 9c6380d

Please sign in to comment.