-1

I am using Phpstan on a Drupal project that needs to be updated; I have solved all the issues revealed by Phpstan except one and I don´t know the solution to that one.

The error message is:

Line   asm89/stack-cors/src/Asm89/Stack/Cors.php                    
 ------ ------------------------------------------------------------- 
  32     Syntax error, unexpected T_STRING, expecting ';' on line 32  

The code mentionned here is the following function:

private array $defaultOptions void   (
        'allowedHeaders'         => array(),
        'allowedMethods'         => array(),
        'allowedOrigins'         => array(),
        'allowedOriginsPatterns' => array(),
        'exposedHeaders'         => false,
        'maxAge'                 => false,
        'supportsCredentials'    => false,
    );

where as line 32 is the following line:

private array $defaultOptions void   (

I am absolutely sure about the line numbers and code parts mentionned py Phpstan, however I am not sure about the solution for this problem and hence, any help or hints would be very much appreciated, thanks in advance!

2
  • 1
    An array is defined with array() or brackets [], not (), and would not have a return type. Functions do not start with a $ Commented May 10, 2022 at 14:54
  • 1
    Missing = [ ... ] or = array( ... ) after $defaultOptions. Also, void is a return type, and is out of place here unless there's some new syntax I'm missing? If you wanted the property as nullable, you could declare it as private ?array. Commented May 10, 2022 at 14:58

1 Answer 1

2

I have no idea what happened here, but the code is completely wrong. It's supposed to be an array definition, not a function. From the source code at https://github.com/asm89/stack-cors/blob/master/src/Cors.php, the definition should be

 private $defaultOptions = [
        'allowedHeaders'         => [],
        'allowedMethods'         => [],
        'allowedOrigins'         => [],
        'allowedOriginsPatterns' => [],
        'exposedHeaders'         => [],
        'maxAge'                 => 0,
        'supportsCredentials'    => false,
    ];

If this file is in the vendor folder, set it back to the original and do not change it. Anything in the vendor folder should be managed by the developers, since the next time you run composer update and there's a new version, it will overwrite any changes you've made. If there's an issue with a library you've included or is part of the original package, contact the developers instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.