Completed
Push — master ( 61c24d...075a0d )
by recca
07:28
created

elFinderPlugin   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCurrentOpts() 0 13 3
C iaEnabled() 0 34 11
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