Passed
Push — master ( 4f4180...bf0301 )
by Mr
03:44
created

Mongo::resultFix()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 11
rs 8.8333
c 0
b 0
f 0
cc 7
nc 6
nop 1
1
<?php
2
3
namespace DrMVC\Helpers;
4
5
use MongoDB\BSON\ObjectID;
6
use MongoDB\BSON\UTCDateTime;
7
8
/**
9
 * Class Mongo for work with data from mongodb
10
 * @package DrMVC\Helpers
11
 */
12
class Mongo
13
{
14
    /**
15
     * Cleanup result of query
16
     * @param object $array
17
     */
18
    public static function resultFix(&$array)
19
    {
20
        foreach ($array as &$element) {
21
            if ($element instanceof \stdClass) {
22
                self::resultFix($element);
23
            } else {
24
                if (\is_object($element) && $element instanceof ObjectID) {
25
                    $element = (string) $element;
26
                }
27
                if (\is_object($element) && $element instanceof UTCDateTime) {
28
                    $element = (new UTCDateTime((string) $element))->toDateTime()->format('Y-m-d H:i:s');
0 ignored issues
show
Bug introduced by
(string)$element of type string is incompatible with the type integer expected by parameter $milliseconds of MongoDB\BSON\UTCDateTime::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
                    $element = (new UTCDateTime(/** @scrutinizer ignore-type */ (string) $element))->toDateTime()->format('Y-m-d H:i:s');
Loading history...
29
                }
30
            }
31
        }
32
    }
33
}
34