ScriptViewCreator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 11 3
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