knuckleswtf / scribe

Generate API documentation for humans from your Laravel codebase.✍
https://scribe.knuckles.wtf/laravel/
MIT License
1.58k stars 280 forks source link

Call to undefined method PhpParser\ParserFactory::create() #809

Closed japheth-sh closed 4 months ago

japheth-sh commented 4 months ago

Scribe version

4.30.1

PHP version

8.1

Framework

Laravel

Framework version

9.52.16

Scribe config

type => "laravel"
try_it_out.enabled => false
auth.enabled => true
auth.default => true
postman.enabled => false
openapi.enabled => false
strategies.urlParameters => added Knuckles\Scribe\Extracting\Strategies\UrlParameters\GetFromLumenAPI
strategies.headers => added Knuckles\Scribe\Extracting\Strategies\Headers\GetFromRouteRules: removed [
    'override',
    [
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
    ],
]
strategies.responses => added Knuckles\Scribe\Extracting\Strategies\Responses\ResponseCalls: removed [
    'Knuckles\\Scribe\\Extracting\\Strategies\\Responses\\ResponseCalls',
    [
        'only' => [
            'GET *',
        ],
    ],
]

What happened?

Met Error

Call to undefined method PhpParser\ParserFactory::create()

at vendor/knuckleswtf/scribe/src/Extracting/MethodAstParser.php:46 42▕ @return \PhpParser\Node\Stmt[]|null 43▕ / 44▕ protected static function parseClassSourceCode(string $sourceCode): ?array 45▕ { ➜ 46▕ $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); 47▕ try { 48▕ $ast = $parser->parse($sourceCode); 49▕ } catch (Throwable $error) { 50▕ throw new Exception("Parse error: {$error->getMessage()}");

  +23 vendor frames 

24 artisan:37 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Docs

japheth-sh commented 4 months ago

After some investigation, I believe this is because nikic/php-parser had removed ParserFactory::create in their ^5.0 versions, and you had modified composer.json to allow ^5.0 in 4.30.0 without code update. After I force to use 4.29.0, everything is back to correct.

rabol commented 4 months ago

same problem here

david-windsock commented 4 months ago

After some investigation, I believe this is because nikic/php-parser had removed ParserFactory::create in their ^5.0 versions, and you had modified composer.json to allow ^5.0 in 4.30.0 without code update. After I force to use 4.29.0, everything is back to correct.

Same problem, same solution.

lukemorcom commented 4 months ago

Same problem, downgrading to 4.29.0 solved

shalvah commented 4 months ago

Thanks everyone. It should be fixed now. v4.32.0 has been released with support for php-parser v5; if that doesn't work for you, try v4.31.0 which supports v4.