Mongo   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 11
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkId() 0 5 2
B resultFix() 0 11 7
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
     * Check if id have a valid length
16
     * @param   string $id
17
     * @return  bool
18
     */
19
    public static function checkId(string $id): bool
20
    {
21
        // If strlen is incorrect, then return error
22
        $len = \strlen($id);
23
        return ($len !== 24 || $len !== 12);
24
    }
25
26
    /**
27
     * Cleanup result of query
28
     * @param  array|object $array
29
     */
30
    public static function resultFix(&$array)
31
    {
32
        foreach ($array as &$element) {
33
            if ($element instanceof \stdClass) {
34
                self::resultFix($element);
35
            } else {
36
                if (\is_object($element) && $element instanceof ObjectID) {
37
                    $element = (string) $element;
38
                }
39
                if (\is_object($element) && $element instanceof UTCDateTime) {
40
                    $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

40
                    $element = (new UTCDateTime(/** @scrutinizer ignore-type */ (string) $element))->toDateTime()->format('Y-m-d H:i:s');
Loading history...
41
                }
42
            }
43
        }
44
    }
45
}
46