GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ConfigurationManager::parseConfigurationFile()   B
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 6.0061

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
ccs 17
cts 18
cp 0.9444
rs 8.5906
cc 6
eloc 13
nc 10
nop 1
crap 6.0061
1
<?php
2
3
namespace PhpAbac\Manager;
4
5
use PhpAbac\Loader\AbacLoader;
6
use PhpAbac\Loader\JsonAbacLoader;
7
use PhpAbac\Loader\YamlAbacLoader;
8
9
use Symfony\Component\Config\FileLocatorInterface;
10
11
class ConfigurationManager {
12
	/** @var FileLocatorInterface * */
13
	protected $locator;
14
	/** @var AbacLoader[] * */
15
	protected $loaders;
16
	/** @var array * */
17
	protected $rules;
18
	/** @var array * */
19
	protected $attributes;
20
	
21
//	protected $config_path_route;
22
	
23
	/** @var array List of File Already Loader */
24
	protected $config_files_loaded;
25
	
26
	/**
27
	 * @param FileLocatorInterface $locator
28
	 * @param string|array         $format A format or an array of format
29
	 */
30 12
	public function __construct( FileLocatorInterface $locator, $format = [
31
		'yaml',
32
		'json',
33
	] ) {
34 12
		$this->locator             = $locator;
35 12
		$this->attributes          = [];
36 12
		$this->rules               = [];
37 12
		$this->config_files_loaded = [];
38 12
		if ( in_array( 'yaml', $format ) ) {
39 12
			$this->loaders[ 'yaml' ] = new YamlAbacLoader( $locator, $this );
0 ignored issues
show
Unused Code introduced by
The call to YamlAbacLoader::__construct() has too many arguments starting with $this.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
40 12
		}
41 12
		if ( in_array( 'json', $format ) ) {
42 12
			$this->loaders[ 'json' ] = new JsonAbacLoader( $locator, $this );
0 ignored issues
show
Unused Code introduced by
The call to JsonAbacLoader::__construct() has too many arguments starting with $this.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
43 12
		}
44
		
45 12
	}
46
	
47 4
	public function setConfigPathRoot($configPaths_root = null) {
48
//		$this->config_path_route = $configPaths_root;
49 4
		foreach($this->loaders as $loader) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FOREACH keyword; 0 found
Loading history...
50 4
			$loader->setCurrentDir($configPaths_root);
51 4
		}
52 4
	}
53
		
54
	/**
55
	 * @param array $configurationFiles
56
	 */
57 12
	public function parseConfigurationFile( $configurationFiles ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between opening bracket and argument "$configurationFiles"; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces between argument "$configurationFiles" and closing bracket; 1 found
Loading history...
58 12
		foreach ( $configurationFiles as $configurationFile ) {
0 ignored issues
show
Coding Style introduced by
Space found after opening bracket of FOREACH loop
Loading history...
Coding Style introduced by
Space found before closing bracket of FOREACH loop
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
59 12
			$config = $this->getLoader( $configurationFile )->import( $configurationFile, pathinfo( $configurationFile, PATHINFO_EXTENSION ) );
60
			
61 12
			if (in_array($config['path'],$this->config_files_loaded)) {
62
				continue;
63
			}
64
			
65 12
			$this->config_files_loaded[] = $config['path'];
66
			
67 12
			if (isset($config['@import'])) {
68 4
				$this->parseConfigurationFile($config['@import']);
69 4
				unset($config['@import']);
70 4
			}
71
			
72 12
			if ( isset( $config[ 'attributes' ] ) ) {
73 12
				$this->attributes = array_merge( $this->attributes, $config[ 'attributes' ] );
74 12
			}
75 12
			if ( isset( $config[ 'rules' ] ) ) {
76 12
				$this->rules = array_merge( $this->rules, $config[ 'rules' ] );
77 12
			}
78 12
		}
79 12
	}
80
	
81
	
82
	
83
	/**
84
	 * Function to retrieve the good loader for the configuration file
85
	 *
86
	 * @param $configurationFile
87
	 *
88
	 * @return AbacLoader
89
	 *
90
	 * @throws \Exception
91
	 */
92 12
	private function getLoader( $configurationFile ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between opening bracket and argument "$configurationFile"; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces between argument "$configurationFile" and closing bracket; 1 found
Loading history...
93
		
94 12
		foreach ( $this->loaders as $AbacLoader ) {
0 ignored issues
show
Coding Style introduced by
Space found after opening bracket of FOREACH loop
Loading history...
Coding Style introduced by
Space found before closing bracket of FOREACH loop
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
95 12
			if ( $AbacLoader::supportsExtension( $configurationFile ) ) {
96 12
				return $AbacLoader;
97
			}
98 4
		}
99
		throw new \Exception( 'Loader not found for the file ' . $configurationFile );
100
	}
101
	
102
	/**
103
	 * @return array
104
	 */
105 12
	public function getAttributes() {
106 12
		return $this->attributes;
107
	}
108
	
109
	/**
110
	 * @return array
111
	 */
112 6
	public function getRules() {
113 6
		return $this->rules;
114
	}
115
}