Skip to content

Commit c569080

Browse files
committed
Use PHP 5.3 array syntax.
1 parent 2500cbe commit c569080

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

library/Xi/Algorithm/TopologicalSort.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ public static function apply(array $edges)
2828
// If we meet a node marked 2 then it's already on the list and we return.
2929
$unmarkedNodes = array_fill_keys($allNodes, null);
3030
$marks = array_fill_keys($allNodes, 0);
31-
$result = [];
31+
$result = array();
3232

3333
$visit = function ($node) use ($edges, &$visit, &$marks, &$unmarkedNodes, &$result) {
3434
$mark = $marks[$node];
3535
if ($mark === 0) {
3636
$marks[$node] = 1;
3737
unset($unmarkedNodes[$node]);
3838

39-
foreach ((isset($edges[$node]) ? $edges[$node] : []) as $next) {
39+
foreach ((isset($edges[$node]) ? $edges[$node] : array()) as $next) {
4040
$visit($next);
4141
}
4242

@@ -60,7 +60,7 @@ public static function apply(array $edges)
6060

6161
private static function allNodes(array $deps)
6262
{
63-
$allNodes = [];
63+
$allNodes = array();
6464
foreach ($deps as $node => $others) {
6565
if (!is_array($others)) {
6666
throw new \InvalidArgumentException('Dependencies should be given as arrays, not single elements.');

tests/Xi/Tests/Algorithm/TopologicalSortTest.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ class TopologicalSortTest extends \PHPUnit_Framework_TestCase
88
*/
99
public function simpleCase()
1010
{
11-
$edges = [
12-
'B' => ['C', 'D'],
13-
'A' => ['B'],
14-
'C' => ['D'],
15-
];
11+
$edges = array(
12+
'B' => array('C', 'D'),
13+
'A' => array('B'),
14+
'C' => array('D'),
15+
);
1616

1717
for ($i = 0; $i < 100; ++$i) {
1818
$edges = self::shuffleGraphSpec($edges);
19-
$this->assertEquals(['D', 'C', 'B', 'A'], TopologicalSort::apply($edges));
19+
$this->assertEquals(array('D', 'C', 'B', 'A'), TopologicalSort::apply($edges));
2020
}
2121
}
2222

@@ -35,22 +35,22 @@ public function test(array $edges)
3535

3636
public function provider()
3737
{
38-
return [
39-
[[
40-
'B' => ['C', 'D'],
41-
'A' => ['B'],
42-
'C' => ['D'],
43-
]],
38+
return array(
39+
array(array(
40+
'B' => array('C', 'D'),
41+
'A' => array('B'),
42+
'C' => array('D'),
43+
)),
4444

4545
// Wikipedia's example
46-
[[
47-
7 => [11, 8],
48-
5 => [11],
49-
3 => [8, 10],
50-
11 => [2, 9, 10],
51-
8 => [9]
52-
]]
53-
];
46+
array(array(
47+
7 => array(11, 8),
48+
5 => array(11),
49+
3 => array(8, 10),
50+
11 => array(2, 9, 10),
51+
8 => array(9)
52+
))
53+
);
5454
}
5555

5656
/**
@@ -59,12 +59,12 @@ public function provider()
5959
*/
6060
public function throwsOnCycle()
6161
{
62-
$edges = [
63-
'B' => ['C', 'D'],
64-
'A' => ['B'],
65-
'C' => ['D'],
66-
'D' => ['A']
67-
];
62+
$edges = array(
63+
'B' => array('C', 'D'),
64+
'A' => array('B'),
65+
'C' => array('D'),
66+
'D' => array('A')
67+
);
6868

6969
TopologicalSort::apply($edges);
7070
}
@@ -73,7 +73,7 @@ private function shuffleGraphSpec(array $array)
7373
{
7474
$keys = array_keys($array);
7575
shuffle($keys);
76-
$result = [];
76+
$result = array();
7777
foreach ($keys as $key) {
7878
$result[$key] = $array[$key];
7979
shuffle($result[$key]);

0 commit comments

Comments
 (0)