Skip to content

Commit 7eb7569

Browse files
committed
Method, ClassType: better whitespace usage
1 parent 37f5128 commit 7eb7569

File tree

9 files changed

+7
-89
lines changed

9 files changed

+7
-89
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ public function __toString()
157157
. $this->name . ' '
158158
. ($this->extends ? 'extends ' . implode(', ', $extends) . ' ' : '')
159159
. ($this->implements ? 'implements ' . implode(', ', $implements) . ' ' : '')
160-
. "\n{\n\n"
160+
. "\n{\n"
161161
. Strings::indent(
162162
($this->traits ? 'use ' . implode(', ', $traits) . ";\n\n" : '')
163-
. ($this->consts ? implode('', $consts) . "\n\n" : '')
164-
. ($this->properties ? implode("\n", $properties) . "\n\n" : '')
165-
. implode("\n\n\n", $this->methods), 1)
166-
. "\n\n}"
163+
. ($this->consts ? implode('', $consts) . "\n" : '')
164+
. ($this->properties ? implode("\n", $properties) . "\n" : '')
165+
. ($this->methods ? "\n" . implode("\n\n\n", $this->methods) . "\n\n" : ''), 1)
166+
. '}'
167167
) . "\n";
168168
}
169169

src/PhpGenerator/Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function __toString()
108108
. '(' . implode(', ', $parameters) . ')'
109109
. ($this->uses ? ' use (' . implode(', ', $uses) . ')' : '')
110110
. ($this->abstract || $this->body === FALSE ? ';'
111-
: ($this->name ? "\n" : ' ') . "{\n" . Nette\Utils\Strings::indent(trim($this->body), 1) . "\n}");
111+
: ($this->name ? "\n" : ' ') . "{\n" . Nette\Utils\Strings::indent(ltrim(rtrim($this->body) . "\n"), 1) . '}');
112112
}
113113

114114

tests/PhpGenerator/ClassType.expect

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
*/
77
abstract final class Example extends ParentClass implements IExample, IOne
88
{
9-
109
use ObjectTrait;
1110

1211
const ROLE = 'admin';
1312
const FORCE_ARRAY = Nette\Utils\Json::FORCE_ARRAY;
1413

15-
1614
/** @var resource orignal file handle */
1715
private $handle;
1816

tests/PhpGenerator/ClassType.from.expect

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ interface Interface1
1111

1212
interface Interface2
1313
{
14-
15-
16-
1714
}
1815

1916
abstract class Class1 implements Interface1
@@ -24,7 +21,6 @@ abstract class Class1 implements Interface1
2421
*/
2522
function func1()
2623
{
27-
2824
}
2925

3026

@@ -34,7 +30,6 @@ abstract class Class1 implements Interface1
3430

3531
class Class2 extends Class1 implements Interface2
3632
{
37-
3833
/**
3934
* Public
4035
* @var int
@@ -55,13 +50,11 @@ class Class2 extends Class1 implements Interface2
5550
*/
5651
private function & func3(array $a%a?%, Class2 $b = NULL, Unknown $c, \Xyz\Unknown $d, $e)
5752
{
58-
5953
}
6054

6155

6256
final function func2()
6357
{
64-
6558
}
6659

6760
}

tests/PhpGenerator/ClassType.from.trait.expect

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ trait Trait1
66

77
function func1()
88
{
9-
109
}
1110

1211
}
@@ -16,7 +15,6 @@ trait Trait2
1615

1716
protected function func2()
1817
{
19-
2018
}
2119

2220
}
@@ -26,20 +24,15 @@ abstract class Class1
2624

2725
function func1()
2826
{
29-
3027
}
3128

3229

3330
protected function func2()
3431
{
35-
3632
}
3733

3834
}
3935

4036
class Class2 extends Class1
4137
{
42-
43-
44-
4538
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
class B extends A
22
{
3-
43
public $d;
54

65
protected $e;
@@ -10,7 +9,6 @@ class B extends A
109

1110
function bar()
1211
{
13-
1412
}
1513

1614
}

tests/PhpGenerator/PhpFile.bracketed.expect

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,16 @@ namespace Foo {
99

1010
class A implements A, \Bar\C
1111
{
12-
1312
use C, \Bar\D;
1413

15-
16-
1714
}
1815

1916
interface B
2017
{
21-
22-
23-
2418
}
2519

2620
trait C
2721
{
28-
29-
30-
3122
}
3223

3324
}
@@ -37,25 +28,16 @@ namespace Bar {
3728

3829
class B extends \Foo\A implements \Foo\B
3930
{
40-
4131
use \Foo\C;
4232

43-
44-
4533
}
4634

4735
interface C
4836
{
49-
50-
51-
5237
}
5338

5439
trait D
5540
{
56-
57-
58-
5941
}
6042

6143
}
@@ -65,23 +47,14 @@ namespace Baz {
6547

6648
class E
6749
{
68-
69-
70-
7150
}
7251

7352
interface F extends \Foo\B, \Bar\C
7453
{
75-
76-
77-
7854
}
7955

8056
trait G
8157
{
82-
83-
84-
8558
}
8659

8760
}
@@ -91,9 +64,6 @@ namespace {
9164

9265
class H
9366
{
94-
95-
96-
9767
}
9868

9969
}
@@ -103,9 +73,6 @@ namespace FooBar {
10373

10474
class I
10575
{
106-
107-
108-
10976
}
11077

11178
}

tests/PhpGenerator/PhpFile.regular.expect

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,73 +9,46 @@ namespace Foo;
99

1010
class A implements A, \Bar\C
1111
{
12-
1312
use C, \Bar\D;
1413

15-
16-
1714
}
1815

1916
interface B
2017
{
21-
22-
23-
2418
}
2519

2620
trait C
2721
{
28-
29-
30-
3122
}
3223

3324

3425
namespace Bar;
3526

3627
class B extends \Foo\A implements \Foo\B
3728
{
38-
3929
use \Foo\C;
4030

41-
42-
4331
}
4432

4533
interface C
4634
{
47-
48-
49-
5035
}
5136

5237
trait D
5338
{
54-
55-
56-
5739
}
5840

5941

6042
namespace Baz;
6143

6244
class E
6345
{
64-
65-
66-
6746
}
6847

6948
interface F extends \Foo\B, \Bar\C
7049
{
71-
72-
73-
7450
}
7551

7652
trait G
7753
{
78-
79-
80-
8154
}

tests/PhpGenerator/PhpNamespace.expect

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@ use Bar\C;
44

55
class A implements A, C
66
{
7-
87
use \Bar\D;
98

9+
1010
public function test(C $test)
1111
{
12-
1312
}
1413

1514
}
1615

1716
interface B
1817
{
19-
20-
21-
2218
}

0 commit comments

Comments
 (0)