TemplatesController::view()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace A17\Twill\Http\Controllers\Admin;
4
5
use Illuminate\Routing\ResponseFactory;
6
use Illuminate\View\Factory as ViewFactory;
7
8
class TemplatesController extends Controller
9
{
10
    /**
11
     * @var ViewFactory
12
     */
13
    protected $viewFactory;
14
15
    /**
16
     * @var ResponseFactory
17
     */
18
    protected $responseFactory;
19
20
    public function __construct(ViewFactory $viewFactory, ResponseFactory $responseFactory)
21
    {
22
        parent::__construct();
23
24
        $this->viewFactory = $viewFactory;
25
        $this->responseFactory = $responseFactory;
26
    }
27
28
    /**
29
     * @return \Illuminate\View\View
30
     */
31
    public function index()
32
    {
33
        return $this->viewFactory->make('templates.index');
34
    }
35
36
    /**
37
     * @param string $view
38
     * @return \Illuminate\View\View
39
     */
40
    public function view($view)
41
    {
42
        return $this->viewFactory->make('templates.' . $view);
43
    }
44
45
    /**
46
     * @param string view
0 ignored issues
show
Bug introduced by
The type A17\Twill\Http\Controllers\Admin\view was not found. Did you mean view? If so, make sure to prefix the type with \.
Loading history...
47
     * @return \Illuminate\Http\JsonResponse
48
     * @throws \Throwable
49
     */
50
    public function xhr($view)
51
    {
52
        $response = [
53
            'data' => $this->viewFactory->make('templates.' . $view)->render(),
54
            'has_more' => (rand(0, 10) > 5),
55
        ];
56
        return $this->responseFactory->json($response);
57
    }
58
}
59