PrimaryIdMapper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 45.45%

Importance

Changes 0
Metric Value
dl 0
loc 49
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2
ccs 5
cts 11
cp 0.4545
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getOptions() 0 4 1
A slumber() 0 8 2
A awake() 0 4 1
1
<?php
2
/**
3
 * File was created 11.04.2016 06:22
4
 */
5
6
namespace PeekAndPoke\Component\Slumber\Data\MongoDb\Types;
7
8
use MongoDB\BSON\ObjectId;
9
use PeekAndPoke\Component\Slumber\Annotation\PropertyMappingMarker;
10
use PeekAndPoke\Component\Slumber\Core\Codec\Awaker;
11
use PeekAndPoke\Component\Slumber\Core\Codec\Property\AbstractPropertyMapper;
12
use PeekAndPoke\Component\Slumber\Core\Codec\Slumberer;
13
use PeekAndPoke\Component\Slumber\Data\MongoDb\MongoDbSlumberer;
14
use PeekAndPoke\Component\Slumber\Data\MongoDb\MongoDbUtil;
15
16
/**
17
 * @author Karsten J. Gerber <[email protected]>
18
 */
19
class PrimaryIdMapper extends AbstractPropertyMapper
20
{
21
    /** @var PropertyMappingMarker */
22
    private $options;
23
24
    /**
25
     * PrimaryIdMapper constructor.
26
     *
27
     * @param PropertyMappingMarker $options
28
     */
29
    public function __construct(PropertyMappingMarker $options)
30
    {
31
        $this->options = $options;
32
    }
33
34
    /**
35
     * @return PropertyMappingMarker
36
     */
37
    public function getOptions()
38
    {
39
        return $this->options;
40
    }
41
42
    /**
43
     * @param MongoDbSlumberer|Slumberer $slumberer
44
     * @param mixed                      $value
45
     *
46
     * @return mixed
47
     */
48 28
    public function slumber(Slumberer $slumberer, $value)
49
    {
50 28
        if ($value instanceof 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...
51
            return $value;
52
        }
53
54 28
        return MongoDbUtil::ensureMongoId($value);
55
    }
56
57
    /**
58
     * @param Awaker $awaker
59
     * @param mixed  $value
60
     *
61
     * @return mixed
62
     */
63 21
    public function awake(Awaker $awaker, $value)
64
    {
65 21
        return (string) $value;
66
    }
67
}
68