Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
94.44% covered (success)
94.44%
17 / 18
74.07% covered (warning)
74.07%
20 / 27
17.07% covered (danger)
17.07%
7 / 41
57.14% covered (warning)
57.14%
4 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
EntityId
94.44% covered (success)
94.44%
17 / 18
74.07% covered (warning)
74.07%
20 / 27
17.07% covered (danger)
17.07%
7 / 41
85.71% covered (warning)
85.71%
6 / 7
44.50
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
83.33% covered (warning)
83.33%
5 / 6
50.00% covered (danger)
50.00%
2 / 4
100.00% covered (success)
100.00%
1 / 1
2.50
 fromString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 generate
100.00% covered (success)
100.00%
10 / 10
68.75% covered (warning)
68.75%
11 / 16
3.12% covered (danger)
3.12%
1 / 32
100.00% covered (success)
100.00%
1 / 1
1.91
 value
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 equals
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 valueEquals
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Shared\Domain\Model;
4
5use App\Shared\Domain\Exception\InvalidEntityIdException;
6use Random\RandomException;
7
8class EntityId
9{
10    private string $value;
11
12    /**
13     * @throws InvalidEntityIdException
14     */
15    private function __construct(string $value)
16    {
17        // TODO check value format
18        if (!preg_match('/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i', $value)) {
19            throw new InvalidEntityIdException();
20        }
21        $this->value = $value;
22    }
23
24    /**
25     * @throws InvalidEntityIdException
26     */
27    public static function fromString(string $value): self
28    {
29        return new self($value);
30    }
31
32    /**
33     * @throws RandomException
34     */
35    public static function generate(): self
36    {
37        // Simple UUID v4 generation
38        $data = random_bytes(16);
39        $data[6] = chr((ord($data[6]) & 0x0f) | 0x40); // version 4
40        $data[8] = chr((ord($data[8]) & 0x3f) | 0x80); // variant
41        $hex = bin2hex($data);
42        $uuid = substr($hex, 0, 8) . '-' .
43            substr($hex, 8, 4) . '-' .
44            substr($hex, 12, 4) . '-' .
45            substr($hex, 16, 4) . '-' .
46            substr($hex, 20, 12);
47        return new self($uuid);
48    }
49
50    public function value(): string
51    {
52        return $this->value;
53    }
54
55    public function __toString(): string
56    {
57        return $this->value;
58    }
59
60    public function equals(EntityId $entityId): bool
61    {
62        return $this->value() === $entityId->value();
63    }
64
65    public function valueEquals(string $value): bool
66    {
67        return $this->value() === $value;
68    }
69}

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

EntityId->__construct
15    private function __construct(string $value)
16    {
17        // TODO check value format
18        if (!preg_match('/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i', $value)) {
18        if (!preg_match('/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i', $value)) {
18        if (!preg_match('/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i', $value)) {
18        if (!preg_match('/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i', $value)) {
19            throw new InvalidEntityIdException();
21        $this->value = $value;
22    }
EntityId->__toString
57        return $this->value;
58    }
EntityId->equals
60    public function equals(EntityId $entityId): bool
61    {
62        return $this->value() === $entityId->value();
63    }
EntityId->fromString
27    public static function fromString(string $value): self
28    {
29        return new self($value);
30    }
EntityId->generate
38        $data = random_bytes(16);
39        $data[6] = chr((ord($data[6]) & 0x0f) | 0x40); // version 4
40        $data[8] = chr((ord($data[8]) & 0x3f) | 0x80); // variant
41        $hex = bin2hex($data);
42        $uuid = substr($hex, 0, 8) . '-' .
42        $uuid = substr($hex, 0, 8) . '-' .
42        $uuid = substr($hex, 0, 8) . '-' .
42        $uuid = substr($hex, 0, 8) . '-' .
43            substr($hex, 8, 4) . '-' .
43            substr($hex, 8, 4) . '-' .
43            substr($hex, 8, 4) . '-' .
43            substr($hex, 8, 4) . '-' .
44            substr($hex, 12, 4) . '-' .
44            substr($hex, 12, 4) . '-' .
44            substr($hex, 12, 4) . '-' .
44            substr($hex, 12, 4) . '-' .
45            substr($hex, 16, 4) . '-' .
45            substr($hex, 16, 4) . '-' .
45            substr($hex, 16, 4) . '-' .
45            substr($hex, 16, 4) . '-' .
46            substr($hex, 20, 12);
46            substr($hex, 20, 12);
46            substr($hex, 20, 12);
46            substr($hex, 20, 12);
47        return new self($uuid);
48    }
EntityId->value
52        return $this->value;
53    }
EntityId->valueEquals
65    public function valueEquals(string $value): bool
66    {
67        return $this->value() === $value;
68    }
{main}
3namespace App\Shared\Domain\Model;
4
5use App\Shared\Domain\Exception\InvalidEntityIdException;
6use Random\RandomException;
7
8class EntityId
9{
10    private string $value;
11
12    /**
13     * @throws InvalidEntityIdException
14     */
15    private function __construct(string $value)
16    {
17        // TODO check value format
18        if (!preg_match('/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i', $value)) {
19            throw new InvalidEntityIdException();
20        }
21        $this->value = $value;
22    }
23
24    /**
25     * @throws InvalidEntityIdException
26     */
27    public static function fromString(string $value): self
28    {
29        return new self($value);
30    }
31
32    /**
33     * @throws RandomException
34     */
35    public static function generate(): self
36    {
37        // Simple UUID v4 generation
38        $data = random_bytes(16);
39        $data[6] = chr((ord($data[6]) & 0x0f) | 0x40); // version 4
40        $data[8] = chr((ord($data[8]) & 0x3f) | 0x80); // variant
41        $hex = bin2hex($data);
42        $uuid = substr($hex, 0, 8) . '-' .
43            substr($hex, 8, 4) . '-' .
44            substr($hex, 12, 4) . '-' .
45            substr($hex, 16, 4) . '-' .
46            substr($hex, 20, 12);
47        return new self($uuid);
48    }
49
50    public function value(): string
51    {
52        return $this->value;
53    }
54
55    public function __toString(): string
56    {
57        return $this->value;
58    }
59
60    public function equals(EntityId $entityId): bool
61    {
62        return $this->value() === $entityId->value();
63    }
64
65    public function valueEquals(string $value): bool
66    {
67        return $this->value() === $value;
68    }