Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit ea00686

Browse files
authored
Merge pull request #134 from Tobion/short-array-syntax
use short array syntax by default with param type array
2 parents 0294464 + 5d634c5 commit ea00686

13 files changed

+30
-30
lines changed

src/Generator/ValueGenerator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function getConstants()
185185
*/
186186
public function isValidConstantType()
187187
{
188-
if ($this->type == self::TYPE_AUTO) {
188+
if ($this->type === self::TYPE_AUTO) {
189189
$type = $this->getAutoDeterminedType($this->value);
190190
} else {
191191
$type = $this->type;
@@ -336,13 +336,13 @@ public function generate()
336336
{
337337
$type = $this->type;
338338

339-
if ($type != self::TYPE_AUTO) {
339+
if ($type !== self::TYPE_AUTO) {
340340
$type = $this->getValidatedType($type);
341341
}
342342

343343
$value = $this->value;
344344

345-
if ($type == self::TYPE_AUTO) {
345+
if ($type === self::TYPE_AUTO) {
346346
$type = $this->getAutoDeterminedType($value);
347347
}
348348

@@ -388,12 +388,12 @@ public function generate()
388388
case self::TYPE_ARRAY:
389389
case self::TYPE_ARRAY_LONG:
390390
case self::TYPE_ARRAY_SHORT:
391-
if ($type == self::TYPE_ARRAY_SHORT) {
392-
$startArray = '[';
393-
$endArray = ']';
394-
} else {
391+
if ($type === self::TYPE_ARRAY_LONG) {
395392
$startArray = 'array(';
396-
$endArray = ')';
393+
$endArray = ')';
394+
} else {
395+
$startArray = '[';
396+
$endArray = ']';
397397
}
398398

399399
$output .= $startArray;

test/Generator/MethodGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function testDefaultValueGenerationDoesNotIncludeTrailingSemicolon()
233233

234234
$method->setParameter($param);
235235
$generated = $method->generate();
236-
self::assertRegExp('/array \$options = array\(\)\)/', $generated, $generated);
236+
self::assertContains('array $options = [])', $generated);
237237
}
238238

239239
public function testCreateFromArray()

test/Generator/ParameterGeneratorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ public function dataFromReflectionGenerate()
181181
['defaultNull', '$value = null'],
182182
['fromArray', 'array $array'],
183183
['hasNativeDocTypes', '$integer'],
184-
['defaultArray', '$array = array()'],
185-
['defaultArrayWithValues', '$array = array(1, 2, 3)'],
184+
['defaultArray', '$array = []'],
185+
['defaultArrayWithValues', '$array = [1, 2, 3]'],
186186
['defaultFalse', '$val = false'],
187187
['defaultTrue', '$val = true'],
188188
['defaultZero', '$number = 0'],

test/Generator/PropertyGeneratorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ public function testPropertyMultilineValue() : void
108108
];
109109

110110
$expectedSource = <<<EOS
111-
public \$myFoo = array(
111+
public \$myFoo = [
112112
5,
113113
'one' => 1,
114114
'two' => '2',
115115
'null' => null,
116116
'true' => true,
117117
'bar\'s' => 'bar\'s',
118-
);
118+
];
119119
EOS;
120120

121121
$property = new PropertyGenerator('myFoo', $targetValue);

test/Generator/TestAsset/ParameterClass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function fromArray(array $array)
4040

4141
}
4242

43-
public function defaultArray($array = array())
43+
public function defaultArray($array = [])
4444
{
4545

4646
}
@@ -70,7 +70,7 @@ public function defaultFloat($float = 1.34)
7070

7171
}
7272

73-
public function defaultArrayWithValues($array = array(0 => 1, 1 => 2, 2 => 3))
73+
public function defaultArrayWithValues($array = [0 => 1, 1 => 2, 2 => 3])
7474
{
7575

7676
}

test/Generator/TestAsset/TestClassWithManyProperties.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ class TestClassWithManyProperties
2727

2828
private static $_bazStaticProperty = self::FOO;
2929

30-
private $_bazProperty = array(true, false, true);
30+
private $_bazProperty = [true, false, true];
3131

32-
protected $_complexType = array(
32+
protected $_complexType = [
3333
5,
3434
'one' => 1,
3535
'two' => '2',
36-
array(
36+
[
3737
'bar',
3838
'baz',
3939
"\n"
40-
)
41-
);
40+
]
41+
];
4242

4343
}

test/Generator/ValueGeneratorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function validConstantTypes()
9292
return [
9393
[
9494
new PropertyValueGenerator([], PropertyValueGenerator::TYPE_ARRAY, ValueGenerator::OUTPUT_SINGLE_LINE),
95-
' const FOO = array();',
95+
' const FOO = [];',
9696
],
9797
[
9898
new PropertyValueGenerator(
@@ -139,12 +139,12 @@ protected function generateArrayData($longOutput, array $value)
139139
'auto' => [
140140
ValueGenerator::TYPE_AUTO,
141141
$value,
142-
$longOutput,
142+
$shortOutput,
143143
],
144144
'array' => [
145145
ValueGenerator::TYPE_ARRAY,
146146
$value,
147-
$longOutput,
147+
$shortOutput,
148148
],
149149
'array long' => [
150150
ValueGenerator::TYPE_ARRAY_LONG,

test/Reflection/ClassReflectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function getProp2(\$param1, TestSampleClass \$param2)
100100
101101
public function getIterator()
102102
{
103-
return array();
103+
return [];
104104
}
105105
106106
}
@@ -133,7 +133,7 @@ public function getProp2(\$param1, TestSampleClass \$param2)
133133
134134
public function getIterator()
135135
{
136-
return array();
136+
return [];
137137
}
138138
139139
}

test/Reflection/TestAsset/TestSampleClass2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function getProp2($param1, TestSampleClass $param2)
2525

2626
public function getIterator()
2727
{
28-
return array();
28+
return [];
2929
}
3030

3131
}

test/Reflection/TestAsset/TestSampleClass9.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function getProp2($param1, TestSampleClass $param2)
2727

2828
public function getIterator()
2929
{
30-
return array();
30+
return [];
3131
}
3232

3333
}

0 commit comments

Comments
 (0)