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.
Passed
Pull Request — master (#2899)
by
unknown
03:18
created

Configuration::toJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * @package core
5
 */
6
7
 /**
8
  * The Configuration class acts as a property => value store for settings
9
  * used throughout Symphony. The result of this class is a string containing
10
  * a PHP representation of the properties (and their values) set by the Configuration.
11
  * Symphony's configuration file is saved at `CONFIG`. The initial
12
  * file is generated by the Symphony installer, and then subsequent use of Symphony
13
  * loads in this file for each page view. Like minded properties can be grouped.
14
  */
15
class Configuration
16
{
17
    /**
18
     * An associative array of the properties for this Configuration object
19
     * @var array
20
     */
21
    private $_properties = array();
22
23
    /**
24
     * Whether all properties and group keys will be forced to be lowercase.
25
     * By default this is false, which makes all properties case sensitive
26
     * @var boolean
27
     */
28
    private $_forceLowerCase = false;
29
30
    /**
31
     * The string representing the tab characters used to serialize the configuration
32
     * @var string
33
     */
34
    const TAB = '    ';
35
36
    /**
37
     * The constructor for the Configuration class takes one parameter,
38
     * `$forceLowerCase` which will make all property and
39
     * group names lowercase or not. By default they are left to the case
40
     * the user provides
41
     *
42
     * @param boolean $forceLowerCase
43
     *  False by default, if true this will make all property and group names
44
     *  lowercase
45
     */
46
    public function __construct($forceLowerCase = false)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$forceLowerCase" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$forceLowerCase"; expected 0 but found 1
Loading history...
47
    {
48
        $this->_forceLowerCase = $forceLowerCase;
49
    }
50
51
    /**
52
     * Setter for the `$this->_properties`. The properties array
53
     * can be grouped to be an 'array' of an 'array' of properties. For instance
54
     * a 'region' key may be an array of 'properties' (that is name/value), or it
55
     * may be a 'value' itself.
56
     *
57
     * @param string $name
58
     *  The name of the property to set, eg 'timezone'
59
     * @param array|string|integer|float|boolean $value
60
     *  The value for the property to set, eg. '+10:00'
61
     * @param string $group
62
     *  The group for this property, eg. 'region'
63
     */
64
    public function set($name, $value, $group = null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$group" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$group"; expected 0 but found 1
Loading history...
65
    {
66
        if ($this->_forceLowerCase) {
67
            $name = strtolower($name);
68
            $group = strtolower($group);
69
        }
70
71
        if ($group) {
72
            $this->_properties[$group][$name] = $value;
73
        } else {
74
            $this->_properties[$name] = $value;
75
        }
76
    }
77
78
    /**
79
     * A quick way to set a large number of properties. Given an associative
80
     * array or a nested associative array (where the key will be the group),
81
     * this function will merge the `$array` with the existing configuration.
82
     * By default the given `$array` will overwrite any existing keys unless
83
     * the `$overwrite` parameter is passed as false.
84
     *
85
     * @since Symphony 2.3.2 The `$overwrite` parameter is available
86
     * @param array $array
87
     *  An associative array of properties, 'property' => 'value' or
88
     *  'group' => array('property' => 'value')
89
     * @param boolean $overwrite
90
     *  An optional boolean parameter to indicate if it is safe to use array_merge
91
     *  or if the provided array should be integrated using the 'set()' method
92
     *  to avoid possible change collision. Defaults to false.
93
     */
94
    public function setArray(array $array, $overwrite = false)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$overwrite" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$overwrite"; expected 0 but found 1
Loading history...
95
    {
96
        if ($overwrite) {
97
            $this->_properties = array_merge($this->_properties, $array);
98
        } else {
99
            foreach ($array as $set => $values) {
100
                foreach ($values as $key => $val) {
101
                    self::set($key, $val, $set);
0 ignored issues
show
Bug Best Practice introduced by
The method Configuration::set() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

101
                    self::/** @scrutinizer ignore-call */ 
102
                          set($key, $val, $set);
Loading history...
102
                }
103
            }
104
        }
105
    }
106
107
    /**
108
     * Accessor function for the `$this->_properties`.
109
     *
110
     * @param string $name
111
     *  The name of the property to retrieve
112
     * @param string $group
113
     *  The group that this property will be in
114
     * @return array|string|integer|float|boolean
115
     *  If `$name` or `$group` are not
116
     *  provided this function will return the full `$this->_properties`
117
     *  array.
118
     */
119
    public function get($name = null, $group = null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$name" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$name"; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$group" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$group"; expected 0 but found 1
Loading history...
120
    {
121
122
        // Return the whole array if no name or index is requested
123
        if (!$name && !$group) {
124
            return $this->_properties;
125
        }
126
127
        if ($this->_forceLowerCase) {
128
            $name = strtolower($name);
129
            $group = strtolower($group);
130
        }
131
132
        if ($group) {
133
            return (isset($this->_properties[$group][$name]) ? $this->_properties[$group][$name] : null);
134
        }
135
136
        return (isset($this->_properties[$name]) ? $this->_properties[$name] : null);
137
    }
138
139
    /**
140
     * The remove function will unset a property by `$name`.
141
     * It is possible to remove an entire 'group' by passing the group
142
     * name as the `$name`
143
     *
144
     * @param string $name
145
     *  The name of the property to unset. This can also be the group name
146
     * @param string $group
147
     *  The group of the property to unset
148
     */
149
    public function remove($name, $group = null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$group" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$group"; expected 0 but found 1
Loading history...
150
    {
151
        if ($this->_forceLowerCase) {
152
            $name = strtolower($name);
153
            $group = strtolower($group);
154
        }
155
156
        if ($group && isset($this->_properties[$group][$name])) {
157
            unset($this->_properties[$group][$name]);
158
        } elseif ($this->_properties[$name]) {
159
            unset($this->_properties[$name]);
160
        }
161
    }
162
163
    /**
164
     * Empties all the Configuration values by setting `$this->_properties`
165
     * to an empty array
166
     */
167
    public function flush()
168
    {
169
        $this->_properties = array();
170
    }
171
172
    /**
173
     * This magic `__toString` function converts the internal `$this->_properties`
174
     * array into a string representation. Symphony generates the `MANIFEST/config.php`
175
     * file in this manner.
176
     * @see Configuration::serializeArray()
177
     * @return string
178
     *  A string that contains a array representation of `$this->_properties`.
179
     *  This is used by Symphony to write the `config.php` file.
180
     */
181
    public function __toString()
182
    {
183
        return $this->toJson();
184
    }
185
186
    /**
187
     * Converts all properties into a JSON string
188
     * @return string json representation of configuration properties
189
     */
190
    public function toJson(): string {
191
        return json_encode($this->_properties, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
192
    }
193
194
    /**
195
     * Function will write the current Configuration object to
196
     * a specified `$file` with the given `$permissions`.
197
     *
198
     * @param string $file
199
     *  the path of the file to write.
200
     * @param integer|null $permissions (optional)
201
     *  the permissions as an octal number to set set on the resulting file.
202
     *  If this is not provided it will use the permissions defined in [`write_mode`][`file`]
203
     * @return boolean
204
     */
205
    public function write(string $file = null, int $permissions = null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$file" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$file"; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$permissions" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$permissions"; expected 0 but found 1
Loading history...
206
    {
207
        $file = $file ?? CONFIG;
0 ignored issues
show
Bug introduced by
The constant CONFIG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
208
209
        if (null == $permissions && isset($this->_properties['file']['write_mode'])) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $permissions of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison === instead.
Loading history...
210
            $permissions = $this->_properties['file']['write_mode'];
211
        }
212
213
        return General::writeFile($file, (string)$this, $permissions);
214
    }
215
}
216