Uuid::getLong()   A
last analyzed

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\Id;
4
5
use Igni\Storage\Exception\MappingException;
6
use Igni\Util\UuidGenerator;
7
use InvalidArgumentException;
8
9
class Uuid extends GenericId
10
{
11
    private $long;
12
13 9
    public function __construct(string $value = null)
14
    {
15 9
        if ($value === null) {
16 6
            $value = UuidGenerator::generate();
17 6
            $this->long = $value;
18 6
            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...
19
        }
20
21 3
        $uuid = (string) $value;
22 3
        $short = (string) $value;
23
24
        try {
25 3
            if (!UuidGenerator::validate($uuid)) {
26 3
                $uuid = UuidGenerator::fromShort($uuid);
27
            } else {
28 2
                $short = UuidGenerator::toShort($short);
29
            }
30 1
        } catch (InvalidArgumentException $exception) {
31 1
            throw MappingException::forInvalidUuid($value);
32
        }
33
34 2
        if (!UuidGenerator::validate($uuid)) {
35 1
            throw MappingException::forInvalidUuid($value);
36
        }
37
38 1
        $this->long = $uuid;
39 1
        parent::__construct($short);
40 1
    }
41
42 2
    public function getShort(): string
43
    {
44 2
        return $this->getValue();
45
    }
46
47 2
    public function getLong(): string
48
    {
49 2
        return $this->long;
50
    }
51
}
52