diff --git a/Beautifier/Common.php b/Beautifier/Common.php
index 23fb48f..25c31b6 100755
--- a/Beautifier/Common.php
+++ b/Beautifier/Common.php
@@ -192,7 +192,7 @@ public static function getLog()
* @param string
* @return string
*/
- function wsToString($sText)
+ public static function wsToString($sText)
{
// ArrayNested->off();
return str_replace(array("\r", "\n", "\t"), array('\r', '\n', '\t'), $sText);
@@ -235,4 +235,4 @@ public function get();
*/
public function save($sFile = null);
}
-?>
\ No newline at end of file
+?>
diff --git a/Beautifier/Filter/Pear.filter.php b/Beautifier/Filter/Pear.filter.php
index 786e27f..9b7d940 100755
--- a/Beautifier/Filter/Pear.filter.php
+++ b/Beautifier/Filter/Pear.filter.php
@@ -1,7 +1,7 @@
* $oBeaut->addFilter('Pear',array('add_header'=>'php'));
*
+ * Two extra options allows to break the spec about newline before braces
+ * on function and classes. By default, they are set to true. Use
+ *
+ * $oBeaut->addFilter('Pear',array('newline_class'=>false, 'newline_function'=>false));
+ *
* @category PHP
* @package PHP_Beautifier
* @subpackage Filter
@@ -53,9 +58,7 @@
*/
class PHP_Beautifier_Filter_Pear extends PHP_Beautifier_Filter
{
- protected $aSettings = array(
- 'add_header' => false
- );
+ protected $aSettings = array('add_header' => false, 'newline_class' => true, 'newline_function' => true);
protected $sDescription = 'Filter the code to make it compatible with PEAR Coding Specs';
private $bOpenTag = false;
function t_open_tag_with_echo($sTag)
@@ -64,16 +67,17 @@ function t_open_tag_with_echo($sTag)
}
function t_semi_colon($sTag)
{
- // TODO: What is the function of this structure?
- // I don't remember it....
+ // A break statement and the next statement are separated by an empty line
if ($this->oBeaut->isPreviousTokenConstant(T_BREAK)) {
$this->oBeaut->removeWhitespace();
- $this->oBeaut->add($sTag);
- $this->oBeaut->addNewLine();
+ $this->oBeaut->add($sTag); // add the semicolon
+ $this->oBeaut->addNewLine(); // empty line
$this->oBeaut->addNewLineIndent();
} elseif ($this->oBeaut->getControlParenthesis() == T_FOR) {
+ // The three terms in the head of a for loop are separated by the string "; "
$this->oBeaut->removeWhitespace();
$this->oBeaut->add($sTag . " "); // Bug 8327
+
} else {
return PHP_Beautifier_Filter::BYPASS;
}
@@ -97,10 +101,20 @@ function t_default($sTag)
function t_break($sTag)
{
$this->oBeaut->add($sTag);
+ if ($this->oBeaut->isNextTokenConstant(T_LNUMBER)) {
+ $this->oBeaut->add(" ");
+ }
}
function t_open_brace($sTag)
{
- if ($this->oBeaut->getControlSeq() != T_CLASS and $this->oBeaut->getControlSeq() != T_FUNCTION) {
+ $bypass = true;
+ if ($this->oBeaut->getControlSeq() == T_CLASS and $this->getSetting('newline_class')) {
+ $bypass = false;
+ }
+ if ($this->oBeaut->getControlSeq() == T_FUNCTION and $this->getSetting('newline_function')) {
+ $bypass = false;
+ }
+ if ($bypass) {
return PHP_Beautifier_Filter::BYPASS;
}
$this->oBeaut->addNewLineIndent();
@@ -163,4 +177,4 @@ function addHeaderComment()
$this->oBeaut->addNewLineIndent();
}
}
-?>
\ No newline at end of file
+?>
diff --git a/package2.xml b/package2.xml
index 99c8cc6..2f353c3 100644
--- a/package2.xml
+++ b/package2.xml
@@ -15,10 +15,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
clbustos+php_beautifier@gmail.comyes
- 2007-02-10
-
+ 2007-02-14
+
- 0.1.12
+ 0.1.130.1.12
@@ -26,15 +26,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
betaPHP License
- Bug fix release
-- Bug fix[9078]:php_beautifier script use addFilter defore addFilterDirectory. Fixed file php_beautifier
-- Bug fix[7706 and rolfhub_at_web.de 2007-02-07-1]: The beautifer removes the whitespaces left and right of the operator, so for example "echo 2 . 1 . 0 . "\n";" becomes "echo 2.1.0."\n";". Added space after and before questions.
-- Bug fix[rolfhub_at_web.de 2007-02-07-2]: When using the "break" command, the command takes an optional parameter, see http://de.php.net/break for details. But this doesn't work when using the beautifier, because, for example "break 2;" morphs to "break2;"
-- Bug fix[rolfhub_at_web.de 2007-01-31]: I think that I have found and fixed a bug in the PHP Beautifier, in the file Common.php in the function getFilesByGlob(). It fails if used under MS-Windows because of the different path separators.
-- Bug fix[8327]: There is one extra space before semicolon in Pear filter
-+ Added -h option on php_beautifier for usage message
-+ New package2.xml
-
+ Small Rolf bug fix release:
+- Bug fix[rolfhub_at_web.de 2007-02-07-2/pear]: Pear filter delete the space between break and a number.
+- Bug fix[rolfhub_at_web.de 2007-02-12]: function wsToString($sText) to public static function wsToString($sText)
++ Two new settings on Pear filter: "newline_class" and "newline_class"
@@ -224,6 +219,28 @@ http://pear.php.net/dtd/package-2.0.xsd">
+
+
+ 0.1.12
+ 0.1.12
+
+
+ beta
+ beta
+
+2007-02-10
+ PHP License
+ Bug fix release
+- Bug fix[9078]:php_beautifier script use addFilter defore addFilterDirectory. Fixed file php_beautifier
+- Bug fix[7706 and rolfhub_at_web.de 2007-02-07-1]: The beautifer removes the whitespaces left and right of the operator, so for example "echo 2 . 1 . 0 . "\n";" becomes "echo 2.1.0."\n";". Added space after and before questions.
+- Bug fix[rolfhub_at_web.de 2007-02-07-2]: When using the "break" command, the command takes an optional parameter, see http://de.php.net/break for details. But this doesn't work when using the beautifier, because, for example "break 2;" morphs to "break2;"
+- Bug fix[rolfhub_at_web.de 2007-01-31]: I think that I have found and fixed a bug in the PHP Beautifier, in the file Common.php in the function getFilesByGlob(). It fails if used under MS-Windows because of the different path separators.
+- Bug fix[8327]: There is one extra space before semicolon in Pear filter
++ Added -h option on php_beautifier for usage message
++ New package2.xml
+
+
+ 0.1.11
diff --git a/tests/Beautifier_Bugs.phpt b/tests/Beautifier_Bugs.phpt
index 924e667..43d9468 100755
--- a/tests/Beautifier_Bugs.phpt
+++ b/tests/Beautifier_Bugs.phpt
@@ -545,7 +545,49 @@ while (++\$i) {
SCRIPT;
$this->assertEquals($sExpected, $this->oBeaut->get());
}
+ /**
+ * When using the "break" command, the command takes an optional parameter, see http://de.php.net/break for details. But this doesn't work when using the beautifier, because, for example "break 2;" morphs to "break2;" (notice the missing space, which makes the PHP interpreter quite sour :-(
+ */
+ function testBug_rolfhub_2007_02_07_1_pear() {
+ $this->oBeaut->addFilter("Pear");
+ $sText=<<";
+ break 1; /* Exit only the switch. */
+ case 10:
+ echo "At 10; quitting ";
+ break 2; /* Exit the switch and the while. */
+ default:
+ break;
+ }
+}
+?>
+SCRIPT;
+$this->setText($sText);
+ $sExpected = <<";
+ break 1; /* Exit only the switch. */
+ case 10:
+ echo "At 10; quitting ";
+ break 2; /* Exit the switch and the while. */
+ default:
+ break;
+ }
+}
+?>
+SCRIPT;
+ $this->assertEquals($sExpected, $this->oBeaut->get());
+ }
/**
* The beautifer removes the whitespaces left and right of the operator, so for example "echo 2 . 1 . 0 . "\n";" becomes "echo 2.1.0."\n";"
*/