Skip to content

Commit 199678f

Browse files
committed
Renamed functions to sit in line with php function names
1 parent d8ea444 commit 199678f

File tree

6 files changed

+38
-37
lines changed

6 files changed

+38
-37
lines changed

src/Arr.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public static function exists($array, $key)
200200
* @param bool $strict
201201
* @return false|int|string
202202
*/
203-
public static function findKey(array $haystack, $needle, $strict = false)
203+
public static function searchKey(array $haystack, $needle, $strict = false)
204204
{
205205
if (is_callable($needle)) {
206206
foreach ($haystack as $key => $item) {
@@ -226,7 +226,7 @@ public static function findKey(array $haystack, $needle, $strict = false)
226226
* @param bool $strict
227227
* @return false|int|string
228228
*/
229-
public static function find(array $haystack, $needle, $strict = false)
229+
public static function search(array $haystack, $needle, $strict = false)
230230
{
231231
if (is_callable($needle)) {
232232
foreach ($haystack as $key => $item) {

src/ArrDots.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,16 @@ public static function get($array, $key, $default = null)
146146
}
147147

148148
/**
149-
* Get all items from a multi-dimensional associative array using "dots" notation.
149+
* Get all items from a multi-dimensional associative array using "dots" notation and
150+
* return a flattened "dots" notation array.
150151
*
151152
* @param ArrayAccess|array $array
152153
* @param string $key
153154
* @param null|string $wildcard
154155
*
155156
* @return array|mixed[]
156157
*/
157-
public static function search($array, $key, $wildcard = null)
158+
public static function collate($array, $key, $wildcard = null)
158159
{
159160
// If no wildcard set or the wildcard is not in the key
160161
if (null === $wildcard || strpos($key, $wildcard) === false) {
@@ -174,7 +175,7 @@ public static function search($array, $key, $wildcard = null)
174175
$values = [];
175176
foreach (array_keys($array) as $attr) {
176177
$subKey = implode('.', array_merge([$attr], $segments));
177-
foreach (static::search($array, $subKey, $wildcard) as $attrKey => $value) {
178+
foreach (static::collate($array, $subKey, $wildcard) as $attrKey => $value) {
178179
$values[$pattern . $attrKey] = $value;
179180
}
180181
}

src/Collection.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ public function unique($flag = SORT_REGULAR)
193193
* @param bool $strict
194194
* @return mixed|null
195195
*/
196-
public function find($needle, $strict = false)
196+
public function search($needle, $strict = false)
197197
{
198-
return Arr::find($this->items, $needle, $strict);
198+
return Arr::search($this->items, $needle, $strict);
199199
}
200200

201201
/**

tests/Unit/ArrDotsTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function testGet()
127127
$this->assertEquals('Not There', ArrDots::get($array, 'foobar', 'Not There'));
128128
}
129129

130-
public function testSearch()
130+
public function testCollate()
131131
{
132132
$data = [
133133
'field0' => 'field0-value',
@@ -146,30 +146,30 @@ public function testSearch()
146146
],
147147
];
148148

149-
$this->assertEquals([], ArrDots::search($data, 'field1'));
150-
$this->assertEquals([], ArrDots::search($data, 'field0.*'));
151-
$this->assertEquals([], ArrDots::search($data, 'array1.item1'));
149+
$this->assertEquals([], ArrDots::collate($data, 'field1'));
150+
$this->assertEquals([], ArrDots::collate($data, 'field0.*'));
151+
$this->assertEquals([], ArrDots::collate($data, 'array1.item1'));
152152
$this->assertEquals([
153153
'field0' => 'field0-value'
154-
], ArrDots::search($data, 'field0'));
154+
], ArrDots::collate($data, 'field0'));
155155
$this->assertEquals([
156156
'array0' => [1, 2, 3, 4]
157-
], ArrDots::search($data, 'array0'));
157+
], ArrDots::collate($data, 'array0'));
158158
$this->assertEquals([
159159
'array0.0' => 1,
160160
'array0.1' => 2,
161161
'array0.2' => 3,
162162
'array0.3' => 4,
163-
], ArrDots::search($data, 'array0.*', '*'));
163+
], ArrDots::collate($data, 'array0.*', '*'));
164164
$this->assertEquals([
165165
'array2.0.sub-array0' => [1, 2, 3, 4],
166166
'array2.1.sub-array0' => [1, 2, 3, 4],
167-
], ArrDots::search($data, 'array2.*.sub-array0', '*'));
167+
], ArrDots::collate($data, 'array2.*.sub-array0', '*'));
168168
$this->assertEquals([
169169
'array3.0.sub-array1.0.item1' => 'item2-value',
170170
'array3.0.sub-array1.1.item1' => 'item3-value',
171171
'array3.1.sub-array1.0.item1' => 'item4-value',
172-
], ArrDots::search($data, 'array3.*.sub-array1.*.item1', '*'));
172+
], ArrDots::collate($data, 'array3.*.sub-array1.*.item1', '*'));
173173
}
174174

175175
public function testHas()

tests/Unit/ArrTest.php

+20-20
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function testExists()
209209
$this->assertFalse(Arr::exists($array, 'four'));
210210
}
211211

212-
public function testFindKey()
212+
public function testSearchKey()
213213
{
214214
$array = [
215215
'one' => 'value 1',
@@ -221,14 +221,14 @@ public function testFindKey()
221221
]
222222
];
223223

224-
$this->assertEquals('one', Arr::findKey($array, 'value 1'));
225-
$this->assertEquals('two', Arr::findKey($array, 'value 2'));
226-
$this->assertEquals('three', Arr::findKey($array, 'value 3'));
224+
$this->assertEquals('one', Arr::searchKey($array, 'value 1'));
225+
$this->assertEquals('two', Arr::searchKey($array, 'value 2'));
226+
$this->assertEquals('three', Arr::searchKey($array, 'value 3'));
227227

228-
$this->assertFalse(Arr::findKey($array, 'four'));
228+
$this->assertFalse(Arr::searchKey($array, 'four'));
229229
}
230230

231-
public function testFindKeyCallable()
231+
public function testSearchKeyCallable()
232232
{
233233
$array = [
234234
'one' => 'value 1',
@@ -240,14 +240,14 @@ public function testFindKeyCallable()
240240
]
241241
];
242242

243-
$this->assertEquals('one', Arr::findKey($array, function ($item) { return $item === 'value 1';}));
244-
$this->assertEquals('two', Arr::findKey($array, function ($item) { return $item === 'value 2';}));
245-
$this->assertEquals('three', Arr::findKey($array, function ($item) { return $item === 'value 3';}));
243+
$this->assertEquals('one', Arr::searchKey($array, function ($item) { return $item === 'value 1';}));
244+
$this->assertEquals('two', Arr::searchKey($array, function ($item) { return $item === 'value 2';}));
245+
$this->assertEquals('three', Arr::searchKey($array, function ($item) { return $item === 'value 3';}));
246246

247-
$this->assertFalse(Arr::findKey($array, function ($item) { return $item === 'blah';}));
247+
$this->assertFalse(Arr::searchKey($array, function ($item) { return $item === 'blah';}));
248248
}
249249

250-
public function testFind()
250+
public function testSearch()
251251
{
252252
$array = [
253253
'one' => 'value 1',
@@ -259,14 +259,14 @@ public function testFind()
259259
]
260260
];
261261

262-
$this->assertEquals('value 1', Arr::find($array, 'value 1'));
263-
$this->assertEquals('value 2', Arr::find($array, 'value 2'));
264-
$this->assertEquals('value 3', Arr::find($array, 'value 3'));
262+
$this->assertEquals('value 1', Arr::search($array, 'value 1'));
263+
$this->assertEquals('value 2', Arr::search($array, 'value 2'));
264+
$this->assertEquals('value 3', Arr::search($array, 'value 3'));
265265

266-
$this->assertNull(Arr::find($array, 'four'));
266+
$this->assertNull(Arr::search($array, 'four'));
267267
}
268268

269-
public function testFindCallable()
269+
public function testSearchCallable()
270270
{
271271
$array = [
272272
'one' => 'value 1',
@@ -278,11 +278,11 @@ public function testFindCallable()
278278
]
279279
];
280280

281-
$this->assertEquals('value 1', Arr::find($array, function ($item, $key) { return $key === 'one'; }));
282-
$this->assertEquals('value 2', Arr::find($array, function ($item, $key) { return $key === 'two'; }));
283-
$this->assertEquals('value 3', Arr::find($array, function ($item, $key) { return $key === 'three'; }));
281+
$this->assertEquals('value 1', Arr::search($array, function ($item, $key) { return $key === 'one'; }));
282+
$this->assertEquals('value 2', Arr::search($array, function ($item, $key) { return $key === 'two'; }));
283+
$this->assertEquals('value 3', Arr::search($array, function ($item, $key) { return $key === 'three'; }));
284284

285-
$this->assertNull(Arr::find($array, function ($item, $key) { return $key === 'four'; }));
285+
$this->assertNull(Arr::search($array, function ($item, $key) { return $key === 'four'; }));
286286
}
287287

288288
public function testLocate()

tests/Unit/CollectionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function testFind()
192192
];
193193
$collection = new Collection($items);
194194

195-
$this->assertEquals(['id' => 2, 'value' => 'beta'], $collection->find(function ($item) {
195+
$this->assertEquals(['id' => 2, 'value' => 'beta'], $collection->search(function ($item) {
196196
return $item['id'] == 2;
197197
}));
198198
}

0 commit comments

Comments
 (0)