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

use short array syntax by default with param type array #134

Merged
merged 1 commit into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Generator/ValueGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function getConstants()
*/
public function isValidConstantType()
{
if ($this->type == self::TYPE_AUTO) {
if ($this->type === self::TYPE_AUTO) {
$type = $this->getAutoDeterminedType($this->value);
} else {
$type = $this->type;
Expand Down Expand Up @@ -336,13 +336,13 @@ public function generate()
{
$type = $this->type;

if ($type != self::TYPE_AUTO) {
if ($type !== self::TYPE_AUTO) {
$type = $this->getValidatedType($type);
}

$value = $this->value;

if ($type == self::TYPE_AUTO) {
if ($type === self::TYPE_AUTO) {
$type = $this->getAutoDeterminedType($value);
}

Expand Down Expand Up @@ -388,12 +388,12 @@ public function generate()
case self::TYPE_ARRAY:
case self::TYPE_ARRAY_LONG:
case self::TYPE_ARRAY_SHORT:
if ($type == self::TYPE_ARRAY_SHORT) {
$startArray = '[';
$endArray = ']';
} else {
if ($type === self::TYPE_ARRAY_LONG) {
$startArray = 'array(';
$endArray = ')';
$endArray = ')';
} else {
$startArray = '[';
$endArray = ']';
}

$output .= $startArray;
Expand Down
2 changes: 1 addition & 1 deletion test/Generator/MethodGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function testDefaultValueGenerationDoesNotIncludeTrailingSemicolon()

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

public function testCreateFromArray()
Expand Down
4 changes: 2 additions & 2 deletions test/Generator/ParameterGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ public function dataFromReflectionGenerate()
['defaultNull', '$value = null'],
['fromArray', 'array $array'],
['hasNativeDocTypes', '$integer'],
['defaultArray', '$array = array()'],
['defaultArrayWithValues', '$array = array(1, 2, 3)'],
['defaultArray', '$array = []'],
['defaultArrayWithValues', '$array = [1, 2, 3]'],
['defaultFalse', '$val = false'],
['defaultTrue', '$val = true'],
['defaultZero', '$number = 0'],
Expand Down
4 changes: 2 additions & 2 deletions test/Generator/PropertyGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ public function testPropertyMultilineValue() : void
];

$expectedSource = <<<EOS
public \$myFoo = array(
public \$myFoo = [
5,
'one' => 1,
'two' => '2',
'null' => null,
'true' => true,
'bar\'s' => 'bar\'s',
);
];
EOS;

$property = new PropertyGenerator('myFoo', $targetValue);
Expand Down
4 changes: 2 additions & 2 deletions test/Generator/TestAsset/ParameterClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function fromArray(array $array)

}

public function defaultArray($array = array())
public function defaultArray($array = [])
{

}
Expand Down Expand Up @@ -70,7 +70,7 @@ public function defaultFloat($float = 1.34)

}

public function defaultArrayWithValues($array = array(0 => 1, 1 => 2, 2 => 3))
public function defaultArrayWithValues($array = [0 => 1, 1 => 2, 2 => 3])
{

}
Expand Down
10 changes: 5 additions & 5 deletions test/Generator/TestAsset/TestClassWithManyProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ class TestClassWithManyProperties

private static $_bazStaticProperty = self::FOO;

private $_bazProperty = array(true, false, true);
private $_bazProperty = [true, false, true];

protected $_complexType = array(
protected $_complexType = [
5,
'one' => 1,
'two' => '2',
array(
[
'bar',
'baz',
"\n"
)
);
]
];

}
6 changes: 3 additions & 3 deletions test/Generator/ValueGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function validConstantTypes()
return [
[
new PropertyValueGenerator([], PropertyValueGenerator::TYPE_ARRAY, ValueGenerator::OUTPUT_SINGLE_LINE),
' const FOO = array();',
' const FOO = [];',
],
[
new PropertyValueGenerator(
Expand Down Expand Up @@ -139,12 +139,12 @@ protected function generateArrayData($longOutput, array $value)
'auto' => [
ValueGenerator::TYPE_AUTO,
$value,
$longOutput,
$shortOutput,
],
'array' => [
ValueGenerator::TYPE_ARRAY,
$value,
$longOutput,
$shortOutput,
],
'array long' => [
ValueGenerator::TYPE_ARRAY_LONG,
Expand Down
4 changes: 2 additions & 2 deletions test/Reflection/ClassReflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function getProp2(\$param1, TestSampleClass \$param2)

public function getIterator()
{
return array();
return [];
}

}
Expand Down Expand Up @@ -133,7 +133,7 @@ public function getProp2(\$param1, TestSampleClass \$param2)

public function getIterator()
{
return array();
return [];
}

}
Expand Down
2 changes: 1 addition & 1 deletion test/Reflection/TestAsset/TestSampleClass2.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getProp2($param1, TestSampleClass $param2)

public function getIterator()
{
return array();
return [];
}

}
2 changes: 1 addition & 1 deletion test/Reflection/TestAsset/TestSampleClass9.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getProp2($param1, TestSampleClass $param2)

public function getIterator()
{
return array();
return [];
}

}
2 changes: 1 addition & 1 deletion test/Scanner/MethodScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function testMethodScannerMethodSignatureLatestOptionalParamHasParenthese
$method = $class->getMethod('four');
$paramTwo = $method->getParameter(1);
$optionalValue = $paramTwo->getDefaultValue();
self::assertEquals('array(array(array(\'default\')))', $optionalValue);
self::assertEquals('array([array(\'default\')])', $optionalValue);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/TestAsset/AbstractClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

abstract class AbstractClass
{
protected $config = array();
protected $config = [];

public function getConfig()
{
Expand Down
2 changes: 1 addition & 1 deletion test/TestAsset/BarClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function three(\ArrayObject $o, &$t = 2, FooBarBaz\BazBarFoo $bbf = se
$y = 'this string';
}

protected function four($one, $two = array(array(array('default'))))
protected function four($one, $two = array([array('default')]))
{
// four
}
Expand Down