Skip to content

Commit

Permalink
Improved readability. No functional change
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Jan 12, 2015
1 parent 5c3bbab commit ad3a9c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion bin/source-optimizer
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ class OptimizeControlStructures extends Pass
{
return$this->stream->isAny([\T_ELSE,\T_ELSEIF,\T_FOR,\T_FOREACH,\T_IF,\T_WHILE]);
}
protected function isCurlyOpen()
{
return($this->stream->current()==='{'||$this->stream->isAny([\T_CURLY_OPEN,\T_DOLLAR_OPEN_CURLY_BRACES]));
}
protected function optimizeElse(array$structure)
{
$this->stream->seek($structure['offsetLeftBrace']);
Expand Down Expand Up @@ -527,7 +531,7 @@ class OptimizeControlStructures extends Pass
if(!$braces)
break;
}
elseif(\in_array($token,['{',[\T_CURLY_OPEN,'{'],[\T_DOLLAR_OPEN_CURLY_BRACES,'${']],\true))
elseif($this->isCurlyOpen())
++$braces;
elseif($this->isControlStructure())
{
Expand Down
12 changes: 11 additions & 1 deletion src/Passes/OptimizeControlStructures.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ protected function isControlStructure()
return $this->stream->isAny([T_ELSE, T_ELSEIF, T_FOR, T_FOREACH, T_IF, T_WHILE]);
}

/**
* Test whether the token at current offset is an open curly brace
*
* @return bool
*/
protected function isCurlyOpen()
{
return ($this->stream->current() === '{' || $this->stream->isAny([T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES]));
}

/**
* Optimize given T_ELSE structure
*
Expand Down Expand Up @@ -186,7 +196,7 @@ protected function parseControlStructure()
break;
}
}
elseif (in_array($token, ['{', [T_CURLY_OPEN, '{'], [T_DOLLAR_OPEN_CURLY_BRACES, '${']], true))
elseif ($this->isCurlyOpen())
{
++$braces;
}
Expand Down

0 comments on commit ad3a9c7

Please sign in to comment.