Slot   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 62
ccs 24
cts 24
cp 1
rs 10
wmc 11

8 Methods

Rating   Name   Duplication   Size   Complexity  
A clearTargets() 0 13 3
A adUnitPath() 0 3 1
A make() 0 3 1
A size() 0 3 1
A divId() 0 3 1
A addTarget() 0 5 1
A __construct() 0 9 2
A targets() 0 3 1
1
<?php
2
3
namespace AdDirector\GPT;
4
5
use Illuminate\Support\Str;
6
7
/**
8
 * @link https://developers.google.com/publisher-tag/reference#googletag.defineSlot
9
 */
10
class Slot
11
{
12
    protected string $divId;
13
14
    protected array $targets = [];
15
16 5
    public function __construct(
17
        protected string      $adUnitPath,
18
        protected Size|string $size,
19
        ?string               $divId = null
20
    ) {
21 5
        if (is_null($divId)) {
22 3
            $divId = 'id_'.Str::random(8).'_'.time();
23
        }
24 5
        $this->divId = $divId;
25
    }
26
27 5
    public static function make(...$arguments): static
28
    {
29 5
        return new static(...$arguments);
30
    }
31
32 4
    public function targets(): array
33
    {
34 4
        return $this->targets;
35
    }
36
37 1
    public function addTarget(string $key, string|array $value): static
38
    {
39 1
        $this->targets[$key] = $value;
40
41 1
        return $this;
42
    }
43
44 1
    public function clearTargets(string|array|null $key = null): static
45
    {
46 1
        if (is_null($key)) {
47 1
            $this->targets = [];
48
49 1
            return $this;
50
        }
51
52 1
        foreach (((array) $key) as $key) {
53 1
            unset($this->targets[$key]);
54
        }
55
56 1
        return $this;
57
    }
58
59 4
    public function adUnitPath(): string
60
    {
61 4
        return $this->adUnitPath;
62
    }
63
64 4
    public function divId(): string
65
    {
66 4
        return $this->divId;
67
    }
68
69 4
    public function size(): Size|string
70
    {
71 4
        return $this->size;
72
    }
73
}
74