Passed
Push — master ( a290cb...57bf28 )
by Dawid
02:40
created

Uuid::getLong()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Igni\Storage\Id;
4
5
use Igni\Storage\Exception\MappingException;
6
use Igni\Util\UuidGenerator;
7
8
class Uuid extends GenericId
9
{
10
    private $long;
11
12 4
    public function __construct($value = null)
13
    {
14 4
        if ($value === null) {
15 4
            $value = UuidGenerator::generate();
16 4
            $this->long = $value;
17 4
            return parent::__construct(UuidGenerator::toShort($value));
0 ignored issues
show
Bug introduced by
Are you sure the usage of parent::__construct(Igni...rator::toShort($value)) targeting Igni\Storage\Id\GenericId::__construct() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
18
        }
19
20
        $uuid = (string) $value;
21
22
        if (!UuidGenerator::validate($uuid)) {
23
            $uuid = UuidGenerator::fromShort($uuid);
24
        }
25
26
        if (!UuidGenerator::validate($uuid)) {
27
            throw MappingException::forInvalidUuid($value);
28
        }
29
30
        $this->long = $uuid;
31
        parent::__construct((string) $value);
32
    }
33
34
    public function getShort(): string
35
    {
36
        return $this->getValue();
37
    }
38
39
    public function getLong(): string
40
    {
41
        return $this->long;
42
    }
43
}
44