AssetController::getIndex()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 28
ccs 15
cts 15
cp 1
rs 9.7666
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 4
1
<?php namespace Distilleries\Expendable\Http\Controllers\Frontend;
2
3
use Distilleries\Expendable\Http\Controllers\Frontend\Base\BaseController;
4
5
class AssetController extends BaseController {
6
7 8
    public function getIndex($path = '')
8
    {
9
10 8
        $directory   = explode('/', $path);
11 8
        $directory   = reset($directory);
12 8
        $white_liste = config('expendable.folder_whitelist');
13 8
        if (in_array($directory, $white_liste))
14
        {
15 6
            $path = storage_path($path);
16 6
            $filesystem = app('files');
17 6
            if ($filesystem->isFile($path))
18
            {
19 4
                $mimetype = mime_content_type($path);
20 4
                if (@is_array(getimagesize($path)))
21
                {
22 2
                    return response()->make($filesystem->get($path), 200, array('content-type' => $mimetype));
23
                } else
24
                {
25 2
                    $name = explode('/', $path);
26 2
                    $name = end($name);
27
28 2
                    return response()->download($path, $name, array('content-type' => $mimetype));
29
                }
30
            }
31
        }
32
33
34 4
        return abort(404);
0 ignored issues
show
Bug introduced by
Are you sure the usage of abort(404) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
35
    }
36
}