View Issue Details

IDProjectCategoryView StatusLast Update
0000969XdebugUncategorizedpublic2013-10-09 18:38
Reportervis7mac Assigned Toderick  
PriorityhighSeveritymajorReproducibilityalways
Status resolvedResolutionno change required 
PlatformUnixOSOS XOS Version10.8.4
Product Version2.2.3 
Summary0000969: XDebug (when used with PHPUnit) marks closing curly braces after a switch or if as not covered
DescriptionI use XDebug 2.2.3 together with PHP_CodeCoverage 1.2.12 and PHPUnit 3.7.24 to generate code coverage reports for my code tested by PHPUnit.

My code includes some switch case statements right at the end of methods, so I process a value and depending on it different values get returned right in the switch case:

<code>public function someMethod() {
  $value = $this->doSomething();
  
  switch($value) {
    case 1:
      return true;
    case 2:
      return false;
    case 3:
      throw new Exception('Error.');
  }
} // This line is marked as "not executed" in the code coverage report</code>


As you can see, there is no case where the switch would be left and PHP would proceed executing the code of the method - instead, in every case the switch is left with a return statement or throwing an Exception.
I don't use a default statement here because I know what the possible return values are. These are also tested by my Unit Tests.
BTW: This bug also works for if conditions using a return statement as I read in Stack Overflow, but I didn't test that.

This is not really a bug in XDebug as the last line (marked in the code) with only the closing curly brace is actually never run - but the question is if this should be like that:
A curly brace (or any other bracket) is not a piece of code to execute - instead, it's a way of structuring the code so the interpreter understands what to do. A curly brace can not even ever be "executed".

My request: Ignore lines with only a brace from code coverage analysis.
Steps To ReproduceUse the code I mentioned in the description. This might also just be a function, but I only tested with a instance method.
Additional InformationMy PHP version is actually 5.5.1 and not 5.5-dev - but I can't select it. You should probably fix that. :D
TagsNo tags attached.
Operating SystemOS X 10.8.4
PHP Version5.5-dev

Activities

derick

2013-10-09 18:38

administrator   ~0002575

This is not a bug. In theory "$value" could be something else than 1, 2
      or 3 and in that case the switch() would *not* leave due to one of the
      values. Xdebug can not make assumptions on what "doSomething()" returns an
      has no way to know that all that ever is returned than 1, 2 or 3. The
      last } of each function and method includes an implicit "return NULL;" -
      which PHP sees as executable code. Because there is a possible code path
      where the } is not hit, it is marked as "not executed".

Issue History

Date Modified Username Field Change
2013-08-12 10:46 vis7mac New Issue
2013-10-09 18:38 derick Note Added: 0002575
2013-10-09 18:38 derick Status new => resolved
2013-10-09 18:38 derick Resolution open => no change required
2013-10-09 18:38 derick Assigned To => derick
2016-07-31 12:36 derick Category Usage problems => Usage problems (Crashes)
2016-07-31 12:38 derick Category Usage problems (Crashes) => Usage problems (Wrong Results)
2020-03-12 16:35 derick Category Usage problems (Wrong Results) => Variable Display
2020-03-12 16:38 derick Category Variable Display => Uncategorized