Skip to content

Commit e633233

Browse files
committed
used PHP 5.4 array syntax
1 parent 1384ea7 commit e633233

File tree

11 files changed

+53
-53
lines changed

11 files changed

+53
-53
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ matrix:
1313

1414
script:
1515
- vendor/bin/tester tests -s -p php
16-
- php code-checker/src/code-checker.php
16+
- php temp/code-checker/src/code-checker.php --short-arrays
1717

1818
after_failure:
1919
# Print *.actual content
@@ -22,4 +22,4 @@ after_failure:
2222
before_script:
2323
# Install Nette Tester & Code Checker
2424
- composer install --no-interaction --prefer-source
25-
- composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source
25+
- composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction --prefer-source

src/PhpGenerator/ClassType.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,25 @@ class ClassType extends Nette\Object
4040
private $abstract = FALSE;
4141

4242
/** @var strings|string[] */
43-
private $extends = array();
43+
private $extends = [];
4444

4545
/** @var string[] */
46-
private $implements = array();
46+
private $implements = [];
4747

4848
/** @var string[] */
49-
private $traits = array();
49+
private $traits = [];
5050

5151
/** @var string[] */
52-
private $documents = array();
52+
private $documents = [];
5353

5454
/** @var array name => value */
55-
private $consts = array();
55+
private $consts = [];
5656

5757
/** @var Property[] name => Property */
58-
private $properties = array();
58+
private $properties = [];
5959

6060
/** @var Method[] name => Method */
61-
private $methods = array();
61+
private $methods = [];
6262

6363

