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.
Completed
Push — master ( 17ed34...f4bd34 )
by Omar El
03:18
created

Config::loadJsConfig()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 10
Ratio 76.92 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 13
rs 9.4285
cc 3
eloc 6
nc 3
nop 0
1
<?php
2
3
/**
4
 * Config class.
5
 * Gets a configuration value
6
 *
7
 * @license    http://opensource.org/licenses/MIT The MIT License (MIT)
8
 * @author     Omar El Gabry <[email protected]>
9
 */
10
11
class Config{
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...
12
13
    /**
14
     * Array of configurations
15
     *
16
     * @var array
17
     */
18
    public static $config = null;
19
20
    /**
21
     * Array of javascript configurations
22
     *
23
     * @var array
24
     */
25
    public static $jsConfig = null;
26
27
    /**
28
     * Gets a configuration value
29
     *
30
     * @param $key string
31
     * @return string|null
32
     * @throws Exception if configuration file doesn't exist
33
     */
34
    public static function get($key){
35
36 View Code Duplication
        if (!self::$config) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::$config of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
38
	        $config_file = APP . 'config/config.php';
39
40
			if (!file_exists($config_file)) {
41
				throw new Exception("Configuration file doesn't exist");
42
			}
43
44
	        self::$config = require $config_file . "";
45
        }
46
47
        return isset(self::$config[$key])? self::$config[$key]: null;
48
    }
49
50
    /**
51
     * Loads javascript configurations
52
     *
53
     * @param $key string
54
     * @return string|null
55
     * @throws Exception if configuration file doesn't exist
56
     */
57
    private static function loadJsConfig(){
58
59 View Code Duplication
        if (!self::$jsConfig) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::$jsConfig of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
61
            $config_file = APP . 'config/javascript.php';
62
63
            if (!file_exists($config_file)) {
64
                throw new Exception("JavaScript Configuration file doesn't exist");
65
            }
66
67
            self::$jsConfig = require $config_file . "";
68
        }
69
    }
70
71
    /**
72
     * Gets javascript configuration value(s)
73
     *
74
     * @param $key string
75
     * @return string|array|null
76
     * @throws Exception if configuration file doesn't exist
77
     */
78
    public static function getJsConfig($key = ""){
79
        
80
        if (!self::$jsConfig) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::$jsConfig of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
81
            self::loadJsConfig();
82
        }
83
84
        if(empty($key)){
85
            return self::$jsConfig;
86
        }else if(isset(self::$jsConfig[$key])){
87
            return self::$jsConfig[$key];
88
        }
89
        return null;
90
    }
91
92
    /**
93
     * Adds a new variable to javascript configurations
94
     *
95
     * @param string $key
96
     * @param mixed  $value
97
     */
98
    public static function addJsConfig($key, $value){
99
        if (!self::$jsConfig) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::$jsConfig of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
100
            self::loadJsConfig();
101
        }
102
        self::$jsConfig[$key] = $value;
103
    }
104
}
105