Completed
Push — master ( cf1d2d...03d5cb )
by raphael
9s
created

LogViewerController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
c 4
b 0
f 0
lcom 0
cbo 2
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B index() 0 22 4
A redirect() 0 8 2
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
use Illuminate\Support\Facades\File;
11
use Illuminate\Support\Facades\View;
12
use Illuminate\Support\Facades\Redirect;
13
use Illuminate\Support\Facades\Request;
14
use Illuminate\Support\Facades\Response;
15
16
class LogViewerController extends BaseController
17
{
18
19
    public function index()
20
    {
21
22
        if (Request::input('l')) {
23
            LaravelLogViewer::setFile(base64_decode(Request::input('l')));
24
        }
25
26
        if (Request::input('dl')) {
27
            return Response::download(LaravelLogViewer::pathToLogFile(base64_decode(Request::input('dl'))));
28
        } elseif (Request::has('del')) {
29
            File::delete(LaravelLogViewer::pathToLogFile(base64_decode(Request::input('del'))));
30
            return $this->redirect(Request::url());
31
        }
32
33
        $logs = LaravelLogViewer::all();
34
35
        return 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 Redirect::to($to);
49
    }
50
}
51