6464
/**
@@ -113,12 +113,12 @@ public function __construct($name = NULL, PhpNamespace $namespace = NULL)
113113
*/
114114
public function __toString()
115115
{
116-
$consts = array();
116+
$consts = [];
117117
foreach ($this->consts as $name => $value) {
118118
$consts[] = "const $name = " . Helpers::dump($value) . ";\n";
119119
}
120120

121-
$properties = array();
121+
$properties = [];
122122
foreach ($this->properties as $property) {
123123
$doc = str_replace("\n", "\n * ", implode("\n", (array) $property->getDocuments()));
124124
$properties[] = ($property->getDocuments() ? (strpos($doc, "\n") === FALSE ? "/** $doc */\n" : "/**\n * $doc\n */\n") : '')
@@ -127,7 +127,7 @@ public function __toString()
127127
. ";\n";
128128
}
129129

130-
$extends = $implements = $traits = array();
130+
$extends = $implements = $traits = [];
131131
if ($this->namespace) {
132132
foreach ((array) $this->extends as $name) {
133133
$extends[] = $this->namespace->unresolveName($name);
@@ -205,7 +205,7 @@ public function getName()
205205
*/
206206
public function setType($type)
207207
{
208-
if (!in_array($type, array('class', 'interface', 'trait'), TRUE)) {
208+
if (!in_array($type, ['class', 'interface', 'trait'], TRUE)) {
209209
throw new Nette\InvalidArgumentException('Argument must be class|interface|trait.');
210210
}
211211
$this->type = $type;

src/PhpGenerator/Helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private static function _dump(& $var, $level = 0)
100100
$space = str_repeat("\t", $level);
101101
$class = get_class($var);
102102

103-
static $list = array();
103+
static $list = [];
104104
if ($level > self::MAX_DEPTH || in_array($var, $list, TRUE)) {
105105
throw new Nette\InvalidArgumentException('Nesting level too deep or recursive dependency.');
106106

@@ -170,7 +170,7 @@ public static function formatArgs($statement, array $args)
170170
$a = strlen($s);
171171

172172
} else {
173-
$arg = substr($statement, $a - 1, 1) === '$' || in_array(substr($statement, $a - 2, 2), array('->', '::'), TRUE)
173+
$arg = substr($statement, $a - 1, 1) === '$' || in_array(substr($statement, $a - 2, 2), ['->', '::'], TRUE)
174174
? self::formatMember($arg) : self::_dump($arg);
175175
$statement = substr_replace($statement, $arg, $a, 1);
176176
$a += strlen($arg);

src/PhpGenerator/Method.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class Method extends Nette\Object
2121
private $name;
2222

2323
/** @var array of name => Parameter */
24-
private $parameters = array();
24+
private $parameters = [];
2525

2626
/** @var array of name => bool */
27-
private $uses = array();
27+
private $uses = [];
2828

2929
/** @var string|FALSE */
3030
private $body;
@@ -48,7 +48,7 @@ class Method extends Nette\Object
4848
private $variadic = FALSE;
4949

5050
/** @var array of string */
51-
private $documents = array();
51+
private $documents = [];
5252

5353
/** @var PhpNamespace */
5454
private $namespace;
@@ -82,10 +82,10 @@ public static function from($from)
8282
*/
8383
public function __toString()
8484
{
85-
$parameters = array();
85+
$parameters = [];
8686
foreach ($this->parameters as $param) {
8787
$variadic = $this->variadic && $param === end($this->parameters);
88-
$hint = in_array($param->getTypeHint(), array('array', ''))
88+
$hint = in_array($param->getTypeHint(), ['array', ''])
8989
? $param->getTypeHint()
9090
: ($this->namespace ? $this->namespace->unresolveName($param->getTypeHint()) : $param->getTypeHint());
9191

@@ -95,7 +95,7 @@ public function __toString()
9595
. '$' . $param->getName()
9696
. ($param->isOptional() && !$variadic ? ' = ' . Helpers::dump($param->defaultValue) : '');
9797
}
98-
$uses = array();
98+
$uses = [];
9999
foreach ($this->uses as $param) {
100100
$uses[] = ($param->isReference() ? '&' : '') . '$' . $param->getName();
101101
}
@@ -257,7 +257,7 @@ public function isStatic()
257257
*/
258258
public function setVisibility($val)
259259
{
260-
if (!in_array($val, array('public', 'protected', 'private', NULL), TRUE)) {
260+
if (!in_array($val, ['public', 'protected', 'private', NULL], TRUE)) {
261261
throw new Nette\InvalidArgumentException('Argument must be public|protected|private|NULL.');
262262
}
263263
$this->visibility = (string) $val;

src/PhpGenerator/PhpFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class PhpFile extends Object
2727
private $documents;
2828

2929
/** @var PhpNamespace[] */
30-
private $namespaces = array();
30+
private $namespaces = [];
3131

3232

3333
/**

src/PhpGenerator/PhpNamespace.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class PhpNamespace extends Object
3131
private $bracketedSyntax = FALSE;
3232

3333
/** @var string[] */
34-
private $uses = array();
34+
private $uses = [];
3535

3636
/** @var ClassType[] */
37-
private $classes = array();
37+
private $classes = [];
3838

3939

4040
public function __construct($name = NULL)
@@ -204,7 +204,7 @@ public function addTrait($name)
204204
*/
205205
public function __toString()
206206
{
207-
$uses = array();
207+
$uses = [];
208208
asort($this->uses);
209209
foreach ($this->uses as $alias => $name) {
210210
$useNamespace = Helpers::extractNamespace($name);

src/PhpGenerator/Property.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Property extends Nette\Object
3030
private $visibility = 'public';
3131

3232
/** @var array of string */
33-
private $documents = array();
33+
private $documents = [];
3434

3535

3636
/**
@@ -114,7 +114,7 @@ public function isStatic()
114114
*/
115115
public function setVisibility($val)
116116
{
117-
if (!in_array($val, array('public', 'protected', 'private'), TRUE)) {
117+
if (!in_array($val, ['public', 'protected', 'private'], TRUE)) {
118118
throw new Nette\InvalidArgumentException('Argument must be public|protected|private.');
119119
}
120120
$this->visibility = (string) $val;

tests/PhpGenerator/ClassType.from.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ class Class2 extends Class1 implements Interface2
4747
/** @var int */
4848
protected $protected = 10;
4949

50-
private $private = array();
50+
private $private = [];
5151

5252
static public $static;
5353

5454
/**
5555
* Func3
5656
* @return Class1
5757
*/
58-
private function & func3(array $a = array(), Class2 $b = NULL, \Abc\Unknown $c, \Xyz\Unknown $d, $e)
58+
private function & func3(array $a = [], Class2 $b = NULL, \Abc\Unknown $c, \Xyz\Unknown $d, $e)
5959
{}
6060

6161
final function func2()

tests/PhpGenerator/ClassType.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $class->addProperty('handle')
3434
$class->addProperty('order')
3535
->setValue(new PhpLiteral('RecursiveIteratorIterator::SELF_FIRST'));
3636

37-
$p = $class->addProperty('sections', array('first' => TRUE))
37+
$p = $class->addProperty('sections', ['first' => TRUE])
3838
->setStatic(TRUE);
3939

4040
Assert::same($p, $class->getProperty('sections'));
@@ -43,15 +43,15 @@ $m = $class->addMethod('getHandle')
4343
->addDocument('Returns file handle.')
4444
->addDocument('@return resource')
4545
->setFinal(TRUE)
46-
->setBody('return $this->?;', array('handle'));
46+
->setBody('return $this->?;', ['handle']);
4747

4848
Assert::same($m, $class->getMethod('getHandle'));
4949

5050
$class->addMethod('getSections')
5151
->setStatic(TRUE)
5252
->setVisibility('protected')
5353
->setReturnReference(TRUE)
54-
->addBody('$mode = ?;', array(123))
54+
->addBody('$mode = ?;', [123])
5555
->addBody('return self::$sections;')
5656
->addParameter('mode', new PhpLiteral('self::ORDER'));
5757

tests/PhpGenerator/Helpers.dump().phpt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ Assert::same( "'I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xc3\xa0liz\xc3\xa6ti\xc3
2424
Assert::same( '"\rHello \$"', Helpers::dump("\rHello $") );
2525
Assert::same( "'He\\llo'", Helpers::dump('He\llo') );
2626
Assert::same( '\'He\ll\\\\\o \\\'wor\\\\\\\'ld\\\\\'', Helpers::dump('He\ll\\\o \'wor\\\'ld\\') );
27-
Assert::same( 'array()', Helpers::dump(array()) );
27+
Assert::same( 'array()', Helpers::dump([]) );
2828

29-
Assert::same( "array(\$s)", Helpers::dump(array(new PhpLiteral('$s'))) );
29+
Assert::same( "array(\$s)", Helpers::dump([new PhpLiteral('$s')]) );
3030

31-
Assert::same( "array(1, 2, 3)", Helpers::dump(array(1,2,3)) );
32-
Assert::same( "array('a', 7 => 'b', 'c', '9a' => 'd', 'e')", Helpers::dump(array('a', 7 => 'b', 'c', '9a' => 'd', 9 => 'e')) );
33-
Assert::same( "array(\n\tarray(\n\t\t'a',\n\t\t'loooooooooooooooooooooooooooooooooong',\n\t),\n)", Helpers::dump(array(array('a', 'loooooooooooooooooooooooooooooooooong'))) );
34-
Assert::same( "array('a' => 1, array(\"\\r\" => \"\\r\", 2), 3)", Helpers::dump(array('a' => 1, array("\r" => "\r", 2), 3)) );
31+
Assert::same( "array(1, 2, 3)", Helpers::dump([1,2,3]) );
32+
Assert::same( "array('a', 7 => 'b', 'c', '9a' => 'd', 'e')", Helpers::dump(['a', 7 => 'b', 'c', '9a' => 'd', 9 => 'e']) );
33+
Assert::same( "array(\n\tarray(\n\t\t'a',\n\t\t'loooooooooooooooooooooooooooooooooong',\n\t),\n)", Helpers::dump([['a', 'loooooooooooooooooooooooooooooooooong']]) );
34+
Assert::same( "array('a' => 1, array(\"\\r\" => \"\\r\", 2), 3)", Helpers::dump(['a' => 1, ["\r" => "\r", 2], 3]) );
3535

36-
Assert::same( "(object) array(\n\t'a' => 1,\n\t'b' => 2,\n)", Helpers::dump((object) array('a' => 1, 'b' => 2)) );
37-
Assert::same( "(object) array(\n\t'a' => (object) array(\n\t\t'b' => 2,\n\t),\n)" , Helpers::dump((object) array('a' => (object) array('b' => 2))) );
36+
Assert::same( "(object) array(\n\t'a' => 1,\n\t'b' => 2,\n)", Helpers::dump((object) ['a' => 1, 'b' => 2]) );
37+
Assert::same( "(object) array(\n\t'a' => (object) array(\n\t\t'b' => 2,\n\t),\n)" , Helpers::dump((object) ['a' => (object) ['b' => 2]]) );
3838

3939

4040
class Test
@@ -55,7 +55,7 @@ class Test2 extends Test
5555

5656
function __sleep()
5757
{
58-
return array('c', 'b', 'a');
58+
return ['c', 'b', 'a'];
5959
}
6060

6161
function __wakeup()

0 commit comments

Comments
 (0)