Completed
Branch master (486a28)
by Paweł
02:07
created

CodeReviewConfig::getPluginIds()   C

Complexity

Conditions 8
Paths 4

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 10.9859

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 23
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 32
rs 5.3846
ccs 16
cts 25
cp 0.64
crap 10.9859
1
<?php
2
/**
3
 * Simple configuration container handling basic options parsing nad providing convenient methods.
4
 */
5
class CodeReviewConfig {
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...
6
7
	const T_PLUGINS_ALL = 0;
8
	const T_PLUGINS_ACTIVE = 1;
9
	const T_PLUGINS_INACTIVE = 2;
10
11
	/**
12
	 * @var array
13
	 */
14
	protected $options = array();
15
16
	/**
17
	 * @param array $options
18
	 */
19 3
	public function __construct(array $options = array()) {
20 3
		$this->options = (array)$options;
21 3
	}
22
23
	/**
24
	 * @param $key
25
	 * @return mixed
26
	 */
27
	public function __get($key) {
28
		return $this->options[$key];
29
	}
30
31
	/**
32
	 * @param      $key
33
	 * @param null $default
34
	 * @return null
35
	 */
36 2
	public function getOption($key, $default = null) {
37 2
		return isset($this->options[$key]) ? $this->options[$key] : $default;
38
	}
39
40
	/**
41
	 * @param $key
42
	 * @param $value
43
	 */
44
	public function __set($key, $value) {
45
		$this->options[$key] = $value;
46
	}
47
48
	/**
49
	 * @param $type
50
	 * @return array
51
	 */
52 1
	public function getPluginIds($type) {
53 1
		$pluginsDirs = false;
54
55 1
		$config = code_review::getConfig();
56
57
		switch ($type) {
58 1
			case self::T_PLUGINS_INACTIVE:
59 1
				$pluginsDirs = $this->getPluginIds(self::T_PLUGINS_ALL);
60 1
				$actives = call_user_func($config['plugins_getter'], 'active');
61 1
				foreach ($actives as $plugin) {
62 1
					if ($plugin instanceof ElggPlugin) {
1 ignored issue
show
Bug introduced by
The class ElggPlugin does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
63
						$pluginsDirs = array_diff($pluginsDirs, array($plugin->getID()));
64
					} else {
65 1
						$pluginsDirs = array_diff($pluginsDirs, array($plugin));
66
					}
67 1
				}
68 1
				break;
69 1
			case self::T_PLUGINS_ACTIVE:
70
				$pluginsDirs = call_user_func($config['plugins_getter'], 'active');
71
				foreach ($pluginsDirs as $key => $plugin) {
72
					if ($plugin instanceof ElggPlugin) {
1 ignored issue
show
Bug introduced by
The class ElggPlugin does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
73
						$pluginsDirs[$key] = $plugin->getID();
74
					}
75
				}
76
				break;
77 1
			case self::T_PLUGINS_ALL:
78 1
				$pluginsDirs = code_review::getPluginDirsInDir($config['pluginspath']);
79 1
				break;
80
81
		}
82 1
		return $pluginsDirs;
83
	}
84
85
	/*
86
	 * Shorthand methods
87
	 */
88
89
	/**
90
	 * @param array $vars
91
	 */
92
	public function parseInput(array $vars) {
93
94
		//sanitize provided path
95
		$subPath = elgg_extract('subpath', $vars, '/');
96
		$subPath = trim($subPath, '/\\');
97
		$subPath = str_replace('\\', '/', $subPath);
98
		$subPath = str_replace('..', '', $subPath);
99
		$subPath = $subPath . '/';
100
101
		$this->subPath = $subPath;
0 ignored issues
show
Documentation introduced by
The property subPath does not exist on object<CodeReviewConfig>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
102
		$this->maxVersion = elgg_extract('version', $vars);
0 ignored issues
show
Documentation introduced by
The property maxVersion does not exist on object<CodeReviewConfig>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
103
		$this->includeDisabledPlugins = elgg_extract('include_disabled_plugins', $vars, false);
0 ignored issues
show
Documentation introduced by
The property includeDisabledPlugins does not exist on object<CodeReviewConfig>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
104
		$this->findDeprecatedFunctions = elgg_extract('find_deprecated_functions', $vars, true);
0 ignored issues
show
Documentation introduced by
The property findDeprecatedFunctions does not exist on object<CodeReviewConfig>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
105
		$this->findPrivateFunctions = elgg_extract('find_private_functions', $vars, true);
0 ignored issues
show
Documentation introduced by
The property findPrivateFunctions does not exist on object<CodeReviewConfig>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
106
		$this->fixProblems = elgg_extract('fix_problems', $vars);
0 ignored issues
show
Documentation introduced by
The property fixProblems does not exist on object<CodeReviewConfig>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
107
	}
108
109
	/**
110
	 * @return bool
111
	 */
112
	public function isFixProblemsEnabled() {
113
		return (bool)$this->getOption('fixProblems', false);
114
	}
115
116
	/**
117
	 * @return string
118
	 */
119
	public function getMaxVersion() {
120
		if (!$this->maxVersion) {
0 ignored issues
show
Documentation introduced by
The property maxVersion does not exist on object<CodeReviewConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
121
			//TODO decouple Elgg core dependency
122
			return elgg_get_version(true);
123
		}
124
		return $this->maxVersion;
0 ignored issues
show
Documentation introduced by
The property maxVersion does not exist on object<CodeReviewConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
125
	}
126
127
	/**
128
	 * @return string
129
	 */
130
	public function getSubPath() {
131
		return (string)$this->subPath;
0 ignored issues
show
Documentation introduced by
The property subPath does not exist on object<CodeReviewConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
132
	}
133
134
	/**
135
	 * @return bool
136
	 */
137 2
	public function isIncludeDisabledPluginsEnabled() {
138 2
		return (bool)$this->getOption('includeDisabledPlugins', false);
139
	}
140
141
	/**
142
	 * @return bool
143
	 */
144 2
	public function isSkipInactivePluginsEnabled() {
145 2
		return !$this->isIncludeDisabledPluginsEnabled();
146
	}
147
148
	/**
149
	 * @return bool
150
	 */
151
	public function isDeprecatedFunctionsTestEnabled() {
152
		return (bool)$this->getOption('findDeprecatedFunctions', true);
153
	}
154
155
	/**
156
	 * @return bool
157
	 */
158
	public function isPrivateFunctionsTestEnabled() {
159
		return (bool)$this->getOption('findPrivateFunctions', true);
160
	}
161
}