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-04 03:59 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  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 31 - 9 = ?

 
 [2010-02-04 03: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-04 04: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 11:14 UTC] clbustos (Claudio Bustos)
-Assigned To: +Assigned To: clbustos -Roadmap Versions: +Roadmap Versions: 1.0.0RC1
 [2010-08-06 09:43 UTC] clbustos (Claudio Bustos)
-Status: Assigned +Status: Closed
Works on Git.