Suppress next token in PHP_Beautify

I am using PEAR PHP_Beautifier to try to format a large amount of legacy code and achieve some formatting of the array elements.

I wrote my own filter:

class PHP_Beautifier_Filter_ArrayIndent extends PHP_Beautifier_Filter { public function t_array($sTag) { if (($this->oBeaut->getNextTokenContent(1) === '(') && ($this->oBeaut->getNextTokenContent(2) !== ')')) { // Don't use for Array type hinting // Don't use for Empty array definition $this->oBeaut->add($sTag); $this->oBeaut->addNewlineIndent(); } elseif ($this->oBeaut->getNextTokenContent(2) !== ')') { // Ensure a space after type hinted array before argument name $this->oBeaut->add($sTag . ' '); } else { // Empty array definition $this->oBeaut->add($sTag); } } } 

I am trying to get the following format (with an opening bracket on the same line as the "array"):

 public function doSomething(array $params = array()) { $dummy1 = array(); $dummy2 = array ( 'Hello' => 'World', 'Goodnight' => 'Vienna' ); } 

but I get:

 public function doSomething(array $params = array()) { $dummy1 = array(); $dummy2 = array ( 'Hello' => 'World', 'Goodnight' => 'Vienna' ); } 

Is there a way to change / abort the next token after "t_array" or skip it so that I can handle the open shape in my filter?

+4
source share
1 answer

Would this line be $this->oBeaut->addNewlineIndent(); what causes a new line, should it not be deleted or changed in another way?

Sentence:

 <?php if (($this->oBeaut->getNextTokenContent(1) === '(') && ($this->oBeaut->getNextTokenContent(2) !== ')')) { $this->oBeaut->add($sTag); } elseif ($this->oBeaut->getNextTokenContent(2) !== ')') { // Ensure a space after type hinted array before argument name $this->oBeaut->add($sTag . ' '); } else { // Empty array definition $this->oBeaut->add($sTag); } 
+1
source

All Articles