Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix IndentStyles so open brace after object operator isn't treated as

the start of a block (use openBraceDontProcess).  Also avoid trailing
spaces after "if ()", etc., in styles that put open brace on new line.
  • Loading branch information...
commit daa2311a5dc6ff09239040849b51acc9bb5aab5c 1 parent 021e8fb
@kcivey kcivey authored
View
47 Beautifier/Filter/IndentStyles.filter.php
@@ -153,13 +153,18 @@ public function __call($sMethod, $aArgs)
*/
function t_open_brace_bsd($sTag)
{
- $this->oBeaut->addNewLineIndent();
- $this->oBeaut->add($sTag);
- if ($this->oBeaut->getControlSeq() == T_SWITCH) {
+ if ($this->oBeaut->openBraceDontProcess()) {
+ $this->oBeaut->add($sTag);
+ } else {
+ $this->oBeaut->removeWhitespace();
+ $this->oBeaut->addNewLineIndent();
+ $this->oBeaut->add($sTag);
+ if ($this->oBeaut->getControlSeq() == T_SWITCH) {
+ $this->oBeaut->incIndent();
+ }
$this->oBeaut->incIndent();
+ $this->oBeaut->addNewLineIndent();
}
- $this->oBeaut->incIndent();
- $this->oBeaut->addNewLineIndent();
}
/**
* t_close_brace_bsd: Close braces in BSD style
@@ -194,11 +199,16 @@ function t_close_brace_bsd($sTag)
*/
function t_open_brace_ws($sTag)
{
- $this->oBeaut->addNewLine();
- $this->oBeaut->incIndent();
- $this->oBeaut->addIndent();
- $this->oBeaut->add($sTag);
- $this->oBeaut->addNewLineIndent();
+ if ($this->oBeaut->openBraceDontProcess()) {
+ $this->oBeaut->add($sTag);
+ } else {
+ $this->oBeaut->removeWhitespace();
+ $this->oBeaut->addNewLine();
+ $this->oBeaut->incIndent();
+ $this->oBeaut->addIndent();
+ $this->oBeaut->add($sTag);
+ $this->oBeaut->addNewLineIndent();
+ }
}
/**
* t_close_brace_ws: Close braces in Whitesmiths style
@@ -252,12 +262,17 @@ function t_close_brace_gnu($sTag)
*/
function t_open_brace_gnu($sTag)
{
- $iHalfSpace = floor($this->oBeaut->iIndentNumber/2);
- $this->oBeaut->addNewLineIndent();
- $this->oBeaut->add(str_repeat($this->oBeaut->sIndentChar, $iHalfSpace));
- $this->oBeaut->add($sTag);
- $this->oBeaut->incIndent();
- $this->oBeaut->addNewLineIndent();
+ if ($this->oBeaut->openBraceDontProcess()) {
+ $this->oBeaut->add($sTag);
+ } else {
+ $this->oBeaut->removeWhitespace();
+ $iHalfSpace = floor($this->oBeaut->iIndentNumber/2);
+ $this->oBeaut->addNewLineIndent();
+ $this->oBeaut->add(str_repeat($this->oBeaut->sIndentChar, $iHalfSpace));
+ $this->oBeaut->add($sTag);
+ $this->oBeaut->incIndent();
+ $this->oBeaut->addNewLineIndent();
+ }
}
/**
* t_else: Else for bds, gnu & ws
View
14 tests/Beautifier/Filter/indentstyles_bsd_sample_file.phps
@@ -1,8 +1,20 @@
<?php
-if ($x == 1)
+if ($x == 1)
{
$x = "Any text with {$x} sign";
}
+elseif ($x == 2)
+{
+ $x = "Any text with ${x} sign";
+}
+else
+{
+ $x = $object->{$property};
+}
if ($x == 1) $x = 2;
else $x = 3;
+while ($i++ < 4)
+{
+ $obj->{'set' . $prop}($i);
+}
?>
View
16 tests/Beautifier/Filter/indentstyles_gnu_sample_file.phps
@@ -1,6 +1,20 @@
<?php
-if ($x == 1)
+if ($x == 1)
{
$x = "Any text with {$x} sign";
}
+elseif ($x == 2)
+ {
+ $x = "Any text with ${x} sign";
+ }
+else
+ {
+ $x = $object->{$property};
+ }
+if ($x == 1) $x = 2;
+else $x = 3;
+while ($i++ < 4)
+ {
+ $obj->{'set' . $prop}($i);
+ }
?>
View
11 tests/Beautifier/Filter/indentstyles_kr_sample_file.phps
@@ -2,4 +2,15 @@
if ($x == 1) {
$x = "Any text with {$x} sign";
}
+elseif ($x == 2) {
+ $x = "Any text with ${x} sign";
+}
+else {
+ $x = $object->{$property};
+}
+if ($x == 1) $x = 2;
+else $x = 3;
+while ($i++ < 4) {
+ $obj->{'set' . $prop}($i);
+}
?>
View
16 tests/Beautifier/Filter/indentstyles_ws_sample_file.phps
@@ -1,6 +1,20 @@
<?php
-if ($x == 1)
+if ($x == 1)
{
$x = "Any text with {$x} sign";
}
+elseif ($x == 2)
+ {
+ $x = "Any text with ${x} sign";
+ }
+else
+ {
+ $x = $object->{$property};
+ }
+if ($x == 1) $x = 2;
+else $x = 3;
+while ($i++ < 4)
+ {
+ $obj->{'set' . $prop}($i);
+ }
?>
Please sign in to comment.
Something went wrong with that request. Please try again.