Skip to content

Commit b1c16c7

Browse files
Merge pull request #52 from GrahamCampbell/code-style
Code style fixes
2 parents 52a03a2 + 71112e3 commit b1c16c7

File tree

6 files changed

+57
-46
lines changed

6 files changed

+57
-46
lines changed

src/FnDispatcher.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ private function fn_length(array $args)
118118
private function fn_max(array $args)
119119
{
120120
$this->validate('max', $args, [['array']]);
121-
$fn = function ($a, $b) { return $a >= $b ? $a : $b; };
121+
$fn = function ($a, $b) {
122+
return $a >= $b ? $a : $b;
123+
};
122124
return $this->reduce('max:0', $args[0], ['number', 'string'], $fn);
123125
}
124126

@@ -137,7 +139,9 @@ private function fn_max_by(array $args)
137139
private function fn_min(array $args)
138140
{
139141
$this->validate('min', $args, [['array']]);
140-
$fn = function ($a, $b, $i) { return $i && $a <= $b ? $a : $b; };
142+
$fn = function ($a, $b, $i) {
143+
return $i && $a <= $b ? $a : $b;
144+
};
141145
return $this->reduce('min:0', $args[0], ['number', 'string'], $fn);
142146
}
143147

@@ -167,7 +171,9 @@ private function fn_reverse(array $args)
167171
private function fn_sum(array $args)
168172
{
169173
$this->validate('sum', $args, [['array']]);
170-
$fn = function ($a, $b) { return $a + $b; };
174+
$fn = function ($a, $b) {
175+
return $a + $b;
176+
};
171177
return $this->reduce('sum:0', $args[0], ['number'], $fn);
172178
}
173179

src/Parser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ private function nud_not()
142142
return ['type' => T::T_NOT, 'children' => [$this->expr(self::$bp[T::T_NOT])]];
143143
}
144144

145-
private function nud_lparen() {
145+
private function nud_lparen()
146+
{
146147
$this->next();
147148
$result = $this->expr(0);
148149
if ($this->token['type'] !== T::T_RPAREN) {

src/Utils.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class Utils
55
{
6-
static $typeMap = [
6+
public static $typeMap = [
77
'boolean' => 'boolean',
88
'string' => 'string',
99
'NULL' => 'null',
@@ -140,14 +140,18 @@ public static function isEqual($a, $b)
140140
public static function stableSort(array $data, callable $sortFn)
141141
{
142142
// Decorate each item by creating an array of [value, index]
143-
array_walk($data, function (&$v, $k) { $v = [$v, $k]; });
143+
array_walk($data, function (&$v, $k) {
144+
$v = [$v, $k];
145+
});
144146
// Sort by the sort function and use the index as a tie-breaker
145147
uasort($data, function ($a, $b) use ($sortFn) {
146148
return $sortFn($a[0], $b[0]) ?: ($a[1] < $b[1] ? -1 : 1);
147149
});
148150

149151
// Undecorate each item and return the resulting sorted array
150-
return array_map(function ($v) { return $v[0]; }, array_values($data));
152+
return array_map(function ($v) {
153+
return $v[0];
154+
}, array_values($data));
151155
}
152156

153157
/**

tests/EnvTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ class EnvTest extends TestCase
99
{
1010
public function testSearchesInput()
1111
{
12-
$data = array('foo' => 123);
12+
$data = ['foo' => 123];
1313
$this->assertEquals(123, Env::search('foo', $data));
1414
$this->assertEquals(123, Env::search('foo', $data));
1515
}
1616

1717
public function testSearchesWithFunction()
1818
{
19-
$data = array('foo' => 123);
19+
$data = ['foo' => 123];
2020
$this->assertEquals(123, \JmesPath\search('foo', $data));
2121
}
2222

tests/LexerTest.php

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,36 @@ class LexerTest extends TestCase
1212
{
1313
public function inputProvider()
1414
{
15-
return array(
16-
array('0', 'number'),
17-
array('1', 'number'),
18-
array('2', 'number'),
19-
array('3', 'number'),
20-
array('4', 'number'),
21-
array('5', 'number'),
22-
array('6', 'number'),
23-
array('7', 'number'),
24-
array('8', 'number'),
25-
array('9', 'number'),
26-
array('-1', 'number'),
27-
array('-1.5', 'number'),
28-
array('109.5', 'number'),
29-
array('.', 'dot'),
30-
array('{', 'lbrace'),
31-
array('}', 'rbrace'),
32-
array('[', 'lbracket'),
33-
array(']', 'rbracket'),
34-
array(':', 'colon'),
35-
array(',', 'comma'),
36-
array('||', 'or'),
37-
array('*', 'star'),
38-
array('foo', 'identifier'),
39-
array('"foo"', 'quoted_identifier'),
40-
array('`true`', 'literal'),
41-
array('`false`', 'literal'),
42-
array('`null`', 'literal'),
43-
array('`"true"`', 'literal')
44-
);
15+
return [
16+
['0', 'number'],
17+
['1', 'number'],
18+
['2', 'number'],
19+
['3', 'number'],
20+
['4', 'number'],
21+
['5', 'number'],
22+
['6', 'number'],
23+
['7', 'number'],
24+
['8', 'number'],
25+
['9', 'number'],
26+
['-1', 'number'],
27+
['-1.5', 'number'],
28+
['109.5', 'number'],
29+
['.', 'dot'],
30+
['{', 'lbrace'],
31+
['}', 'rbrace'],
32+
['[', 'lbracket'],
33+
[']', 'rbracket'],
34+
[':', 'colon'],
35+
[',', 'comma'],
36+
['||', 'or'],
37+
['*', 'star'],
38+
['foo', 'identifier'],
39+
['"foo"', 'quoted_identifier'],
40+
['`true`', 'literal'],
41+
['`false`', 'literal'],
42+
['`null`', 'literal'],
43+
['`"true"`', 'literal']
44+
];
4545
}
4646

4747
/**

tests/TreeInterpreterTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ class TreeInterpreterTest extends TestCase
1313
public function testReturnsNullWhenMergingNonArray()
1414
{
1515
$t = new TreeInterpreter();
16-
$this->assertNull($t->visit(array(
16+
$this->assertNull($t->visit([
1717
'type' => 'flatten',
18-
'children' => array(
19-
array('type' => 'literal', 'value' => 1),
20-
array('type' => 'literal', 'value' => 1)
21-
)
22-
), array(), array(
18+
'children' => [
19+
['type' => 'literal', 'value' => 1],
20+
['type' => 'literal', 'value' => 1]
21+
]
22+
], [], [
2323
'runtime' => new AstRuntime()
24-
)));
24+
]));
2525
}
2626

2727
public function testWorksWithArrayObjectAsObject()

0 commit comments

Comments
 (0)