ElfinderController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 2 Features 0
Metric Value
dl 0
loc 82
ccs 0
cts 32
cp 0
rs 10
c 2
b 2
f 0
wmc 7
lcom 1
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A elfinder() 0 9 2
A connector() 0 4 1
B sound() 0 27 3
1
<?php
2
3
namespace Recca0120\Elfinder\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Recca0120\Elfinder\Connector;
7
use Illuminate\Routing\Controller;
8
use Illuminate\Filesystem\Filesystem;
9
use Illuminate\Contracts\Routing\ResponseFactory;
10
11
class ElfinderController extends Controller
12
{
13
    /**
14
     * $responseFactory.
15
     *
16
     * @var \Illuminate\Contracts\Routing\ResponseFactory
17
     */
18
    protected $responseFactory;
19
20
    /**
21
     * __construct.
22
     *
23
     * @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory
24
     */
25
    public function __construct(ResponseFactory $responseFactory)
26
    {
27
        $this->responseFactory = $responseFactory;
28
    }
29
30
    /**
31
     * elfinder.
32
     *
33
     * @param \Illuminate\Http\Request $request
34
     * @return \Illuminate\Http\Response
35
     */
36
    public function elfinder(Request $request)
37
    {
38
        $token = null;
39
        if ($request->hasSession() === true) {
40
            $token = $request->session()->token();
41
        }
42
43
        return $this->responseFactory->view('elfinder::elfinder', compact('token'));
44
    }
45
46
    /**
47
     * connector.
48
     *
49
     * @param \Recca0120\Elfinder\Connector $elfinder
0 ignored issues
show
Bug introduced by
There is no parameter named $elfinder. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
50
     * @return mixed
51
     */
52
    public function connector(Connector $connector)
53
    {
54
        return $connector->run();
55
    }
56
57
    /**
58
     * sound.
59
     *
60
     * @param \Illuminate\Filesystem\Filesystem $files
61
     * @param \Illuminate\Http\Request $request
62
     * @param string $file
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function sound(Filesystem $files, Request $request, $file)
66
    {
67
        $filename = __DIR__.'/../../../resources/elfinder/sounds/'.$file;
68
        $mimeType = $files->mimeType($filename);
69
        $lastModified = $files->lastModified($filename);
70
        $eTag = sha1_file($filename);
71
        $headers = [
72
            'content-type' => $mimeType,
73
            'last-modified' => date('D, d M Y H:i:s ', $lastModified).'GMT',
74
        ];
75
76
        if (@strtotime($request->server('HTTP_IF_MODIFIED_SINCE')) === $lastModified ||
77
            trim($request->server('HTTP_IF_NONE_MATCH'), '"') === $eTag
78
        ) {
79
            $response = $this->responseFactory->make(null, 304, $headers);
80
        } else {
81
            $response = $this->responseFactory->stream(function () use ($filename) {
82
                $out = fopen('php://output', 'wb');
83
                $file = fopen($filename, 'rb');
84
                stream_copy_to_stream($file, $out, filesize($filename));
85
                fclose($out);
86
                fclose($file);
87
            }, 200, $headers);
88
        }
89
90
        return $response->setEtag($eTag);
91
    }
92
}
93