ScriptViewCreator::create()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
namespace Spatie\GoogleTagManager;
4
5
use Illuminate\View\View;
6
use Spatie\GoogleTagManager\Exceptions\ApiKeyNotSetException;
7
8
class ScriptViewCreator
9
{
10
    /**
11
     * @var \Spatie\GoogleTagManager\GoogleTagManager
12
     */
13
    protected $googleTagManager;
14
15
    /**
16
     * @param  \Spatie\GoogleTagManager\GoogleTagManager
17
     */
18
    public function __construct(GoogleTagManager $googleTagManager)
19
    {
20
        $this->googleTagManager = $googleTagManager;
21
    }
22
23
    /**
24
     * Bind data to the view.
25
     *
26
     * @param View $view
27
     */
28
    public function create(View $view)
29
    {
30
        if ($this->googleTagManager->isEnabled() && empty($this->googleTagManager->id())) {
31
            throw new ApiKeyNotSetException();
32
        }
33
34
        $view
35
            ->with('enabled', $this->googleTagManager->isEnabled())
36
            ->with('id', $this->googleTagManager->id())
37
            ->with('dataLayer', $this->googleTagManager->getDataLayer());
38
    }
39
}
40