Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.1.15

Bug #17063 Pear filter generates sometimes invalid code in switches
Submitted: 2010-02-03 22:59 UTC Modified: 2010-08-06 04:43 UTC
From: murat_purc Assigned: clbustos
Status: Closed Package: PHP_Beautifier (version 0.1.14)
PHP Version: 5.2.5 OS: Windows Vista
Roadmaps: 1.0.0RC1    
Subscription  


 [2010-02-03 22:59 UTC] murat_purc (Murat Purc)
Description: ------------ Pear filter PHP_Beautifier_Filter_Pear with enabled "switch_without_indent" setting, this is enabled by default, results in invalid code, if the case block contains closing brackets in strings. Line 70 [code] if($this->oBeaut->getControlSeq() == T_SWITCH and $this->getSetting('switch_without_indent')) { [/code] should be modified as follows: [code] if($this->oBeaut->getControlSeq() == T_SWITCH and $this->getSetting('switch_without_indent') and ($this->oBeaut->getPreviousTokenConstant() == T_STRING_VARNAME) // bypass "\$${var}" and ($this->oBeaut->getPreviousTokenConstant() == T_VARIABLE) // bypass "{$variable}" and ($this->oBeaut->getPreviousTokenConstant() == T_LNUMBER) // bypass $foobar{0} ) { [/code] Test script: --------------- <?php function testFunction() { $foo = 'foo'; $bar = 'bar'; switch ($foo) { case 'foo': return "string with var having braces {$foo}{$bar}"; break; case 'bar': return $foo{0} . $bar{0}; break; default: return "\$${var}"; } } Expected result: ---------------- <?php function testFunction() { $foo = 'foo'; $bar = 'bar'; switch ($foo) { case 'foo': return "string with var having braces {$foo}{$bar}"; break; case 'bar': return $foo{0} . $bar{0}; break; default: return "\$${var}"; } } Actual result: -------------- <?php function testFunction() { $foo = 'foo'; $bar = 'bar'; switch ($foo) { case 'foo': return "string with var having braces {$foo } {$bar } "; break; case 'bar': return $foo{0 } . $bar{0 }; break; default: return "\$${var } "; } }

Comments

 [2010-02-03 23:09 UTC] murat_purc (Murat Purc)
Sorry, the solution is wrong, this works: [code] if($this->oBeaut->getControlSeq() == T_SWITCH and $this- >getSetting('switch_without_indent') and (($this->oBeaut->getPreviousTokenConstant() !== T_STRING_VARNAME) // bypass "\$${var}" and ($this->oBeaut->getPreviousTokenConstant() !== T_VARIABLE) // bypass "{$variable}" and ($this->oBeaut->getPreviousTokenConstant() !== T_LNUMBER)) // bypass $foobar{0} ) { [/code]
 [2010-03-16 07:14 UTC] clbustos (Claudio Bustos)
-Assigned To: +Assigned To: clbustos -Roadmap Versions: +Roadmap Versions: 1.0.0RC1
 [2010-08-06 04:43 UTC] clbustos (Claudio Bustos)
-Status: Assigned +Status: Closed
Works on Git.