elFinderPlugin::iaEnabled()   C
last analyzed

Complexity

Conditions 11
Paths 30

Size

Total Lines 34
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 22
nc 30
nop 1
dl 0
loc 34
rs 5.2653
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * elFinder Plugin Abstract.
4
 *
5
 * @author Naoki Sawada
6
 * @license New BSD
7
 */
8
class elFinderPlugin
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * This plugin's options.
12
     *
13
     * @var array
14
     */
15
    protected $opts = [];
16
17
    /**
18
     * Get current volume's options.
19
     *
20
     * @param object $volume
21
     * @return array options
22
     */
23
    protected function getCurrentOpts($volume)
24
    {
25
        $name = substr(get_class($this), 14); // remove "elFinderPlugin"
26
        $opts = $this->opts;
27
        if (is_object($volume)) {
28
            $volOpts = $volume->getOptionsPlugin($name);
29
            if (is_array($volOpts)) {
30
                $opts = array_merge($opts, $volOpts);
31
            }
32
        }
33
34
        return $opts;
35
    }
36
37
    /**
38
     * Is enabled with options.
39
     *
40
     * @param array $opts
41
     * @return bool
42
     */
43
    protected function iaEnabled($opts)
0 ignored issues
show
Coding Style introduced by
iaEnabled uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
44
    {
45
        if (! $opts['enable']) {
46
            return false;
47
        }
48
49
        if (isset($opts['offDropWith']) && ! is_null($opts['offDropWith']) && isset($_REQUEST['dropWith'])) {
50
            $offDropWith = $opts['offDropWith'];
51
            $action = (int) $_REQUEST['dropWith'];
52
            if (! is_array($offDropWith)) {
53
                $offDropWith = [$offDropWith];
54
            }
55
            $res = true;
56
            foreach ($offDropWith as $key) {
57
                $key = (int) $key;
58
                if ($key === 0) {
59
                    if ($action === 0) {
60
                        $res = false;
61
                        break;
62
                    }
63
                } else {
64
                    if (($action & $key) === $key) {
65
                        $res = false;
66
                        break;
67
                    }
68
                }
69
            }
70
            if (! $res) {
71
                return false;
72
            }
73
        }
74
75
        return true;
76
    }
77
}
78