Config   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 8
Bugs 3 Features 2
Metric Value
c 8
b 3
f 2
dl 0
loc 118
rs 10
wmc 11
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 7 1
B setup() 0 27 6
A getConfig() 0 4 1
A getAlias() 0 4 1
A getEntities() 0 4 1
1
<?php namespace Algorit\Synchronizer\Request;
2
3
use Exception;
4
use Illuminate\Filesystem\Filesystem;
5
use Algorit\Synchronizer\Request\Contracts\SystemInterface;
6
7
class Config {
8
	
9
	/**
10
	 * The config array.
11
	 *
12
	 * @var array
13
	 */
14
	public $config;
15
16
	/**
17
	 * The aliases array.
18
	 *
19
	 * @var array
20
	 */
21
	public $aliases;
22
23
	/**
24
	 * The date config.
25
	 *
26
	 * @var array
27
	 */
28
	public $date;
29
30
	/**
31
	 * The resource instance name.
32
	 *
33
	 * @var array
34
	 */
35
	public $resourceInstance;
36
37
	/**
38
	 * The entities config.
39
	 *
40
	 * @var array
41
	 */
42
	protected $entities;
43
44
	/**
45
	 * The filesystem instance.
46
	 *
47
	 * @var \Illuminate\Filesystem\Filesystem
48
	 */
49
	protected $files;
50
51
	/**
52
	 * Create a new instance.
53
	 *
54
	 * @param  \Illuminate\Filesystem\Filesystem  $files
55
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
56
	 */
57
	public function __construct(Filesystem $files)
58
	{
59
		$this->files = $files;
60
	}
61
62
	protected function load($path)
63
	{
64
		$this->config  = $this->files->getRequire($path . '/config.php');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->files->getRequire($path . '/config.php') of type * is incompatible with the declared type array of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
65
		$this->aliases = $this->files->getRequire($path . '/aliases.php');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->files->getRequire($path . '/aliases.php') of type * is incompatible with the declared type array of property $aliases.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
66
67
		return $this;
68
	}
69
70
	/**
71
	 * Setup the configuration.
72
	 *
73
	 * @param  \Algorit\Synchronizer\Request\Contracts\SystemInterface $system
74
	 * @return \Algorit\Synchronizer\Request\Config
75
	 */
76
	public function setup(SystemInterface $system, $resource)
77
	{
78
		$path = $system->path . '/Config';
0 ignored issues
show
Bug introduced by
Accessing path on the interface Algorit\Synchronizer\Req...ntracts\SystemInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
79
80
		if(isset($resource->slug))
81
		{
82
			$path = $system->path . '/Config/' . $resource->slug;
0 ignored issues
show
Bug introduced by
Accessing path on the interface Algorit\Synchronizer\Req...ntracts\SystemInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
83
		}
84
85
		$this->load($path);
86
87
		if( ! is_array($this->config))
88
		{
89
			throw new Exception('Config files not found.');
90
		}
91
92
		$this->date = array_get($this->config, 'date');
0 ignored issues
show
Documentation Bug introduced by
It seems like array_get($this->config, 'date') of type * is incompatible with the declared type array of property $date.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
93
		$this->entities = array_get($this->config, 'entities');
0 ignored issues
show
Documentation Bug introduced by
It seems like array_get($this->config, 'entities') of type * is incompatible with the declared type array of property $entities.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
94
		$this->resourceInstance = array_get($this->config, 'resourceInstance');
0 ignored issues
show
Documentation Bug introduced by
It seems like array_get($this->config, 'resourceInstance') of type * is incompatible with the declared type array of property $resourceInstance.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
95
96
		if($this->aliases == null or $this->entities == null or $this->date == null)
97
		{
98
			throw new Exception('Wrong file format.');
99
		}
100
101
		return $this;
102
	}
103
104
	public function getConfig()
105
	{
106
		return $this->config;
107
	}
108
109
	public function getAlias($name)
110
	{
111
		return $this->aliases[$name];
112
	}
113
114
	/**
115
	 * Get the entities.
116
	 *
117
	 * @param  void
118
	 * @return array
119
	 */	
120
	public function getEntities()
121
	{
122
		return $this->entities;
123
	}
124
}