Skip to content

Commit d422cac

Browse files
committed
Printer: one-line properties without comments are not separated using one empty line
1 parent 262cd4c commit d422cac

File tree

8 files changed

+4
-16
lines changed

8 files changed

+4
-16
lines changed

src/PhpGenerator/Printer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ public function printClass(ClassType $class, PhpNamespace $namespace = null): st
138138

139139
$members = array_filter([
140140
implode('', $traits),
141-
preg_replace('#^(\w.*\n)\n(?=\w)#m', '$1', implode("\n", $consts)),
142-
implode("\n", $properties),
141+
preg_replace('#^(\w.*\n)\n(?=\w.*;)#m', '$1', implode("\n", $consts)),
142+
preg_replace('#^(\w.*\n)\n(?=\w.*;)#m', '$1', implode("\n", $properties)),
143143
($methods && $properties ? str_repeat("\n", $this->linesBetweenMethods - 1) : '')
144144
. implode(str_repeat("\n", $this->linesBetweenMethods), $methods),
145145
]);

tests/PhpGenerator/expected/ClassType.expect

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@ abstract class Example extends ParentClass implements IExample, IOne
1919

2020
/** @var resource orignal file handle */
2121
private $handle;
22-
2322
public $order = RecursiveIteratorIterator::SELF_FIRST;
24-
2523
public array $typed1;
26-
2724
public ?array $typed2 = null;
28-
2925
public static $sections = ['first' => true];
3026

3127

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
class Class7
22
{
33
public \A $a;
4-
54
public ?\B $b;
6-
75
public ?\C $c = null;
8-
96
public ?int $i = 1;
107
}

tests/PhpGenerator/expected/ClassType.from.anonymous.expect

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
public $a;
3-
43
private $b;
54

65

tests/PhpGenerator/expected/ClassType.from.expect

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ class Class2 extends Class1 implements Interface2
3434

3535
/** @var int */
3636
protected $protected = 10;
37-
3837
private $private = [];
39-
4038
public static $static;
4139

4240

tests/PhpGenerator/expected/ClassType.inheritance.expect

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
class B extends A implements I3
22
{
33
public $d;
4-
54
protected $e;
6-
75
private $f;
86

97

tests/PhpGenerator/expected/Printer.class.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ final class Example extends ParentClass implements IExample
1111

1212
/** Commented */
1313
private const FORCE_ARRAY = Nette\Utils\Json::FORCE_ARRAY;
14+
1415
const MULTILINE_LONG = [
1516
'aaaaaaaa' => 1,
1617
'bbbbbbbb' => 2,
@@ -24,7 +25,6 @@ final class Example extends ParentClass implements IExample
2425

2526
/** @var resource orignal file handle */
2627
private $handle;
27-
2828
public $order = RecursiveIteratorIterator::SELF_FIRST;
2929

3030
public $multilineLong = [

tests/PhpGenerator/expected/PsrPrinter.class.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ final class Example extends ParentClass implements IExample
1111

1212
/** Commented */
1313
private const FORCE_ARRAY = Nette\Utils\Json::FORCE_ARRAY;
14+
1415
const MULTILINE_LONG = [
1516
'aaaaaaaa' => 1,
1617
'bbbbbbbb' => 2,
@@ -24,7 +25,6 @@ final class Example extends ParentClass implements IExample
2425

2526
/** @var resource orignal file handle */
2627
private $handle;
27-
2828
public $order = RecursiveIteratorIterator::SELF_FIRST;
2929

3030
public $multilineLong = [

0 commit comments

Comments
 (0)