RecursiveFilter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 25
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A mongoIdToString() 0 14 2
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL-3.0-only, proprietary` license[s].
5
 *
6
 * @package maslosoft/manganel
7
 * @license AGPL-3.0-only, proprietary
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 * @link https://maslosoft.com/manganel/
11
 */
12
13
namespace Maslosoft\Manganel\Helpers;
14
15
use MongoId;
16
use RecursiveArrayIterator;
17
use RecursiveIteratorIterator;
18
19
/**
20
 * RecursiveFilter
21
 *
22
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
23
 */
24
class RecursiveFilter
25
{
26
27
	/**
28
	 * Transform each occurence of MongoId instance to it's string
29
	 * representation. This is required, as ElasticSearch anyway cannot
30
	 * store MongoId's
31
	 * @param array $data
32
	 */
33 49
	public static function mongoIdToString(array $data)
34
	{
35
		// In some cases $value *might* still be mongoId type,
36
		$callback = function(&$item, $key)
37
		{
38 49
			if ($item instanceof MongoId)
39
			{
40
				$item = (string) $item;
41
			}
42 49
		};
43
44 49
		array_walk_recursive($data, $callback);
45 49
		return $data;
46
	}
47
48
}
49