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

RecursiveFilter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 29
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A mongoIdToString() 0 18 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