Skip to content

Commit 9a793cb

Browse files
committed
used PHP 5.4 syntax
1 parent 8b7efc1 commit 9a793cb

File tree

103 files changed

+756
-756
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+756
-756
lines changed

.travis.yml

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

2626
script:
2727
- vendor/bin/tester -p $PHP_BIN tests -s
28-
- php code-checker/src/code-checker.php
28+
- php temp/code-checker/src/code-checker.php --short-arrays
2929

3030
after_failure:
3131
# Print *.actual content
@@ -34,4 +34,4 @@ after_failure:
3434
before_script:
3535
# Install Nette Tester & Code Checker
3636
- composer update --no-interaction --prefer-source $dependencies
37-
- composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source
37+
- composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction --prefer-source

src/Application/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Application extends Nette\Object
5050
public $onError;
5151

5252
/** @var Request[] */
53-
private $requests = array();
53+
private $requests = [];
5454

5555
/** @var IPresenter */
5656
private $presenter;
@@ -169,7 +169,7 @@ public function processException(\Exception $e)
169169
$this->httpResponse->setCode($e instanceof BadRequestException ? ($e->getCode() ?: 404) : 500);
170170
}
171171

172-
$args = array('exception' => $e, 'request' => end($this->requests) ?: NULL);
172+
$args = ['exception' => $e, 'request' => end($this->requests) ?: NULL];
173173
if ($this->presenter instanceof UI\Presenter) {
174174
try {
175175
$this->presenter->forward(":$this->errorPresenter:", $args);

src/Application/IRouter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
interface IRouter
1919
{
2020
/** only matching route */
21-
const ONE_WAY = 1;
21+
const ONE_WAY = 0b0001;
2222

2323
/** HTTPS route */
24-
const SECURED = 2;
24+
const SECURED = 0b0010;
2525

2626
/**
2727
* Maps HTTP request to a Request object.

src/Application/LinkGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(IRouter $router, Nette\Http\Url $refUrl, IPresenterF
3939
* @return string
4040
* @throws InvalidLinkException
4141
*/
42-
public function link($dest, array $params = array())
42+
public function link($dest, array $params = [])
4343
{
4444
if (!preg_match('~^([\w:]+):(\w*+)(#.*)?()\z~', $dest, $m)) {
4545
throw new UI\InvalidLinkException("Invalid link destination '$dest'.");

src/Application/MicroPresenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function run(Application\Request $request)
9292
$response = call_user_func_array($callback, $params);
9393

9494
if (is_string($response)) {
95-
$response = array($response, array());
95+
$response = [$response, []];
9696
}
9797
if (is_array($response)) {
9898
list($templateSource, $templateParams) = $response;

src/Application/PresenterFactory.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class PresenterFactory extends Nette\Object implements IPresenterFactory
2121
public $caseSensitive = TRUE;
2222

2323
/** @var array[] of module => splited mask */
24-
private $mapping = array(
25-
'*' => array('', '*Module\\', '*Presenter'),
26-
'Nette' => array('NetteModule\\', '*\\', '*Presenter'),
27-
);
24+
private $mapping = [
25+
'*' => ['', '*Module\\', '*Presenter'],
26+
'Nette' => ['NetteModule\\', '*\\', '*Presenter'],
27+
];
2828

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

3232
/** @var callable */
3333
private $factory;
@@ -104,7 +104,7 @@ public function setMapping(array $mapping)
104104
if (!preg_match('#^\\\\?([\w\\\\]*\\\\)?(\w*\*\w*?\\\\)?([\w\\\\]*\*\w*)\z#', $mask, $m)) {
105105
throw new Nette\InvalidStateException("Invalid mapping mask '$mask'.");
106106
}
107-
$this->mapping[$module] = array($m[1], $m[2] ?: '*Module\\', $m[3]);
107+
$this->mapping[$module] = [$m[1], $m[2] ?: '*Module\\', $m[3]];
108108
}
109109
return $this;
110110
}
@@ -139,7 +139,7 @@ public function formatPresenterClass($presenter)
139139
public function unformatPresenterClass($class)
140140
{
141141
foreach ($this->mapping as $module => $mapping) {
142-
$mapping = str_replace(array('\\', '*'), array('\\\\', '(\w+)'), $mapping);
142+
$mapping = str_replace(['\\', '*'], ['\\\\', '(\w+)'], $mapping);
143143
if (preg_match("#^\\\\?$mapping[0]((?:$mapping[1])*)$mapping[2]\\z#i", $class, $matches)) {
144144
return ($module === '*' ? '' : $module . ':')
145145
. preg_replace("#$mapping[1]#iA", '$1:', $matches[1]) . $matches[3];

src/Application/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Request extends Nette\Object
3636
private $method;
3737

3838
/** @var array */
39-
private $flags = array();
39+
private $flags = [];
4040

4141
/** @var string */
4242
private $name;
@@ -59,7 +59,7 @@ class Request extends Nette\Object
5959
* @param array all uploaded files
6060
* @param array flags
6161
*/
62-
public function __construct($name, $method = NULL, array $params = array(), array $post = array(), array $files = array(), array $flags = array())
62+
public function __construct($name, $method = NULL, array $params = [], array $post = [], array $files = [], array $flags = [])
6363
{
6464
$this->name = $name;
6565
$this->method = $method;

src/Application/Routers/CliRouter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CliRouter extends Nette\Object implements Application\IRouter
2929
/**
3030
* @param array default values
3131
*/
32-
public function __construct($defaults = array())
32+
public function __construct($defaults = [])
3333
{
3434
$this->defaults = $defaults;
3535
}
@@ -45,7 +45,7 @@ public function match(Nette\Http\IRequest $httpRequest)
4545
return NULL;
4646
}
4747

48-
$names = array(self::PRESENTER_KEY);
48+
$names = [self::PRESENTER_KEY];
4949
$params = $this->defaults;
5050
$args = $_SERVER['argv'];
5151
array_shift($args);

src/Application/Routers/Route.php

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -52,35 +52,35 @@ class Route extends Nette\Object implements Application\IRouter
5252
public static $defaultFlags = 0;
5353

5454
/** @var array */
55-
public static $styles = array(
56-
'#' => array( // default style for path parameters
55+
public static $styles = [
56+
'#' => [ // default style for path parameters
5757
self::PATTERN => '[^/]+',
58-
self::FILTER_OUT => array(__CLASS__, 'param2path'),
59-
),
60-
'?#' => array( // default style for query parameters
61-
),
62-
'module' => array(
58+
self::FILTER_OUT => [__CLASS__, 'param2path'],
59+
],
60+
'?#' => [ // default style for query parameters
61+
],
62+
'module' => [
6363
self::PATTERN => '[a-z][a-z0-9.-]*',
64-
self::FILTER_IN => array(__CLASS__, 'path2presenter'),
65-
self::FILTER_OUT => array(__CLASS__, 'presenter2path'),
66-
),
67-
'presenter' => array(
64+
self::FILTER_IN => [__CLASS__, 'path2presenter'],
65+
self::FILTER_OUT => [__CLASS__, 'presenter2path'],
66+
],
67+
'presenter' => [
6868
self::PATTERN => '[a-z][a-z0-9.-]*',
69-
self::FILTER_IN => array(__CLASS__, 'path2presenter'),
70-
self::FILTER_OUT => array(__CLASS__, 'presenter2path'),
71-
),
72-
'action' => array(
69+
self::FILTER_IN => [__CLASS__, 'path2presenter'],
70+
self::FILTER_OUT => [__CLASS__, 'presenter2path'],
71+
],
72+
'action' => [
7373
self::PATTERN => '[a-z][a-z0-9-]*',
74-
self::FILTER_IN => array(__CLASS__, 'path2action'),
75-
self::FILTER_OUT => array(__CLASS__, 'action2path'),
76-
),
77-
'?module' => array(
78-
),
79-
'?presenter' => array(
80-
),
81-
'?action' => array(
82-
),
83-
);
74+
self::FILTER_IN => [__CLASS__, 'path2action'],
75+
self::FILTER_OUT => [__CLASS__, 'action2path'],
76+
],
77+
'?module' => [
78+
],
79+
'?presenter' => [
80+
],
81+
'?action' => [
82+
],
83+
];
8484

8585
/** @var string */
8686
private $mask;
@@ -95,7 +95,7 @@ class Route extends Nette\Object implements Application\IRouter
9595
private $aliases;
9696

9797
/** @var array of [value & fixity, filterIn, filterOut] */
98-
private $metadata = array();
98+
private $metadata = [];
9999

100100
/** @var array */
101101
private $xlat;
@@ -118,22 +118,22 @@ class Route extends Nette\Object implements Application\IRouter
118118
* @param array|string default values or metadata
119119
* @param int flags
120120
*/
121-
public function __construct($mask, $metadata = array(), $flags = 0)
121+
public function __construct($mask, $metadata = [], $flags = 0)
122122
{
123123
if (is_string($metadata)) {
124124
$a = strrpos($metadata, ':');
125125
if (!$a) {
126126
throw new Nette\InvalidArgumentException("Second argument must be array or string in format Presenter:action, '$metadata' given.");
127127
}
128-
$metadata = array(
128+
$metadata = [
129129
self::PRESENTER_KEY => substr($metadata, 0, $a),
130130
'action' => $a === strlen($metadata) - 1 ? NULL : substr($metadata, $a + 1),
131-
);
131+
];
132132
} elseif ($metadata instanceof \Closure || $metadata instanceof Nette\Callback) {
133-
$metadata = array(
133+
$metadata = [
134134
self::PRESENTER_KEY => 'Nette:Micro',
135135
'callback' => $metadata,
136-
);
136+
];
137137
}
138138

139139
$this->flags = $flags | static::$defaultFlags;
@@ -156,12 +156,12 @@ public function match(Nette\Http\IRequest $httpRequest)
156156
if ($this->type === self::HOST) {
157157
$host = $url->getHost();
158158
$path = '//' . $host . $url->getPath();
159-
$host = ip2long($host) ? array($host) : array_reverse(explode('.', $host));
160-
$re = strtr($re, array(
159+
$host = ip2long($host) ? [$host] : array_reverse(explode('.', $host));
160+
$re = strtr($re, [
161161
'/%basePath%/' => preg_quote($url->getBasePath(), '#'),
162162
'%tld%' => preg_quote($host[0], '#'),
163163
'%domain%' => preg_quote(isset($host[1]) ? "$host[1].$host[0]" : $host[0], '#'),
164-
));
164+
]);
165165

166166
} elseif ($this->type === self::RELATIVE) {
167167
$basePath = $url->getBasePath();
@@ -184,7 +184,7 @@ public function match(Nette\Http\IRequest $httpRequest)
184184
}
185185

186186
// assigns matched values to parameters
187-
$params = array();
187+
$params = [];
188188
foreach ($matches as $k => $v) {
189189
if (is_string($k) && $v !== '') {
190190
$params[$this->aliases[$k]] = $v;
@@ -262,7 +262,7 @@ public function match(Nette\Http\IRequest $httpRequest)
262262
$params,
263263
$httpRequest->getPost(),
264264
$httpRequest->getFiles(),
265-
array(Application\Request::SECURED => $httpRequest->isSecured())
265+
[Application\Request::SECURED => $httpRequest->isSecured()]
266266
);
267267
}
268268

@@ -343,7 +343,7 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
343343

344344
// compositing path
345345
$sequence = $this->sequence;
346-
$brackets = array();
346+
$brackets = [];
347347
$required = NULL; // NULL for auto-optional
348348
$url = '';
349349
$i = count($sequence) - 1;
@@ -401,12 +401,12 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
401401

402402
} else {
403403
$host = $refUrl->getHost();
404-
$host = ip2long($host) ? array($host) : array_reverse(explode('.', $host));
405-
$url = strtr($url, array(
404+
$host = ip2long($host) ? [$host] : array_reverse(explode('.', $host));
405+
$url = strtr($url, [
406406
'/%basePath%/' => $refUrl->getBasePath(),
407407
'%tld%' => $host[0],
408408
'%domain%' => isset($host[1]) ? "$host[1].$host[0]" : $host[0],
409-
));
409+
]);
410410
$url = ($this->flags & self::SECURED ? 'https:' : 'http:') . $url;
411411
}
412412

@@ -452,7 +452,7 @@ private function setMask($mask, array $metadata)
452452

453453
foreach ($metadata as $name => $meta) {
454454
if (!is_array($meta)) {
455-
$metadata[$name] = $meta = array(self::VALUE => $meta);
455+
$metadata[$name] = $meta = [self::VALUE => $meta];
456456
}
457457

458458
if (array_key_exists(self::VALUE, $meta)) {
@@ -465,7 +465,7 @@ private function setMask($mask, array $metadata)
465465

466466
if (strpbrk($mask, '?<[') === FALSE) {
467467
$this->re = '#' . preg_quote($mask, '#') . '/?\z#A';
468-
$this->sequence = array($mask);
468+
$this->sequence = [$mask];
469469
$this->metadata = $metadata;
470470
return;
471471
}
@@ -474,7 +474,7 @@ private function setMask($mask, array $metadata)
474474
// <parameter-name[=default] [pattern] [#class]> or [ or ] or ?...
475475
$parts = Strings::split($mask, '/<([^>#= ]+)(=[^># ]*)? *([^>#]*)(#?[^>\[\]]*)>|(\[!?|\]|\s*\?.*)/');
476476

477-
$this->xlat = array();
477+
$this->xlat = [];
478478
$i = count($parts) - 1;
479479

480480
// PARSE QUERY PART OF MASK
@@ -520,9 +520,9 @@ private function setMask($mask, array $metadata)
520520
// PARSE PATH PART OF MASK
521521
$brackets = 0; // optional level
522522
$re = '';
523-
$sequence = array();
523+
$sequence = [];
524524
$autoOptional = TRUE;
525-
$aliases = array();
525+
$aliases = [];
526526
do {
527527
array_unshift($sequence, $parts[$i]);
528528
$re = preg_quote($parts[$i], '#') . $re;
@@ -647,7 +647,7 @@ public function getMask()
647647
*/
648648
public function getDefaults()
649649
{
650-
$defaults = array();
650+
$defaults = [];
651651
foreach ($this->metadata as $name => $meta) {
652652
if (isset($meta['fixity'])) {
653653
$defaults[$name] = $meta[self::VALUE];
@@ -678,7 +678,7 @@ public function getFlags()
678678
public function getTargetPresenters()
679679
{
680680
if ($this->flags & self::ONE_WAY) {
681-
return array();
681+
return [];
682682
}
683683

684684
$m = $this->metadata;
@@ -693,7 +693,7 @@ public function getTargetPresenters()
693693
}
694694

695695
if (isset($m[self::PRESENTER_KEY]['fixity']) && $m[self::PRESENTER_KEY]['fixity'] === self::CONSTANT) {
696-
return array($module . $m[self::PRESENTER_KEY][self::VALUE]);
696+
return [$module . $m[self::PRESENTER_KEY][self::VALUE]];
697697
}
698698
return NULL;
699699
}
@@ -711,7 +711,7 @@ private static function renameKeys($arr, $xlat)
711711
return $arr;
712712
}
713713

714-
$res = array();
714+
$res = [];
715715
$occupied = array_flip($xlat);
716716
foreach ($arr as $k => $v) {
717717
if (isset($xlat[$k])) {
@@ -817,7 +817,7 @@ public static function addStyle($style, $parent = '#')
817817
static::$styles[$style] = static::$styles[$parent];
818818

819819
} else {
820-
static::$styles[$style] = array();
820+
static::$styles[$style] = [];
821821
}
822822
}
823823

src/Application/Routers/RouteList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public function match(Nette\Http\IRequest $httpRequest)
5858
public function constructUrl(Nette\Application\Request $appRequest, Nette\Http\Url $refUrl)
5959
{
6060
if ($this->cachedRoutes === NULL) {
61-
$routes = array();
62-
$routes['*'] = array();
61+
$routes = [];
62+
$routes['*'] = [];
6363

6464
foreach ($this as $route) {
6565
$presenters = $route instanceof Route && is_array($tmp = $route->getTargetPresenters())

0 commit comments

Comments
 (0)