Completed
Push — multimodel-dp ( 745c1d...bcd65b )
by Peter
03:53
created

RecursiveFilter::mongoIdToString()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 1
nop 1
crap 3
1
<?php
2
3
namespace Maslosoft\Manganel\Helpers;
4
5
use MongoId;
6
use RecursiveArrayIterator;
7
use RecursiveIteratorIterator;
8
9
/**
10
 * RecursiveFilter
11
 *
12
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
13
 */
14
class RecursiveFilter
15
{
16
17
	/**
18
	 * Transform each occurence of MongoId instance to it's string
19
	 * representation. This is required, as ElasticSearch anyway cannot
20
	 * store MongoId's
21
	 * @param array $data
22
	 */
23
	public static function mongoIdToString(array $data)
24
	{
25
		// In some cases $value *might* still be mongoId type,
26 43
		$callback = function(&$item, $key)
27
		{
28 43
			if ($key === 'primaryOne')
29
			{
30 5
				codecept_debug($item);
31
			}
32 43
			if ($item instanceof MongoId)
33
			{
34 1
				$item = (string) $item;
35
			}
36 43
		};
37
38 43
		array_walk_recursive($data, $callback);
39 43
		return $data;
40
	}
41
42
}
43