Completed
Push — master ( 78f1d5...da548b )
by Dawid
04:18
created

Id::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Igni\Storage\Driver\MongoDB;
4
5
use MongoDB\BSON\ObjectId;
6
7
class Id implements \Igni\Storage\Id
8
{
9
    private $value;
10
11 2
    public function __construct($value = null)
12
    {
13 2
        if ($value === null) {
14 1
            $value = new ObjectId();
15
        }
16
17 2
        if (!$value instanceof ObjectId) {
18 1
            $value = new ObjectId((string) $value);
19
        }
20
21 2
        $this->value = $value;
22 2
    }
23
24 2
    public function getValue()
25
    {
26 2
        return $this->value;
27
    }
28
29 2
    public function __toString(): string
30
    {
31 2
        return (string) $this->value;
32
    }
33
}
34