ContentIdTrait::withoutContentId()   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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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