Completed
Pull Request — master (#81)
by
unknown
01:40
created

LogViewerController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Rap2hpoutre\LaravelLogViewer;
3
4
if (class_exists("\\Illuminate\\Routing\\Controller")) {
5
    class BaseController extends \Illuminate\Routing\Controller {}
6
} else if (class_exists("Laravel\\Lumen\\Routing\\Controller")) {
7
    class BaseController extends \Laravel\Lumen\Routing\Controller {}
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Rap2hpoutre\LaravelLogViewer\BaseController has been defined more than once; this definition is ignored, only the first definition in this file (L5-5) is considered.

This check looks for classes that have been defined more than once in the same file.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
8
}
9
10
class LogViewerController extends BaseController
11
{
12
    protected $request;
13
14
    public function __construct ()
15
    {
16
        $this->request = app('request');
17
    }
18
19
    public function index()
20
    {
21
22
        if ($this->request->input('l')) {
23
            LaravelLogViewer::setFile(base64_decode($this->request->input('l')));
24
        }
25
26
        if ($this->request->input('dl')) {
27
            return $this->download(LaravelLogViewer::pathToLogFile(base64_decode($this->request->input('dl'))));
28
        } elseif ($this->request->has('del')) {
29
            app('files')->delete(LaravelLogViewer::pathToLogFile(base64_decode($this->request->input('del'))));
30
            return $this->redirect($this->request->url());
31
        }
32
33
        $logs = LaravelLogViewer::all();
34
35
        return app('view')->make('laravel-log-viewer::log', [
36
            'logs' => $logs,
37
            'files' => LaravelLogViewer::getFiles(true),
38
            'current_file' => LaravelLogViewer::getFileName()
39
        ]);
40
    }
41
42
    private function redirect($to)
43
    {
44
        if (function_exists('redirect')) {
45
            return redirect($to);
46
        }
47
48
        return app('redirect')->to($to);
49
    }
50
51
    private function download($data)
52
    {
53
        if (function_exists('response')) {
54
            return response()->download($data);
55
        }
56
57
        // For laravel 4.2
58
        return app('\Illuminate\Support\Facades\Response')->download($data);
59
    }
60
}
61