Skip to content

Commit

Permalink
Simplified some code
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Jan 12, 2015
1 parent 7f3e6a4 commit a1d7e0d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Passes/OptimizeControlStructures.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ public function optimize(TokenStream $stream)
$this->optimizeStructures($structures);
}

/**
* Test whether the given structure's braces can be removed
*
* @param array $structure
* @return bool
*/
protected function canRemoveBracesFrom(array $structure)
{
return ($structure['statements'] <= 1 && !isset($this->preservedBraces[$structure['offsetRightBrace']]));
}

/**
* Test whether the token at current offset is a control structure
*
Expand Down Expand Up @@ -94,17 +105,14 @@ protected function optimizeElse(array $structure)
*/
protected function optimizeStructure(array $structure)
{
if ($structure['structures'])
{
$this->optimizeStructures($structure['structures']);
}
$this->optimizeStructures($structure['structures']);

if ($structure['isIf'] || $structure['isElseif'])
{
$this->markPreservedBraces($structure['offsetRightBrace']);
}

if ($structure['statements'] <= 1 && !isset($this->preservedBraces[$structure['offsetRightBrace']]))
if ($this->canRemoveBracesFrom($structure))
{
if ($structure['isElse'])
{
Expand Down

0 comments on commit a1d7e0d

Please sign in to comment.