Skip to content

Commit d7ec5f1

Browse files
committed
used PHP 5.4 array syntax
1 parent 5645381 commit d7ec5f1

38 files changed

+207
-207
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 -c tests/php-unix.ini
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
@@ -25,4 +25,4 @@ services:
2525
before_script:
2626
# Install Nette Tester & Code Checker
2727
- composer install --no-interaction --prefer-source
28-
- composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source
28+
- composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction --prefer-source

src/Bridges/CacheDI/CacheExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public function loadConfiguration()
3333

3434
$container->addDefinition($this->prefix('journal'))
3535
->setClass('Nette\Caching\Storages\IJournal')
36-
->setFactory('Nette\Caching\Storages\SQLiteJournal', array($this->tempDir . '/cache/journal.s3db'));
36+
->setFactory('Nette\Caching\Storages\SQLiteJournal', [$this->tempDir . '/cache/journal.s3db']);
3737

3838
$container->addDefinition($this->prefix('storage'))
3939
->setClass('Nette\Caching\IStorage')
40-
->setFactory('Nette\Caching\Storages\FileStorage', array($this->tempDir . '/cache'));
40+
->setFactory('Nette\Caching\Storages\FileStorage', [$this->tempDir . '/cache']);
4141

4242
if ($this->name === 'cache') {
4343
$container->addAlias('nette.cacheJournal', $this->prefix('journal'));

src/Bridges/CacheLatte/CacheMacro.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function initialize()
3939
public function finalize()
4040
{
4141
if ($this->used) {
42-
return array('Nette\Bridges\CacheLatte\CacheMacro::initRuntime($template, $_g);');
42+
return ['Nette\Bridges\CacheLatte\CacheMacro::initRuntime($template, $_g);'];
4343
}
4444
}
4545

@@ -97,7 +97,7 @@ public static function createCache(Nette\Caching\IStorage $cacheStorage, $key, &
9797
if (array_key_exists('if', $args) && !$args['if']) {
9898
return $parents[] = new \stdClass;
9999
}
100-
$key = array_merge(array($key), array_intersect_key($args, range(0, count($args))));
100+
$key = array_merge([$key], array_intersect_key($args, range(0, count($args))));
101101
}
102102
if ($parents) {
103103
end($parents)->dependencies[Nette\Caching\Cache::ITEMS][] = $key;
@@ -111,10 +111,10 @@ public static function createCache(Nette\Caching\IStorage $cacheStorage, $key, &
111111
if (isset($args['expire'])) {
112112
$args['expiration'] = $args['expire']; // back compatibility
113113
}
114-
$helper->dependencies = array(
114+
$helper->dependencies = [
115115
Nette\Caching\Cache::TAGS => isset($args['tags']) ? $args['tags'] : NULL,
116116
Nette\Caching\Cache::EXPIRATION => isset($args['expiration']) ? $args['expiration'] : '+ 7 days',
117-
);
117+
];
118118
$parents[] = $helper;
119119
}
120120
return $helper;

src/Caching/Cache.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function load($key, $fallback = NULL)
9999
$data = $this->storage->read($this->generateKey($key));
100100
if ($data === NULL && $fallback) {
101101
return $this->save($key, function(& $dependencies) use ($fallback) {
102-
return call_user_func_array($fallback, array(& $dependencies));
102+
return call_user_func_array($fallback, [& $dependencies]);
103103
});
104104
}
105105
return $data;
@@ -130,7 +130,7 @@ public function save($key, $data, array $dependencies = NULL)
130130

131131
if ($data instanceof Nette\Callback || $data instanceof \Closure) {
132132
$this->storage->lock($key);
133-
$data = call_user_func_array($data, array(& $dependencies));
133+
$data = call_user_func_array($data, [& $dependencies]);
134134
}
135135

136136
if ($data === NULL) {
@@ -152,26 +152,26 @@ private function completeDependencies($dp, $data)
152152
// convert FILES into CALLBACKS
153153
if (isset($dp[self::FILES])) {
154154
foreach (array_unique((array) $dp[self::FILES]) as $item) {
155-
$dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkFile'), $item, @filemtime($item)); // @ - stat may fail
155+
$dp[self::CALLBACKS][] = [[__CLASS__, 'checkFile'], $item, @filemtime($item)]; // @ - stat may fail
156156
}
157157
unset($dp[self::FILES]);
158158
}
159159

160160
// add namespaces to items
161161
if (isset($dp[self::ITEMS])) {
162-
$dp[self::ITEMS] = array_unique(array_map(array($this, 'generateKey'), (array) $dp[self::ITEMS]));
162+
$dp[self::ITEMS] = array_unique(array_map([$this, 'generateKey'], (array) $dp[self::ITEMS]));
163163
}
164164

165165
// convert CONSTS into CALLBACKS
166166
if (isset($dp[self::CONSTS])) {
167167
foreach (array_unique((array) $dp[self::CONSTS]) as $item) {
168-
$dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkConst'), $item, constant($item));
168+
$dp[self::CALLBACKS][] = [[__CLASS__, 'checkConst'], $item, constant($item)];
169169
}
170170
unset($dp[self::CONSTS]);
171171
}
172172

173173
if (!is_array($dp)) {
174-
$dp = array();
174+
$dp = [];
175175
}
176176
return $dp;
177177
}
@@ -230,7 +230,7 @@ public function wrap($function, array $dependencies = NULL)
230230
{
231231
$cache = $this;
232232
return function() use ($cache, $function, $dependencies) {
233-
$key = array($function, func_get_args());
233+
$key = [$function, func_get_args()];
234234
if (is_array($function) && is_object($function[0])) {
235235
$key[0][0] = get_class($function[0]);
236236
}

src/Caching/Storages/FileJournal.php

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,27 @@ class FileJournal extends Nette\Object implements IJournal
7676
private $processIdentifier;
7777

7878
/** @var array Cache and uncommitted but changed nodes */
79-
private $nodeCache = array();
79+
private $nodeCache = [];
8080

8181
/** @var array */
82-
private $nodeChanged = array();
82+
private $nodeChanged = [];
8383

8484
/** @var array */
85-
private $toCommit = array();
85+
private $toCommit = [];
8686

8787
/** @var array */
88-
private $deletedLinks = array();
88+
private $deletedLinks = [];
8989

9090
/** @var array Free space in data nodes */
91-
private $dataNodeFreeSpace = array();
91+
private $dataNodeFreeSpace = [];
9292

9393
/** @var array */
94-
private static $startNode = array(
94+
private static $startNode = [
9595
self::TAGS => 0,
9696
self::PRIORITY => 1,
9797
self::ENTRIES => 2,
9898
self::DATA => 3,
99-
);
99+
];
100100

101101

102102
/**
@@ -151,7 +151,7 @@ public function write($key, array $dependencies)
151151
}
152152
$exists = TRUE;
153153
} else { // Already exists, but with other tags or priority
154-
$toDelete = array();
154+
$toDelete = [];
155155
foreach ($dataNode[$link][self::TAGS] as $tag) {
156156
$toDelete[self::TAGS][$tag][$link] = TRUE;
157157
}
@@ -186,21 +186,21 @@ public function write($key, array $dependencies)
186186
$data = $this->getNode($freeDataNode);
187187

188188
if ($data === FALSE) {
189-
$data = array(
190-
self::INFO => array(
189+
$data = [
190+
self::INFO => [
191191
self::LAST_INDEX => ($freeDataNode << self::BITROT),
192192
self::TYPE => self::DATA,
193-
)
194-
);
193+
]
194+
];
195195
}
196196

197197
$dataNodeKey = $this->findNextFreeKey($freeDataNode, $data);
198-
$data[$dataNodeKey] = array(
198+
$data[$dataNodeKey] = [
199199
self::KEY => $key,
200-
self::TAGS => $tags ? $tags : array(),
200+
self::TAGS => $tags ? $tags : [],
201201
self::PRIORITY => $priority,
202202
self::DELETED => FALSE,
203-
);
203+
];
204204

205205
$this->saveNode($freeDataNode, $data);
206206

@@ -240,19 +240,19 @@ public function clean(array $conditions)
240240
$this->lock();
241241

242242
if (!empty($conditions[Cache::ALL])) {
243-
$this->nodeCache = $this->nodeChanged = $this->dataNodeFreeSpace = array();
243+
$this->nodeCache = $this->nodeChanged = $this->dataNodeFreeSpace = [];
244244
$this->deleteAll();
245245
$this->unlock();
246246
return NULL;
247247
}
248248

249-
$toDelete = array(
250-
self::TAGS => array(),
251-
self::PRIORITY => array(),
252-
self::ENTRIES => array()
253-
);
249+
$toDelete = [
250+
self::TAGS => [],
251+
self::PRIORITY => [],
252+
self::ENTRIES => []
253+
];
254254

255-
$entries = array();
255+
$entries = [];
256256

257257
if (!empty($conditions[Cache::TAGS])) {
258258
$entries = $this->cleanTags((array) $conditions[Cache::TAGS], $toDelete);
@@ -262,7 +262,7 @@ public function clean(array $conditions)
262262
$this->arrayAppend($entries, $this->cleanPriority((int) $conditions[Cache::PRIORITY], $toDelete));
263263
}
264264

265-
$this->deletedLinks = array();
265+
$this->deletedLinks = [];
266266
$this->cleanFromIndex($toDelete);
267267

268268
$this->commit();
@@ -280,7 +280,7 @@ public function clean(array $conditions)
280280
*/
281281
private function cleanTags(array $tags, array & $toDelete)
282282
{
283-
$entries = array();
283+
$entries = [];
284284

285285
foreach ($tags as $tag) {
286286
list(, $node) = $this->findIndexNode(self::TAGS, $tag);
@@ -307,7 +307,7 @@ private function cleanPriority($priority, array & $toDelete)
307307

308308
ksort($node);
309309

310-
$allData = array();
310+
$allData = [];
311311

312312
foreach ($node as $prior => $data) {
313313
if ($prior === self::INFO) {
@@ -351,7 +351,7 @@ private function cleanPriority($priority, array & $toDelete)
351351
*/
352352
private function cleanLinks(array $data, array & $toDelete)
353353
{
354-
$return = array();
354+
$return = [];
355355

356356
$data = array_keys($data);
357357
sort($data);
@@ -700,7 +700,7 @@ private function commit()
700700
foreach ($this->toCommit as $node => $str) {
701701
$this->commitNode($node, $str);
702702
}
703-
$this->toCommit = array();
703+
$this->toCommit = [];
704704
}
705705

706706

@@ -779,23 +779,23 @@ private function findIndexNode($type, $search, $childId = NULL, $prevId = NULL)
779779
$node = $this->getNode($nodeId);
780780

781781
if ($node === FALSE) {
782-
return array(
782+
return [
783783
$nodeId,
784-
array(
785-
self::INFO => array(
784+
[
785+
self::INFO => [
786786
self::TYPE => $type,
787787
self::IS_LEAF => TRUE,
788788
self::PREV_NODE => -1,
789789
self::END => -1,
790790
self::MAX => -1,
791-
)
792-
),
791+
]
792+
],
793793
$parentId,
794-
); // Init empty node
794+
]; // Init empty node
795795
}
796796

797797
if ($node[self::INFO][self::IS_LEAF] || $nodeId === $childId || $node[self::INFO][self::PREV_NODE] === $prevId) {
798-
return array($nodeId, $node, $parentId);
798+
return [$nodeId, $node, $parentId];
799799
}
800800

801801
$parentId = $nodeId;
@@ -824,7 +824,7 @@ private function findIndexNode($type, $search, $childId = NULL, $prevId = NULL)
824824
private function findFreeNode($count = 1)
825825
{
826826
$id = $this->lastNode;
827-
$nodesId = array();
827+
$nodesId = [];
828828

829829
do {
830830
if (isset($this->nodeCache[$id])) {
@@ -917,12 +917,12 @@ private function bisectNode($id, array $node)
917917
$key = key($node);
918918

919919
$dataId = $this->findFreeDataNode(self::NODE_SIZE);
920-
$this->saveNode($dataId, array(
920+
$this->saveNode($dataId, [
921921
self::INDEX_DATA => $node[$key],
922-
self::INFO => array(
922+
self::INFO => [
923923
self::TYPE => self::DATA,
924924
self::LAST_INDEX => ($dataId << self::BITROT),
925-
)));
925+
]]);
926926

927927
unset($node[$key]);
928928
$node[$key][self::INDEX_DATA] = $dataId;
@@ -943,54 +943,54 @@ private function bisectNode($id, array $node)
943943
if ($id <= 2) { // Root
944944
list($firstId, $secondId) = $this->findFreeNode(2);
945945

946-
$first[self::INFO] = array(
946+
$first[self::INFO] = [
947947
self::TYPE => $nodeInfo[self::TYPE],
948948
self::IS_LEAF => $nodeInfo[self::IS_LEAF],
949949
self::PREV_NODE => -1,
950950
self::END => -1,
951951
self::MAX => $halfKey,
952-
);
952+
];
953953
$this->saveNode($firstId, $first);
954954

955-
$second[self::INFO] = array(
955+
$second[self::INFO] = [
956956
self::TYPE => $nodeInfo[self::TYPE],
957957
self::IS_LEAF => $nodeInfo[self::IS_LEAF],
958958
self::PREV_NODE => $firstId,
959959
self::END => $nodeInfo[self::END],
960960
self::MAX => -1,
961-
);
961+
];
962962
$this->saveNode($secondId, $second);
963963

964-
$parentNode = array(
965-
self::INFO => array(
964+
$parentNode = [
965+
self::INFO => [
966966
self::TYPE => $nodeInfo[self::TYPE],
967967
self::IS_LEAF => FALSE,
968968
self::PREV_NODE => -1,
969969
self::END => $secondId,
970970
self::MAX => -1,
971-
),
971+
],
972972
$halfKey => $firstId,
973-
);
973+
];
974974
$this->saveNode($id, $parentNode);
975975
} else {
976976
$firstId = $this->findFreeNode();
977977

978-
$first[self::INFO] = array(
978+
$first[self::INFO] = [
979979
self::TYPE => $nodeInfo[self::TYPE],
980980
self::IS_LEAF => $nodeInfo[self::IS_LEAF],
981981
self::PREV_NODE => $nodeInfo[self::PREV_NODE],
982982
self::END => -1,
983983
self::MAX => $halfKey,
984-
);
984+
];
985985
$this->saveNode($firstId, $first);
986986

987-
$second[self::INFO] = array(
987+
$second[self::INFO] = [
988988
self::TYPE => $nodeInfo[self::TYPE],
989989
self::IS_LEAF => $nodeInfo[self::IS_LEAF],
990990
self::PREV_NODE => $firstId,
991991
self::END => $nodeInfo[self::END],
992992
self::MAX => $nodeInfo[self::MAX],
993-
);
993+
];
994994
$this->saveNode($id, $second);
995995

996996
list(,, $parent) = $this->findIndexNode($nodeInfo[self::TYPE], $halfKey);
@@ -1077,7 +1077,7 @@ private function lock()
10771077

10781078
$lastProcessIdentifier = stream_get_contents($this->handle, self::INT32_SIZE, self::INT32_SIZE * 2);
10791079
if ($lastProcessIdentifier !== $this->processIdentifier) {
1080-
$this->nodeCache = $this->dataNodeFreeSpace = array();
1080+
$this->nodeCache = $this->dataNodeFreeSpace = [];
10811081

10821082
// Write current processIdentifier to file header
10831083
fseek($this->handle, self::INT32_SIZE * 2);

0 commit comments

Comments
 (0)