Completed
Push — master ( 6578e4...b57e95 )
by Sandro
27s queued 17s
created

ContentIdTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 45.45%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 31
ccs 5
cts 11
cp 0.4545
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withContentId() 0 7 2
A contentId() 0 3 1
A __construct() 0 3 1
A withoutContentId() 0 3 1
1
<?php
2
/**
3
 * Sandro Keil (https://sandro-keil.de)
4
 *
5
 * @link      http://github.com/sandrokeil/arangodb-php-client for the canonical source repository
6
 * @copyright Copyright (c) 2018-2020 Sandro Keil
7
 * @license   http://github.com/sandrokeil/arangodb-php-client/blob/master/LICENSE.md New BSD License
8
 */
9
10
declare(strict_types=1);
11
12
namespace ArangoDb\Guard;
13
14
trait ContentIdTrait
15
{
16
    /**
17
     * Content id
18
     *
19
     * @var string|null
20
     */
21
    private $contentId;
22
23 9
    private function __construct(?string $contentId)
24
    {
25 9
        $this->contentId = $contentId;
26 9
    }
27
28
    public static function withContentId(string $contentId = null): self
29
    {
30
        if (null === $contentId) {
31
            $contentId = bin2hex(random_bytes(4));
32
        }
33
34
        return new self($contentId);
35
    }
36
37 9
    public static function withoutContentId(): self
38
    {
39 9
        return new self(null);
40
    }
41
42
    public function contentId(): ?string
43
    {
44
        return $this->contentId;
45
    }
46
}
47