Skip to content

Commit

Permalink
used PHP 5.4 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 21, 2015
1 parent 8b7efc1 commit 9a793cb
Show file tree
Hide file tree
Showing 103 changed files with 756 additions and 756 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ matrix:

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

after_failure:
# Print *.actual content
Expand All @@ -34,4 +34,4 @@ after_failure:
before_script:
# Install Nette Tester & Code Checker
- composer update --no-interaction --prefer-source $dependencies
- composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source
- composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction --prefer-source
4 changes: 2 additions & 2 deletions src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Application extends Nette\Object
public $onError;

/** @var Request[] */
private $requests = array();
private $requests = [];

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

$args = array('exception' => $e, 'request' => end($this->requests) ?: NULL);
$args = ['exception' => $e, 'request' => end($this->requests) ?: NULL];
if ($this->presenter instanceof UI\Presenter) {
try {
$this->presenter->forward(":$this->errorPresenter:", $args);
Expand Down
4 changes: 2 additions & 2 deletions src/Application/IRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
interface IRouter
{
/** only matching route */
const ONE_WAY = 1;
const ONE_WAY = 0b0001;

/** HTTPS route */
const SECURED = 2;
const SECURED = 0b0010;

/**
* Maps HTTP request to a Request object.
Expand Down
2 changes: 1 addition & 1 deletion src/Application/LinkGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(IRouter $router, Nette\Http\Url $refUrl, IPresenterF
* @return string
* @throws InvalidLinkException
*/
public function link($dest, array $params = array())
public function link($dest, array $params = [])
{
if (!preg_match('~^([\w:]+):(\w*+)(#.*)?()\z~', $dest, $m)) {
throw new UI\InvalidLinkException("Invalid link destination '$dest'.");
Expand Down
2 changes: 1 addition & 1 deletion src/Application/MicroPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function run(Application\Request $request)
$response = call_user_func_array($callback, $params);

if (is_string($response)) {
$response = array($response, array());
$response = [$response, []];
}
if (is_array($response)) {
list($templateSource, $templateParams) = $response;
Expand Down
14 changes: 7 additions & 7 deletions src/Application/PresenterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class PresenterFactory extends Nette\Object implements IPresenterFactory
public $caseSensitive = TRUE;

/** @var array[] of module => splited mask */
private $mapping = array(
'*' => array('', '*Module\\', '*Presenter'),
'Nette' => array('NetteModule\\', '*\\', '*Presenter'),
);
private $mapping = [
'*' => ['', '*Module\\', '*Presenter'],
'Nette' => ['NetteModule\\', '*\\', '*Presenter'],
];

/** @var array */
private $cache = array();
private $cache = [];

/** @var callable */
private $factory;
Expand Down Expand Up @@ -104,7 +104,7 @@ public function setMapping(array $mapping)
if (!preg_match('#^\\\\?([\w\\\\]*\\\\)?(\w*\*\w*?\\\\)?([\w\\\\]*\*\w*)\z#', $mask, $m)) {
throw new Nette\InvalidStateException("Invalid mapping mask '$mask'.");
}
$this->mapping[$module] = array($m[1], $m[2] ?: '*Module\\', $m[3]);
$this->mapping[$module] = [$m[1], $m[2] ?: '*Module\\', $m[3]];
}
return $this;
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public function formatPresenterClass($presenter)
public function unformatPresenterClass($class)
{
foreach ($this->mapping as $module => $mapping) {
$mapping = str_replace(array('\\', '*'), array('\\\\', '(\w+)'), $mapping);
$mapping = str_replace(['\\', '*'], ['\\\\', '(\w+)'], $mapping);
if (preg_match("#^\\\\?$mapping[0]((?:$mapping[1])*)$mapping[2]\\z#i", $class, $matches)) {
return ($module === '*' ? '' : $module . ':')
. preg_replace("#$mapping[1]#iA", '$1:', $matches[1]) . $matches[3];
Expand Down
4 changes: 2 additions & 2 deletions src/Application/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Request extends Nette\Object
private $method;

/** @var array */
private $flags = array();
private $flags = [];

/** @var string */
private $name;
Expand All @@ -59,7 +59,7 @@ class Request extends Nette\Object
* @param array all uploaded files
* @param array flags
*/
public function __construct($name, $method = NULL, array $params = array(), array $post = array(), array $files = array(), array $flags = array())
public function __construct($name, $method = NULL, array $params = [], array $post = [], array $files = [], array $flags = [])
{
$this->name = $name;
$this->method = $method;
Expand Down
4 changes: 2 additions & 2 deletions src/Application/Routers/CliRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CliRouter extends Nette\Object implements Application\IRouter
/**
* @param array default values
*/
public function __construct($defaults = array())
public function __construct($defaults = [])
{
$this->defaults = $defaults;
}
Expand All @@ -45,7 +45,7 @@ public function match(Nette\Http\IRequest $httpRequest)
return NULL;
}

$names = array(self::PRESENTER_KEY);
$names = [self::PRESENTER_KEY];
$params = $this->defaults;
$args = $_SERVER['argv'];
array_shift($args);
Expand Down
100 changes: 50 additions & 50 deletions src/Application/Routers/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,35 @@ class Route extends Nette\Object implements Application\IRouter
public static $defaultFlags = 0;

/** @var array */
public static $styles = array(
'#' => array( // default style for path parameters
public static $styles = [
'#' => [ // default style for path parameters
self::PATTERN => '[^/]+',
self::FILTER_OUT => array(__CLASS__, 'param2path'),
),
'?#' => array( // default style for query parameters
),
'module' => array(
self::FILTER_OUT => [__CLASS__, 'param2path'],
],
'?#' => [ // default style for query parameters
],
'module' => [
self::PATTERN => '[a-z][a-z0-9.-]*',
self::FILTER_IN => array(__CLASS__, 'path2presenter'),
self::FILTER_OUT => array(__CLASS__, 'presenter2path'),
),
'presenter' => array(
self::FILTER_IN => [__CLASS__, 'path2presenter'],
self::FILTER_OUT => [__CLASS__, 'presenter2path'],
],
'presenter' => [
self::PATTERN => '[a-z][a-z0-9.-]*',
self::FILTER_IN => array(__CLASS__, 'path2presenter'),
self::FILTER_OUT => array(__CLASS__, 'presenter2path'),
),
'action' => array(
self::FILTER_IN => [__CLASS__, 'path2presenter'],
self::FILTER_OUT => [__CLASS__, 'presenter2path'],
],
'action' => [
self::PATTERN => '[a-z][a-z0-9-]*',
self::FILTER_IN => array(__CLASS__, 'path2action'),
self::FILTER_OUT => array(__CLASS__, 'action2path'),
),
'?module' => array(
),
'?presenter' => array(
),
'?action' => array(
),
);
self::FILTER_IN => [__CLASS__, 'path2action'],
self::FILTER_OUT => [__CLASS__, 'action2path'],
],
'?module' => [
],
'?presenter' => [
],
'?action' => [
],
];

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

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

/** @var array */
private $xlat;
Expand All @@ -118,22 +118,22 @@ class Route extends Nette\Object implements Application\IRouter
* @param array|string default values or metadata
* @param int flags
*/
public function __construct($mask, $metadata = array(), $flags = 0)
public function __construct($mask, $metadata = [], $flags = 0)
{
if (is_string($metadata)) {
$a = strrpos($metadata, ':');
if (!$a) {
throw new Nette\InvalidArgumentException("Second argument must be array or string in format Presenter:action, '$metadata' given.");
}
$metadata = array(
$metadata = [
self::PRESENTER_KEY => substr($metadata, 0, $a),
'action' => $a === strlen($metadata) - 1 ? NULL : substr($metadata, $a + 1),
);
];
} elseif ($metadata instanceof \Closure || $metadata instanceof Nette\Callback) {
$metadata = array(
$metadata = [
self::PRESENTER_KEY => 'Nette:Micro',
'callback' => $metadata,
);
];
}

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

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

// assigns matched values to parameters
$params = array();
$params = [];
foreach ($matches as $k => $v) {
if (is_string($k) && $v !== '') {
$params[$this->aliases[$k]] = $v;
Expand Down Expand Up @@ -262,7 +262,7 @@ public function match(Nette\Http\IRequest $httpRequest)
$params,
$httpRequest->getPost(),
$httpRequest->getFiles(),
array(Application\Request::SECURED => $httpRequest->isSecured())
[Application\Request::SECURED => $httpRequest->isSecured()]
);
}

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

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

} else {
$host = $refUrl->getHost();
$host = ip2long($host) ? array($host) : array_reverse(explode('.', $host));
$url = strtr($url, array(
$host = ip2long($host) ? [$host] : array_reverse(explode('.', $host));
$url = strtr($url, [
'/%basePath%/' => $refUrl->getBasePath(),
'%tld%' => $host[0],
'%domain%' => isset($host[1]) ? "$host[1].$host[0]" : $host[0],
));
]);
$url = ($this->flags & self::SECURED ? 'https:' : 'http:') . $url;
}

Expand Down Expand Up @@ -452,7 +452,7 @@ private function setMask($mask, array $metadata)

foreach ($metadata as $name => $meta) {
if (!is_array($meta)) {
$metadata[$name] = $meta = array(self::VALUE => $meta);
$metadata[$name] = $meta = [self::VALUE => $meta];
}

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

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

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

// PARSE QUERY PART OF MASK
Expand Down Expand Up @@ -520,9 +520,9 @@ private function setMask($mask, array $metadata)
// PARSE PATH PART OF MASK
$brackets = 0; // optional level
$re = '';
$sequence = array();
$sequence = [];
$autoOptional = TRUE;
$aliases = array();
$aliases = [];
do {
array_unshift($sequence, $parts[$i]);
$re = preg_quote($parts[$i], '#') . $re;
Expand Down Expand Up @@ -647,7 +647,7 @@ public function getMask()
*/
public function getDefaults()
{
$defaults = array();
$defaults = [];
foreach ($this->metadata as $name => $meta) {
if (isset($meta['fixity'])) {
$defaults[$name] = $meta[self::VALUE];
Expand Down Expand Up @@ -678,7 +678,7 @@ public function getFlags()
public function getTargetPresenters()
{
if ($this->flags & self::ONE_WAY) {
return array();
return [];
}

$m = $this->metadata;
Expand All @@ -693,7 +693,7 @@ public function getTargetPresenters()
}

if (isset($m[self::PRESENTER_KEY]['fixity']) && $m[self::PRESENTER_KEY]['fixity'] === self::CONSTANT) {
return array($module . $m[self::PRESENTER_KEY][self::VALUE]);
return [$module . $m[self::PRESENTER_KEY][self::VALUE]];
}
return NULL;
}
Expand All @@ -711,7 +711,7 @@ private static function renameKeys($arr, $xlat)
return $arr;
}

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

} else {
static::$styles[$style] = array();
static::$styles[$style] = [];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Application/Routers/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function match(Nette\Http\IRequest $httpRequest)
public function constructUrl(Nette\Application\Request $appRequest, Nette\Http\Url $refUrl)
{
if ($this->cachedRoutes === NULL) {
$routes = array();
$routes['*'] = array();
$routes = [];
$routes['*'] = [];

foreach ($this as $route) {
$presenters = $route instanceof Route && is_array($tmp = $route->getTargetPresenters())
Expand Down
Loading

0 comments on commit 9a793cb

Please sign in to comment.