djoos / Symfony-coding-standard

Development repository for the Symfony coding standard
MIT License
402 stars 102 forks source link

Undefined Index when attempting to evaluate PHP file without class / function #93

Closed matthew-muscat closed 7 years ago

matthew-muscat commented 7 years ago

This is based on evaluating a laravel config file, which typically only contains a return statement array of configuration values... (ie: https://github.com/laravel/laravel/blob/master/config/app.php)

Example code triggering issue can be located below...

<?php

return [

    'api_domain' => env('API_DOMAIN', 'api.example.com'),

    'app_id' => env('APP_ID'),

    'client_id' => env('CLIENT_ID'),
    'client_secret' => env('CLIENT_SECRET'),

];

The error displayed is as follows...

An error occurred during processing; checking has been aborted. The error message was: Undefined index: scope_opener in vendor/escapestudios/symfony2-coding-standard/Symfony/Sniffs/Formatting/ReturnOrThrowSniff.php on line 78 (Internal.Exception)

https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Formatting/ReturnOrThrowSniff.php#L78

Notes:

$function variable is returning false, whereas the return of throw sniff is looking for a function call and assumes it's available.

https://github.com/djoos/Symfony-coding-standard/blob/master/Symfony/Sniffs/Formatting/ReturnOrThrowSniff.php#L74

wickedOne commented 7 years ago

hi @matthew-muscat thanks for the extended bug report! i'll make a fix for this today...