AdGPT   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A locations() 0 3 1
A displayScript() 0 7 2
A presenter() 0 7 3
A configurationScript() 0 7 2
A adLocation() 0 5 2
A addLocation() 0 9 2
1
<?php
2
3
namespace AdDirector\GPT;
4
5
use AdDirector\Core\AdManager;
6
use AdDirector\Core\HasVendorScripts;
7
use AdDirector\RenderMinifier;
8
use Illuminate\Support\Facades\View;
9
10
class AdGPT extends AdManager
11
{
12
    use HasVendorScripts, HasGlobalSizes;
13
14
    protected array $locations = [];
15
16
    protected ?Presenter $presenter = null;
17
18 4
    public function configurationScript(bool $minify = true): string
19
    {
20 4
        $view = View::make('ad-director::gpt.configuration-scripts', [
21 4
            'adPresenter' => $this->presenter(),
22 4
        ])->render();
23
24 4
        return $minify ? RenderMinifier::minify($view) : $view;
25
    }
26
27 4
    public function displayScript(bool $minify = true): string
28
    {
29 4
        $view = View::make('ad-director::gpt.display-scripts', [
30 4
            'adPresenter' => $this->presenter(),
31 4
        ])->render();
32
33 4
        return $minify ? RenderMinifier::minify($view) : $view;
34
    }
35
36 5
    public function adLocation(string $name, bool $minify = true): string
37
    {
38 5
        $view = $this->presenter()->adLocation($name);
39
40 5
        return $minify ? RenderMinifier::minify($view) : $view;
41
    }
42
43 5
    protected function presenter(bool $rebuild = false): Presenter
44
    {
45 5
        if ($rebuild || !$this->presenter) {
46 5
            $this->presenter = new Presenter($this);
47
        }
48
49 5
        return $this->presenter;
50
    }
51
52
    /**
53
     * @param  \AdDirector\GPT\Slot  $slot
54
     * @param  string|null  $name  If name is null than ad unit will be used.
55
     *
56
     * @return static
57
     */
58 4
    public function addLocation(Slot $slot, ?string $name = null): static
59
    {
60 4
        if (is_null($name)) {
61 1
            $name = $slot->adUnitPath();
62
        }
63
64 4
        $this->locations[$name] = $slot;
65
66 4
        return $this;
67
    }
68
69 5
    public function locations(): array
70
    {
71 5
        return $this->locations;
72
    }
73
}
74