Skip to content

Commit a644d35

Browse files
committed
Merge branch 'release/4.1.0'
2 parents fa82b32 + 2deb7ae commit a644d35

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG
22

3+
## 4.1.1 - 2021/02/05
4+
- issue #12 - Use array short notation
5+
36
## 4.0.1 - 2021/02/04
47
- Add back `getMainElement` method to `AbstractComponent`
58

src/Element/AssignedValueElementTrait.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,14 @@ protected function getScalarValue($value)
9999

100100
protected function getAnyValue($value): string
101101
{
102-
$exportedValue = var_export($value, true);
102+
if (is_array($value)) {
103+
$exportedValue = empty($value) ? '[]' : implode("\n", array_map(function ($line) {
104+
return 'array (' === $line ? '[' : (')' === $line ? ']' : $line);
105+
}, explode("\n", var_export($value, true))));
106+
} else {
107+
$exportedValue = var_export($value, true);
108+
}
109+
103110
// work around for known bug https://bugs.php.net/bug.php?id=66866
104111
if (is_float($value) && strlen((string) $value) !== strlen((string) $exportedValue)) {
105112
$exportedValue = (string) $value;

src/Element/PhpFunctionParameter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function endsWithSemicolon(): bool
2727
protected function getAnyValue($value): string
2828
{
2929
if (is_array($value)) {
30-
return str_replace([self::BREAK_LINE_CHAR, ' '], '', var_export($value, true));
30+
return str_replace([self::BREAK_LINE_CHAR, ' '], '', parent::getAnyValue($value));
3131
}
3232

3333
return parent::getAnyValue($value);

tests/Element/PhpFunctionParameterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testToStringEmptyArrayValue()
7070
{
7171
$functionParameter = new PhpFunctionParameter('foo', [], 'array');
7272

73-
$this->assertSame('array $foo = array()', $functionParameter->toString());
73+
$this->assertSame('array $foo = []', $functionParameter->toString());
7474
}
7575

7676
public function testToStringWithNamespace()

tests/Element/PhpPropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testPublicGetPhpDeclarationArray()
8787
1,
8888
]);
8989

90-
$this->assertSame("public \$foo = array (\n 0 => '0',\n 1 => 1,\n);", $property->getPhpDeclaration());
90+
$this->assertSame("public \$foo = [\n 0 => '0',\n 1 => 1,\n];", $property->getPhpDeclaration());
9191
}
9292

9393
public function testPublicGetPhpDeclarationNewInstance()

tests/Element/PhpVariableTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,21 @@ public function testGetPhpDeclarationNumberOneValue()
5050
$this->assertSame('$foo = 1;', $variable->getPhpDeclaration());
5151
}
5252

53+
public function testGetPhpDeclarationEmptyArrayValue()
54+
{
55+
$variable = new PhpVariable('foo', []);
56+
57+
$this->assertSame("\$foo = [];", $variable->getPhpDeclaration());
58+
}
59+
5360
public function testGetPhpDeclarationArray()
5461
{
5562
$variable = new PhpVariable('foo', [
5663
'0',
5764
1,
5865
]);
5966

60-
$this->assertSame("\$foo = array (\n 0 => '0',\n 1 => 1,\n);", $variable->getPhpDeclaration());
67+
$this->assertSame("\$foo = [\n 0 => '0',\n 1 => 1,\n];", $variable->getPhpDeclaration());
6168
}
6269

6370
public function testGetPhpDeclarationNewInstance()

0 commit comments

Comments
 (0)