Passed
Push — master ( 423f1a...7014e5 )
by Stream
06:34
created

LfmController::error()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace UniSharp\LaravelFilemanager\Controllers;
4
5
use UniSharp\LaravelFilemanager\Lfm;
6
use UniSharp\LaravelFilemanager\LfmPath;
7
8
class LfmController extends Controller
9
{
10
    protected static $success_response = 'OK';
11
12
    public function __construct()
13
    {
14
        $this->applyIniOverrides();
15
    }
16
17
    /**
18
     * Set up needed functions.
19
     *
20
     * @return object|null
21
     */
22
    public function __get($var_name)
23
    {
24
        if ($var_name === 'lfm') {
25
            return app(LfmPath::class);
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
            return /** @scrutinizer ignore-call */ app(LfmPath::class);
Loading history...
26
        } elseif ($var_name === 'helper') {
27
            return app(Lfm::class);
28
        }
29
    }
30
31
    /**
32
     * Show the filemanager.
33
     *
34
     * @return mixed
35
     */
36
    public function show()
37
    {
38
        return view('laravel-filemanager::index')
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        return /** @scrutinizer ignore-call */ view('laravel-filemanager::index')
Loading history...
39
            ->withHelper($this->helper);
0 ignored issues
show
Bug Best Practice introduced by
The property helper does not exist on UniSharp\LaravelFilemana...ntrollers\LfmController. Since you implemented __get, consider adding a @property annotation.
Loading history...
40
    }
41
42
    /**
43
     * Check if any extension or config is missing.
44
     *
45
     * @return array
46
     */
47
    public function getErrors()
48
    {
49
        $arr_errors = [];
50
51
        if (! extension_loaded('gd') && ! extension_loaded('imagick')) {
52
            array_push($arr_errors, trans('laravel-filemanager::lfm.message-extension_not_found'));
0 ignored issues
show
Unused Code introduced by
The call to trans() has too many arguments starting with 'laravel-filemanager::lf...ge-extension_not_found'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
            array_push($arr_errors, /** @scrutinizer ignore-call */ trans('laravel-filemanager::lfm.message-extension_not_found'));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
Are you sure the usage of trans('laravel-filemanag...e-extension_not_found') 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...
53
        }
54
55
        if (! extension_loaded('exif')) {
56
            array_push($arr_errors, 'EXIF extension not found.');
57
        }
58
59
        if (! extension_loaded('fileinfo')) {
60
            array_push($arr_errors, 'Fileinfo extension not found.');
61
        }
62
63
        $mine_config_key = 'lfm.folder_categories.'
64
            . $this->helper->currentLfmType()
0 ignored issues
show
Bug Best Practice introduced by
The property helper does not exist on UniSharp\LaravelFilemana...ntrollers\LfmController. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method currentLfmType() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
            . $this->helper->/** @scrutinizer ignore-call */ currentLfmType()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
            . '.valid_mime';
66
67
        if (! is_array(config($mine_config_key))) {
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
        if (! is_array(/** @scrutinizer ignore-call */ config($mine_config_key))) {
Loading history...
68
            array_push($arr_errors, 'Config : ' . $mine_config_key . ' is not a valid array.');
69
        }
70
71
        return $arr_errors;
72
    }
73
74
    /**
75
     * Overrides settings in php.ini.
76
     *
77
     * @return null
78
     */
79
    private function applyIniOverrides()
80
    {
81
        $overrides = config('lfm.php_ini_overrides', []);
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
        $overrides = /** @scrutinizer ignore-call */ config('lfm.php_ini_overrides', []);
Loading history...
82
83
        if ($overrides && is_array($overrides) && count($overrides) === 0) {
84
            return;
85
        }
86
87
        foreach ($overrides as $key => $value) {
88
            if ($value && $value != 'false') {
89
                ini_set($key, $value);
90
            }
91
        }
92
    }
93
94
    // TODO: remove this after refactoring RenameController and DeleteController
95
    protected function error($error_type, $variables = [])
96
    {
97
        return trans(Lfm::PACKAGE_NAME . '::lfm.error-' . $error_type, $variables);
0 ignored issues
show
Unused Code introduced by
The call to trans() has too many arguments starting with UniSharp\LaravelFilemana...m.error-' . $error_type. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

97
        return /** @scrutinizer ignore-call */ trans(Lfm::PACKAGE_NAME . '::lfm.error-' . $error_type, $variables);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
Are you sure the usage of trans(UniSharp\LaravelFi...error_type, $variables) 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...
98
    }
99
}
100