Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax error with phpstan starting with 2.6.7 #4614

Closed
lazka opened this issue Jan 3, 2022 · 10 comments
Closed

syntax error with phpstan starting with 2.6.7 #4614

lazka opened this issue Jan 3, 2022 · 10 comments

Comments

@lazka
Copy link

lazka commented Jan 3, 2022

I use phpstan in my project and after the update to 2.6.7 phpstan fails with a "syntax error":

 44/44 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ ---------------------------------------------------------------------- 
  Line   tests/ApiTest.php                                                     
 ------ ---------------------------------------------------------------------- 
         Internal error: syntax error, unexpected 'static' (T_STATIC)          
         Run PHPStan with --debug option and post the stack trace to:          
         https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md  
 ------ ---------------------------------------------------------------------- 

The internal error is (I'm using php 7.4):

Uncaught ParseError: syntax error, unexpected 'static' (T_STATIC) in /home/lazka/my-bundle/vendor/api-platform/core/src/Util/ClientTrait80.php:18

Does anyone know how to work around that?

@b2p-fred
Copy link
Contributor

I am currently having the same problem.

@lazka
Copy link
Author

lazka commented Jan 17, 2022

hm, maybe api-platform should avoid php8-only syntax until php8 is required?

@norkunas
Copy link
Contributor

norkunas commented Jan 17, 2022

It tries to avoid that https://github.com/api-platform/core/blob/4ec515837cf696788e828a61005594fffc4cf244/src/Util/ClientTrait.php :)
So the error indicates that you are not running on 7.4

@lazka
Copy link
Author

lazka commented Jan 17, 2022

yeah, but phpstan parses all referenced files anyway and then fails (I don't think it knows anything about PHP_VERSION_ID). And phpstan doesn't provide a way to skip files before parsing, only after parsing :(

@norkunas
Copy link
Contributor

How your ApiTest looks like?

lazka added a commit to lazka/core that referenced this issue Jan 17, 2022
This resulted in phpstan to fail if the active PHP version is <8.0:
Internal error: syntax error, unexpected 'static' (T_STATIC)

In case a project depending on api-platform/core would use ClientTrait directly,
or indirectly, phpstan would try to parse it and fail with the above syntax error.

Move the type declarations into a comment instead.

Fixes api-platform#4614
@lazka
Copy link
Author

lazka commented Jan 17, 2022

This is enough to trigger the error:

<?php

declare(strict_types=1);

namespace App\Tests;

use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client;

class Test extends ApiTestCase
{
    protected function setUp(): void
    {
        parent::setUp();
        static::createClient();
    }
}

@lazka
Copy link
Author

lazka commented Jan 17, 2022

Since #4636 (comment) says this is a phpstan issue I've opened a bug report with phpstan: phpstan/phpstan#6386

@ondrejmirtes
Copy link

This is going to be fixed in PHPStan 1.4.2 which is going to be released soon.

@ondrejmirtes
Copy link

@lazka
Copy link
Author

lazka commented Jan 18, 2022

Confirmed. Thank you! 🙏

@lazka lazka closed this as completed Jan 18, 2022
pbek pushed a commit to digital-blueprint/relay-greenlight-bundle that referenced this issue Jan 11, 2023
lazka added a commit to digital-blueprint/relay-template-bundle that referenced this issue Apr 12, 2023
lazka added a commit to digital-blueprint/relay-base-person-bundle that referenced this issue Apr 13, 2023
lazka added a commit to digital-blueprint/relay-frontend-bundle that referenced this issue Apr 13, 2023
lazka added a commit to digital-blueprint/relay-base-organization-bundle that referenced this issue Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants