djoos / Symfony-coding-standard

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

Undefined index: scope_closer in ReturnOrThrowSniff #170

Closed GhostLyrics closed 5 years ago

GhostLyrics commented 5 years ago

This is with phpcs 3.4.2 and symfony2-coding-standard dev-master f5b7f6a. With the following example, checking is aborted (I am assuming the checker crashed).

<?php
class TeamMembersController extends AbstractResourceController {
    /**
     * {@inheritdoc}
     */
    public function handleDelete() {
        $aAllowed = $this->_getParser()->getAllowedParamsByInternalName();
        $oService = static::ENTITY_METADATA_CLASS; $oService = $oService::getService();
        $oManip = $oService->getManipulationManager($this->getEntityServiceOptions());
        $oEntity = $oManip->delete($aAllowed);
        if($oEntity === false) return [];
        return $this->_buildResourceResponseData($oEntity);
    }
}
phpcs -v --basepath="$PWD" --parallel=$(nproc --all) minimal_example.php

Registering sniffs in the Symfony for Timetac standard... DONE (81 sniffs registered)
Creating file list... DONE (1 files in queue)
Changing into directory .
Processing minimal_example.php [PHP => 132 tokens in 14 lines]...
FILE: minimal_example.php
---------------------------------------------------------------------------------------------------------------------------------------
FOUND 11 ERRORS AFFECTING 5 LINES
---------------------------------------------------------------------------------------------------------------------------------------
  1 | ERROR | [ ] An error occurred during processing; checking has been aborted. The error message was: Undefined index: scope_closer
    |       |     in /root/.composer/vendor/escapestudios/symfony2-coding-standard/Symfony/Sniffs/Formatting/ReturnOrThrowSniff.php on
    |       |     line 99
  2 | ERROR | [ ] Missing doc comment for class TeamMembersController
  2 | ERROR | [ ] Each class must be in a namespace of at least one level (a top-level vendor name)
  2 | ERROR | [x] Opening brace of a class must be on the line after the definition
  2 | ERROR | [x] Opening brace of a class must be on the line after the definition
  6 | ERROR | [x] Opening brace should be on a new line
  8 | ERROR | [x] Each PHP statement must be on a line by itself
 11 | ERROR | [ ] Use Yoda conditions when checking a variable against an expression to avoid an accidental assignment inside the
    |       |     condition statement.
 11 | ERROR | [x] Expected 1 space(s) after IF keyword; 0 found
 11 | ERROR | [x] Inline control structures are not allowed
 11 | ERROR | [x] Missing blank line before return statement
---------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------

I can change the line I am assuming trips up the checker by making it:

        if($oEntity === false) {return [];}

That change results in different warnings (which is okay) and the checker not crashing (which is very good).

phpcs -v --basepath="$PWD" --parallel=$(nproc --all) minimal_example.php

Registering sniffs in the Symfony for Timetac standard... DONE (81 sniffs registered)
Creating file list... DONE (1 files in queue)
Changing into directory .
Processing minimal_example.php [PHP => 134 tokens in 14 lines]... DONE in 50ms (13 errors, 0 warnings)

FILE: minimal_example.php
---------------------------------------------------------------------------------------------------------------------------------------
FOUND 13 ERRORS AFFECTING 5 LINES
---------------------------------------------------------------------------------------------------------------------------------------
  2 | ERROR | [ ] Missing doc comment for class TeamMembersController
  2 | ERROR | [ ] Each class must be in a namespace of at least one level (a top-level vendor name)
  2 | ERROR | [x] Opening brace of a class must be on the line after the definition
  2 | ERROR | [x] Opening brace of a class must be on the line after the definition
  6 | ERROR | [x] Opening brace should be on a new line
  8 | ERROR | [x] Each PHP statement must be on a line by itself
 11 | ERROR | [ ] Use Yoda conditions when checking a variable against an expression to avoid an accidental assignment inside the
    |       |     condition statement.
 11 | ERROR | [x] Expected 1 space(s) after IF keyword; 0 found
 11 | ERROR | [x] Newline required after opening brace
 11 | ERROR | [x] Missing blank line before return statement
 11 | ERROR | [x] Closing brace must be on a line by itself
 11 | ERROR | [x] Closing brace must be on a line by itself
 12 | ERROR | [x] Missing blank line before return statement
---------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 10 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------
acosta-edgar commented 5 years ago

I've run into the same issue. If I had not read this report I would not have known what is causing the Uncaught Exception since I am not familiar with the code that is failing.

Can the Exception be caught and reported as a Standard violation?

GhostLyrics commented 5 years ago

Thank you. I can confirm it solved the problem for me.