View::collectDetails()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace JumpGate\ViewResolution\Builders;
4
5
use Illuminate\View\Factory;
6
use JumpGate\ViewResolution\Models\View as ViewModel;
7
use JumpGate\ViewResolution\Resolvers\Layout;
8
use JumpGate\ViewResolution\Resolvers\Path;
9
10
class View
11
{
12
    /**
13
     * @var \Illuminate\View\View
14
     */
15
    public $layout;
16
17
    /**
18
     * @var Factory
19
     */
20
    public $view;
21
22
    /**
23
     * @var Layout
24
     */
25
    protected $viewLayout;
26
27
    /**
28
     * @var Path
29
     */
30
    protected $viewPath;
31
32
    /**
33
     * @param Layout  $viewLayout
34
     * @param Path    $viewPath
35
     * @param Factory $view
36
     */
37
    public function __construct(Layout $viewLayout, Path $viewPath, Factory $view)
38
    {
39
        $this->viewLayout = $viewLayout;
40
        $this->viewPath   = $viewPath;
41
        $this->view       = $view;
42
    }
43
44
    /**
45
     * @param array       $layoutOptions
46
     * @param null|string $view
47
     */
48
    public function setUp($layoutOptions, $view = null)
49
    {
50
        $this->layout         = $this->viewLayout->setUp($layoutOptions);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->viewLayout->setUp($layoutOptions) of type object<JumpGate\ViewResolution\Resolvers\Layout> is incompatible with the declared type object<Illuminate\View\View> of property $layout.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
51
        $this->layout->layout = $this->viewPath->setUp($this->layout->layout, $view);
52
    }
53
54
    /**
55
     * Check if a view exists.
56
     *
57
     * @param string $view
58
     *
59
     * @return bool
60
     */
61
    public function exists($view)
62
    {
63
        return $this->view->exists($view);
64
    }
65
66
    /**
67
     * Get the current layout.
68
     *
69
     * @return mixed
70
     */
71
    public function getLayout()
72
    {
73
        return $this->layout->layout;
74
    }
75
76
    /**
77
     * If a method is not defined, try to find it's view.
78
     *
79
     * @param array $parameters
80
     *
81
     * @return $this
82
     */
83
    public function missingMethod($parameters)
84
    {
85
        if (! app()->runningInConsole()) {
86
            $this->viewPath->missingMethod($this->layout->layout, $parameters);
87
        }
88
89
        return $this;
90
    }
91
92
    /**
93
     * Set a custom layout for a page.
94
     *
95
     * @param string $view
96
     */
97
    public function setViewLayout($view)
98
    {
99
        $this->layout         = $this->viewLayout->change($view);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->viewLayout->change($view) of type object<JumpGate\ViewResolution\Resolvers\Layout> is incompatible with the declared type object<Illuminate\View\View> of property $layout.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
100
        $this->layout->layout = $this->viewPath->setUp($this->layout->layout, null);
101
    }
102
103
    /**
104
     * Override the automatically resolved view.
105
     *
106
     * @param string $view
107
     *
108
     * @return $this
109
     */
110
    public function setViewPath($view)
111
    {
112
        $this->layout->layout = $this->viewPath->setUp($this->layout->layout, $view);
113
114
        return $this;
115
    }
116
117
    /**
118
     * Share data with the view.
119
     *
120
     * @param $key
121
     * @param $value
122
     *
123
     * @return $this
124
     */
125
    public function addData($key, $value)
126
    {
127
        $this->view->share($key, $value);
128
129
        return $this;
130
    }
131
132
    /**
133
     * Return the dot notation view the resolver determined.
134
     *
135
     * @return mixed
136
     */
137
    public function getPath()
138
    {
139
        return $this->viewPath->path;
140
    }
141
142
    /**
143
     * Return the details of the view resolution for troubleshooting.
144
     *
145
     * @return mixed
146
     */
147
    public function debug()
148
    {
149
        return $this->viewPath->viewModel;
150
    }
151
152
    /**
153
     * Pass the view resolution details to the debugbar collector.
154
     *
155
     * @param ViewModel $viewModel
156
     */
157
    public function collectDetails($viewModel)
158
    {
159
        if (checkDebugbar()) {
160
            $debugbar = app('debugbar');
161
162
            if ($debugbar->shouldCollect('auto_views')) {
163
                $debugbar['auto_views']->addDetails($viewModel);
164
            }
165
        }
166
    }
167
}
168