MongoDbAwakerImpl   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
dl 0
loc 60
c 0
b 0
f 0
wmc 9
lcom 0
cbo 1
ccs 17
cts 21
cp 0.8095
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getStorage() 0 4 1
B awake() 0 33 7
1
<?php
2
/**
3
 * File was created 03.03.2016 07:13
4
 */
5
6
namespace PeekAndPoke\Component\Slumber\Data\MongoDb;
7
8
use MongoDB\BSON;
9
use PeekAndPoke\Component\Slumber\Core\Codec\GenericAwaker;
10
use PeekAndPoke\Component\Slumber\Core\LookUp\EntityConfigReader;
11
use PeekAndPoke\Component\Slumber\Data\Storage;
12
13
/**
14
 * @author Karsten J. Gerber <[email protected]>
15
 */
16
class MongoDbAwakerImpl extends GenericAwaker implements MongoDbAwaker
17
{
18
    /** @var Storage */
19
    private $storage;
20
21
    /**
22
     * MongoDbAwaker constructor.
23
     *
24
     * @param EntityConfigReader $entityConfigLookUp
25
     * @param Storage            $storage
26
     */
27
    public function __construct(EntityConfigReader $entityConfigLookUp, Storage $storage)
28
    {
29
        parent::__construct($entityConfigLookUp);
30
31
        $this->storage = $storage;
32
    }
33
34
    /**
35
     * @return Storage
36
     */
37 17
    public function getStorage()
38
    {
39 17
        return $this->storage;
40
    }
41
42 21
    public function awake($data, \ReflectionClass $cls)
43
    {
44
        //
45
        // The MongoDB driver returns some typed things that we can normalize here:
46
        // - \MongoDB\BSON\UTCDateTime
47
        // - \MongoDB\BSON\ObjectID
48
        //
49 21
        if (\is_array($data)) {
50 21
            array_walk_recursive($data, function (&$item) {
51
52
                /** @noinspection ReferenceMismatchInspection */
53 21
                if ($item === null ||
54 21
                    is_scalar($item) ||
55 21
                    \is_array($item)) {
56 21
                    return;
57
                }
58
59 21
                if ($item instanceof BSON\UTCDateTime) {
0 ignored issues
show
Bug introduced by
The class MongoDB\BSON\UTCDateTime does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
60 21
                    $item = $item->toDateTime();
61
62 21
                    return;
63
                }
64
65 20
                if ($item instanceof BSON\ObjectID) {
0 ignored issues
show
Bug introduced by
The class MongoDB\BSON\ObjectID does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
66 20
                    $item = $item->__toString();
67
68 20
                    return;
69
                }
70 21
            });
71
        }
72
73 21
        return parent::awake($data, $cls);
74
    }
75
}
76