Passed
Branch master (59633e)
by Alain
02:02
created
src/SemanticVersion.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      *
196 196
      * @since 0.1.0
197 197
      *
198
-     * @return int The patch version that is used. '' if not defined.
198
+     * @return string The patch version that is used. '' if not defined.
199 199
      */
200 200
     public function getPreRelease()
201 201
     {
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
      *
208 208
      * @since 0.1.0
209 209
      *
210
-     * @return int The build metadata for the version that is used. '' if not
210
+     * @return string The build metadata for the version that is used. '' if not
211 211
      *             defined.
212 212
      */
213 213
     public function getBuild()
Please login to merge, or discard this patch.
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * SemanticVersion Class
4
- *
5
- * @package   phpfeature
6
- * @author    Alain Schlesser <[email protected]>
7
- * @license   GPL-2.0+
8
- * @link      http://www.brightnucleus.com/
9
- * @copyright 2016 Alain Schlesser, Bright Nucleus
10
- */
3
+	 * SemanticVersion Class
4
+	 *
5
+	 * @package   phpfeature
6
+	 * @author    Alain Schlesser <[email protected]>
7
+	 * @license   GPL-2.0+
8
+	 * @link      http://www.brightnucleus.com/
9
+	 * @copyright 2016 Alain Schlesser, Bright Nucleus
10
+	 */
11 11
 
12 12
 /**
13 13
  * Class SemanticVersion
@@ -19,241 +19,241 @@  discard block
 block discarded – undo
19 19
 class SemanticVersion
20 20
 {
21 21
 
22
-    /**
23
-     * RegEx pattern that matches the different version components.
24
-     *
25
-     * @since 0.1.0
26
-     *
27
-     * @var string
28
-     */
29
-    const VERSION_PATTERN = '/^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z-]*))?(?:\+([0-9A-Za-z-]*))?$/';
22
+	/**
23
+	 * RegEx pattern that matches the different version components.
24
+	 *
25
+	 * @since 0.1.0
26
+	 *
27
+	 * @var string
28
+	 */
29
+	const VERSION_PATTERN = '/^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z-]*))?(?:\+([0-9A-Za-z-]*))?$/';
30 30
 
31
-    /**
32
-     * Version that is used.
33
-     *
34
-     * @since 0.1.0
35
-     *
36
-     * @var string
37
-     */
38
-    protected $version;
31
+	/**
32
+	 * Version that is used.
33
+	 *
34
+	 * @since 0.1.0
35
+	 *
36
+	 * @var string
37
+	 */
38
+	protected $version;
39 39
 
40
-    /**
41
-     * Different components of the version that is used.
42
-     *
43
-     * @since 0.1.0
44
-     *
45
-     * @var array
46
-     */
47
-    protected $components;
40
+	/**
41
+	 * Different components of the version that is used.
42
+	 *
43
+	 * @since 0.1.0
44
+	 *
45
+	 * @var array
46
+	 */
47
+	protected $components;
48 48
 
49
-    /**
50
-     * Instantiate a Version object.
51
-     *
52
-     * @since 0.1.0
53
-     *
54
-     * @param string|null $version Optional. The version to use. Defaults to
55
-     *                             the current PHP interpreter's version.
56
-     * @param bool        $partial Optional. Whether to accept a partial
57
-     *                             version number. If true, the missing
58
-     *                             components will default to `0` instead of
59
-     *                             throwing an exception.
60
-     * @throws RuntimeException When the version fails to validate.
61
-     */
62
-    public function __construct($version = null, $partial = false)
63
-    {
49
+	/**
50
+	 * Instantiate a Version object.
51
+	 *
52
+	 * @since 0.1.0
53
+	 *
54
+	 * @param string|null $version Optional. The version to use. Defaults to
55
+	 *                             the current PHP interpreter's version.
56
+	 * @param bool        $partial Optional. Whether to accept a partial
57
+	 *                             version number. If true, the missing
58
+	 *                             components will default to `0` instead of
59
+	 *                             throwing an exception.
60
+	 * @throws RuntimeException When the version fails to validate.
61
+	 */
62
+	public function __construct($version = null, $partial = false)
63
+	{
64 64
 
65
-        if ( ! $version) {
66
-            $version = '0.0.0';
67
-        }
65
+		if ( ! $version) {
66
+			$version = '0.0.0';
67
+		}
68 68
 
69
-        $version = $this->validate($version, $partial);
69
+		$version = $this->validate($version, $partial);
70 70
 
71
-        $this->version = $version;
72
-    }
71
+		$this->version = $version;
72
+	}
73 73
 
74
-    /**
75
-     * Validate the version and assert it is in SemVer format.
76
-     *
77
-     * @since 0.1.0
78
-     *
79
-     * @param string $version The version to validate.
80
-     * @param bool   $partial Optional. Whether to accept a partial version
81
-     *                        number. If true, the missing components will
82
-     *                        default to `0` instead of throwing an exception.
83
-     * @return string
84
-     * @throws RuntimeException When the version fails to validate.
85
-     */
86
-    protected function validate($version, $partial = false)
87
-    {
74
+	/**
75
+	 * Validate the version and assert it is in SemVer format.
76
+	 *
77
+	 * @since 0.1.0
78
+	 *
79
+	 * @param string $version The version to validate.
80
+	 * @param bool   $partial Optional. Whether to accept a partial version
81
+	 *                        number. If true, the missing components will
82
+	 *                        default to `0` instead of throwing an exception.
83
+	 * @return string
84
+	 * @throws RuntimeException When the version fails to validate.
85
+	 */
86
+	protected function validate($version, $partial = false)
87
+	{
88 88
 
89
-        $version = trim($version);
90
-        $pattern = self::VERSION_PATTERN;
89
+		$version = trim($version);
90
+		$pattern = self::VERSION_PATTERN;
91 91
 
92
-        $components = array();
93
-        $result     = preg_match($pattern, $version, $components);
92
+		$components = array();
93
+		$result     = preg_match($pattern, $version, $components);
94 94
 
95
-        if ( ! $result) {
96
-            throw new RuntimeException(sprintf(
97
-                'Failed to validate version "%1$s".',
98
-                (string)$version
99
-            ));
100
-        }
95
+		if ( ! $result) {
96
+			throw new RuntimeException(sprintf(
97
+				'Failed to validate version "%1$s".',
98
+				(string)$version
99
+			));
100
+		}
101 101
 
102
-        if ( ! $partial && ( ! isset($components[2]) || ! isset($components[3]))) {
103
-            throw new RuntimeException(sprintf(
104
-                'Could not accept partial version "%1$s", requested full versions only.',
105
-                (string)$version
106
-            ));
107
-        }
102
+		if ( ! $partial && ( ! isset($components[2]) || ! isset($components[3]))) {
103
+			throw new RuntimeException(sprintf(
104
+				'Could not accept partial version "%1$s", requested full versions only.',
105
+				(string)$version
106
+			));
107
+		}
108 108
 
109
-        $this->setComponent('major', isset($components[1]) ? (int)$components[1] : 0);
110
-        $this->setComponent('minor', isset($components[2]) ? (int)$components[2] : 0);
111
-        $this->setComponent('patch', isset($components[3]) ? (int)$components[3] : 0);
112
-        $this->setComponent('pre-release', isset($components[4]) ? (string)$components[4] : '');
113
-        $this->setComponent('build', isset($components[5]) ? (string)$components[5] : '');
109
+		$this->setComponent('major', isset($components[1]) ? (int)$components[1] : 0);
110
+		$this->setComponent('minor', isset($components[2]) ? (int)$components[2] : 0);
111
+		$this->setComponent('patch', isset($components[3]) ? (int)$components[3] : 0);
112
+		$this->setComponent('pre-release', isset($components[4]) ? (string)$components[4] : '');
113
+		$this->setComponent('build', isset($components[5]) ? (string)$components[5] : '');
114 114
 
115
-        $version = $this->getVersionFromComponents();
115
+		$version = $this->getVersionFromComponents();
116 116
 
117
-        return $version;
118
-    }
117
+		return $version;
118
+	}
119 119
 
120
-    /**
121
-     * Get the version that is used.
122
-     *
123
-     * @since 0.1.0
124
-     *
125
-     * @return string The version that is used. '0.0.0' if not defined.
126
-     */
127
-    public function getVersion()
128
-    {
129
-        return (string)isset($this->version) ? $this->version : '0.0.0';
130
-    }
120
+	/**
121
+	 * Get the version that is used.
122
+	 *
123
+	 * @since 0.1.0
124
+	 *
125
+	 * @return string The version that is used. '0.0.0' if not defined.
126
+	 */
127
+	public function getVersion()
128
+	{
129
+		return (string)isset($this->version) ? $this->version : '0.0.0';
130
+	}
131 131
 
132
-    /**
133
-     * Build and return a versin from the separated components.
134
-     *
135
-     * @since 0.1.0
136
-     *
137
-     * @return string
138
-     */
139
-    protected function getVersionFromComponents()
140
-    {
132
+	/**
133
+	 * Build and return a versin from the separated components.
134
+	 *
135
+	 * @since 0.1.0
136
+	 *
137
+	 * @return string
138
+	 */
139
+	protected function getVersionFromComponents()
140
+	{
141 141
 
142
-        $pre_release = $this->getPreRelease() ? '-' . $this->getPreRelease() : '';
143
-        $build       = $this->getBuild() ? '+' . $this->getBuild() : '';
142
+		$pre_release = $this->getPreRelease() ? '-' . $this->getPreRelease() : '';
143
+		$build       = $this->getBuild() ? '+' . $this->getBuild() : '';
144 144
 
145
-        $version = sprintf(
146
-            '%1$s.%2$s.%3$s%4$s%5$s',
147
-            $this->getMajor(),
148
-            $this->getMinor(),
149
-            $this->getPatch(),
150
-            $pre_release,
151
-            $build
152
-        );
145
+		$version = sprintf(
146
+			'%1$s.%2$s.%3$s%4$s%5$s',
147
+			$this->getMajor(),
148
+			$this->getMinor(),
149
+			$this->getPatch(),
150
+			$pre_release,
151
+			$build
152
+		);
153 153
 
154
-        return $version;
155
-    }
154
+		return $version;
155
+	}
156 156
 
157
-    /**
158
-     * Get the major version number.
159
-     *
160
-     * @since 0.1.0
161
-     *
162
-     * @return int The major version that is used. 0 if not defined.
163
-     */
164
-    public function getMajor()
165
-    {
166
-        return (int)$this->getComponent('major') ?: 0;
167
-    }
157
+	/**
158
+	 * Get the major version number.
159
+	 *
160
+	 * @since 0.1.0
161
+	 *
162
+	 * @return int The major version that is used. 0 if not defined.
163
+	 */
164
+	public function getMajor()
165
+	{
166
+		return (int)$this->getComponent('major') ?: 0;
167
+	}
168 168
 
169
-    /**
170
-     * Get the minor version number.
171
-     *
172
-     * @since 0.1.0
173
-     *
174
-     * @return int The minor version that is used. 0 if not defined.
175
-     */
176
-    public function getMinor()
177
-    {
178
-        return (int)$this->getComponent('minor') ?: 0;
179
-    }
169
+	/**
170
+	 * Get the minor version number.
171
+	 *
172
+	 * @since 0.1.0
173
+	 *
174
+	 * @return int The minor version that is used. 0 if not defined.
175
+	 */
176
+	public function getMinor()
177
+	{
178
+		return (int)$this->getComponent('minor') ?: 0;
179
+	}
180 180
 
181
-    /**
182
-     * Get the patch version number.
183
-     *
184
-     * @since 0.1.0
185
-     *
186
-     * @return int The patch version that is used. 0 if not defined.
187
-     */
188
-    public function getPatch()
189
-    {
190
-        return (int)$this->getComponent('patch') ?: 0;
191
-    }
181
+	/**
182
+	 * Get the patch version number.
183
+	 *
184
+	 * @since 0.1.0
185
+	 *
186
+	 * @return int The patch version that is used. 0 if not defined.
187
+	 */
188
+	public function getPatch()
189
+	{
190
+		return (int)$this->getComponent('patch') ?: 0;
191
+	}
192 192
 
193
-    /**
194
-     * Get the pre-release label.
195
-     *
196
-     * @since 0.1.0
197
-     *
198
-     * @return int The patch version that is used. '' if not defined.
199
-     */
200
-    public function getPreRelease()
201
-    {
202
-        return (string)$this->getComponent('pre-release') ?: '';
203
-    }
193
+	/**
194
+	 * Get the pre-release label.
195
+	 *
196
+	 * @since 0.1.0
197
+	 *
198
+	 * @return int The patch version that is used. '' if not defined.
199
+	 */
200
+	public function getPreRelease()
201
+	{
202
+		return (string)$this->getComponent('pre-release') ?: '';
203
+	}
204 204
 
205
-    /**
206
-     * Get the build metadata.
207
-     *
208
-     * @since 0.1.0
209
-     *
210
-     * @return int The build metadata for the version that is used. '' if not
211
-     *             defined.
212
-     */
213
-    public function getBuild()
214
-    {
215
-        return (string)$this->getComponent('build') ?: '';
216
-    }
205
+	/**
206
+	 * Get the build metadata.
207
+	 *
208
+	 * @since 0.1.0
209
+	 *
210
+	 * @return int The build metadata for the version that is used. '' if not
211
+	 *             defined.
212
+	 */
213
+	public function getBuild()
214
+	{
215
+		return (string)$this->getComponent('build') ?: '';
216
+	}
217 217
 
218
-    /**
219
-     * Get a component of the version.
220
-     *
221
-     * @since 0.1.0
222
-     *
223
-     * @param string $level What level of component to get. Possible values:
224
-     *                      'major', 'minor', 'patch'
225
-     * @return int The requested version component. null if not defined.
226
-     */
227
-    protected function getComponent($level)
228
-    {
229
-        return array_key_exists($level, $this->components)
230
-            ? $this->components[$level]
231
-            : null;
232
-    }
218
+	/**
219
+	 * Get a component of the version.
220
+	 *
221
+	 * @since 0.1.0
222
+	 *
223
+	 * @param string $level What level of component to get. Possible values:
224
+	 *                      'major', 'minor', 'patch'
225
+	 * @return int The requested version component. null if not defined.
226
+	 */
227
+	protected function getComponent($level)
228
+	{
229
+		return array_key_exists($level, $this->components)
230
+			? $this->components[$level]
231
+			: null;
232
+	}
233 233
 
234
-    /**
235
-     * Set a component of the version.
236
-     *
237
-     * @since 0.1.0
238
-     *
239
-     * @param string $level   What level of component to set. Possible values:
240
-     *                        'major', 'minor', 'patch'
241
-     * @param int    $version What version to set that component to.
242
-     */
243
-    protected function setComponent($level, $version)
244
-    {
245
-        $this->components[$level] = $version;
246
-    }
234
+	/**
235
+	 * Set a component of the version.
236
+	 *
237
+	 * @since 0.1.0
238
+	 *
239
+	 * @param string $level   What level of component to set. Possible values:
240
+	 *                        'major', 'minor', 'patch'
241
+	 * @param int    $version What version to set that component to.
242
+	 */
243
+	protected function setComponent($level, $version)
244
+	{
245
+		$this->components[$level] = $version;
246
+	}
247 247
 
248
-    /**
249
-     * Get a string representation of the object.
250
-     *
251
-     * @since 0.2.0
252
-     *
253
-     * @return string
254
-     */
255
-    public function __toString()
256
-    {
257
-        return (string)$this->getVersion();
258
-    }
248
+	/**
249
+	 * Get a string representation of the object.
250
+	 *
251
+	 * @since 0.2.0
252
+	 *
253
+	 * @return string
254
+	 */
255
+	public function __toString()
256
+	{
257
+		return (string)$this->getVersion();
258
+	}
259 259
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -95,22 +95,22 @@  discard block
 block discarded – undo
95 95
         if ( ! $result) {
96 96
             throw new RuntimeException(sprintf(
97 97
                 'Failed to validate version "%1$s".',
98
-                (string)$version
98
+                (string) $version
99 99
             ));
100 100
         }
101 101
 
102 102
         if ( ! $partial && ( ! isset($components[2]) || ! isset($components[3]))) {
103 103
             throw new RuntimeException(sprintf(
104 104
                 'Could not accept partial version "%1$s", requested full versions only.',
105
-                (string)$version
105
+                (string) $version
106 106
             ));
107 107
         }
108 108
 
109
-        $this->setComponent('major', isset($components[1]) ? (int)$components[1] : 0);
110
-        $this->setComponent('minor', isset($components[2]) ? (int)$components[2] : 0);
111
-        $this->setComponent('patch', isset($components[3]) ? (int)$components[3] : 0);
112
-        $this->setComponent('pre-release', isset($components[4]) ? (string)$components[4] : '');
113
-        $this->setComponent('build', isset($components[5]) ? (string)$components[5] : '');
109
+        $this->setComponent('major', isset($components[1]) ? (int) $components[1] : 0);
110
+        $this->setComponent('minor', isset($components[2]) ? (int) $components[2] : 0);
111
+        $this->setComponent('patch', isset($components[3]) ? (int) $components[3] : 0);
112
+        $this->setComponent('pre-release', isset($components[4]) ? (string) $components[4] : '');
113
+        $this->setComponent('build', isset($components[5]) ? (string) $components[5] : '');
114 114
 
115 115
         $version = $this->getVersionFromComponents();
116 116
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      */
127 127
     public function getVersion()
128 128
     {
129
-        return (string)isset($this->version) ? $this->version : '0.0.0';
129
+        return (string) isset($this->version) ? $this->version : '0.0.0';
130 130
     }
131 131
 
132 132
     /**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
     protected function getVersionFromComponents()
140 140
     {
141 141
 
142
-        $pre_release = $this->getPreRelease() ? '-' . $this->getPreRelease() : '';
143
-        $build       = $this->getBuild() ? '+' . $this->getBuild() : '';
142
+        $pre_release = $this->getPreRelease() ? '-'.$this->getPreRelease() : '';
143
+        $build       = $this->getBuild() ? '+'.$this->getBuild() : '';
144 144
 
145 145
         $version = sprintf(
146 146
             '%1$s.%2$s.%3$s%4$s%5$s',
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      */
164 164
     public function getMajor()
165 165
     {
166
-        return (int)$this->getComponent('major') ?: 0;
166
+        return (int) $this->getComponent('major') ?: 0;
167 167
     }
168 168
 
169 169
     /**
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
      */
176 176
     public function getMinor()
177 177
     {
178
-        return (int)$this->getComponent('minor') ?: 0;
178
+        return (int) $this->getComponent('minor') ?: 0;
179 179
     }
180 180
 
181 181
     /**
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
      */
188 188
     public function getPatch()
189 189
     {
190
-        return (int)$this->getComponent('patch') ?: 0;
190
+        return (int) $this->getComponent('patch') ?: 0;
191 191
     }
192 192
 
193 193
     /**
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     public function getPreRelease()
201 201
     {
202
-        return (string)$this->getComponent('pre-release') ?: '';
202
+        return (string) $this->getComponent('pre-release') ?: '';
203 203
     }
204 204
 
205 205
     /**
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      */
213 213
     public function getBuild()
214 214
     {
215
-        return (string)$this->getComponent('build') ?: '';
215
+        return (string) $this->getComponent('build') ?: '';
216 216
     }
217 217
 
218 218
     /**
@@ -254,6 +254,6 @@  discard block
 block discarded – undo
254 254
      */
255 255
     public function __toString()
256 256
     {
257
-        return (string)$this->getVersion();
257
+        return (string) $this->getVersion();
258 258
     }
259 259
 }
Please login to merge, or discard this patch.
src/Config.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Config Class.
4
- *
5
- * @package   phpfeature
6
- * @author    Alain Schlesser <[email protected]>
7
- * @license   GPL-2.0+
8
- * @link      http://www.brightnucleus.com/
9
- * @copyright 2016 Alain Schlesser, Bright Nucleus
10
- */
3
+	 * Config Class.
4
+	 *
5
+	 * @package   phpfeature
6
+	 * @author    Alain Schlesser <[email protected]>
7
+	 * @license   GPL-2.0+
8
+	 * @link      http://www.brightnucleus.com/
9
+	 * @copyright 2016 Alain Schlesser, Bright Nucleus
10
+	 */
11 11
 
12 12
 /**
13 13
  * Config loader used to load config PHP files as objects.
@@ -19,74 +19,74 @@  discard block
 block discarded – undo
19 19
 class Config extends ArrayObject implements ConfigInterface
20 20
 {
21 21
 
22
-    /**
23
-     * Instantiate the Config object.
24
-     *
25
-     * @since 0.1.0
26
-     *
27
-     * @param  array $config Array with settings.
28
-     */
29
-    public function __construct(array $config)
30
-    {
31
-        // Make sure the config entries can be accessed as properties.
32
-        parent::__construct($config, ArrayObject::ARRAY_AS_PROPS);
33
-    }
22
+	/**
23
+	 * Instantiate the Config object.
24
+	 *
25
+	 * @since 0.1.0
26
+	 *
27
+	 * @param  array $config Array with settings.
28
+	 */
29
+	public function __construct(array $config)
30
+	{
31
+		// Make sure the config entries can be accessed as properties.
32
+		parent::__construct($config, ArrayObject::ARRAY_AS_PROPS);
33
+	}
34 34
 
35
-    /**
36
-     * Magic method that enables the use of normal array_* functions on the
37
-     * Config object.
38
-     *
39
-     * @since  0.1.0
40
-     *
41
-     * @param  string $function  The function that was called on this object.
42
-     * @param  mixed  $arguments The arguments that were used for the function
43
-     *                           call.
44
-     * @return mixed
45
-     * @throws BadMethodCallException
46
-     */
47
-    public function __call($function, $arguments)
48
-    {
49
-        if ( ! is_callable($function) || substr($function, 0, 6) !== 'array_') {
50
-            throw new BadMethodCallException(__CLASS__ . '->' . $function);
51
-        }
35
+	/**
36
+	 * Magic method that enables the use of normal array_* functions on the
37
+	 * Config object.
38
+	 *
39
+	 * @since  0.1.0
40
+	 *
41
+	 * @param  string $function  The function that was called on this object.
42
+	 * @param  mixed  $arguments The arguments that were used for the function
43
+	 *                           call.
44
+	 * @return mixed
45
+	 * @throws BadMethodCallException
46
+	 */
47
+	public function __call($function, $arguments)
48
+	{
49
+		if ( ! is_callable($function) || substr($function, 0, 6) !== 'array_') {
50
+			throw new BadMethodCallException(__CLASS__ . '->' . $function);
51
+		}
52 52
 
53
-        return call_user_func_array($function, array_merge(array($this->getArrayCopy()), $arguments));
54
-    }
53
+		return call_user_func_array($function, array_merge(array($this->getArrayCopy()), $arguments));
54
+	}
55 55
 
56
-    /**
57
-     * Check whether the Config has a specific key.
58
-     *
59
-     * @since 0.1.0
60
-     *
61
-     * @param string $key The key to check the existence for.
62
-     * @return bool
63
-     */
64
-    public function hasKey($key)
65
-    {
66
-        return array_key_exists($key, (array)$this);
67
-    }
56
+	/**
57
+	 * Check whether the Config has a specific key.
58
+	 *
59
+	 * @since 0.1.0
60
+	 *
61
+	 * @param string $key The key to check the existence for.
62
+	 * @return bool
63
+	 */
64
+	public function hasKey($key)
65
+	{
66
+		return array_key_exists($key, (array)$this);
67
+	}
68 68
 
69
-    /**
70
-     * Get the value of a specific key.
71
-     *
72
-     * @since 0.1.0
73
-     *
74
-     * @param string $key The key to get the value for.
75
-     * @return mixed
76
-     */
77
-    public function getKey($key)
78
-    {
79
-        return $this[$key];
80
-    }
69
+	/**
70
+	 * Get the value of a specific key.
71
+	 *
72
+	 * @since 0.1.0
73
+	 *
74
+	 * @param string $key The key to get the value for.
75
+	 * @return mixed
76
+	 */
77
+	public function getKey($key)
78
+	{
79
+		return $this[$key];
80
+	}
81 81
 
82
-    /**
83
-     * Get the an array with all the keys
84
-     *
85
-     * @since 0.1.0
86
-     * @return mixed
87
-     */
88
-    public function getKeys()
89
-    {
90
-        return array_keys((array)$this);
91
-    }
82
+	/**
83
+	 * Get the an array with all the keys
84
+	 *
85
+	 * @since 0.1.0
86
+	 * @return mixed
87
+	 */
88
+	public function getKeys()
89
+	{
90
+		return array_keys((array)$this);
91
+	}
92 92
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     public function __call($function, $arguments)
48 48
     {
49 49
         if ( ! is_callable($function) || substr($function, 0, 6) !== 'array_') {
50
-            throw new BadMethodCallException(__CLASS__ . '->' . $function);
50
+            throw new BadMethodCallException(__CLASS__.'->'.$function);
51 51
         }
52 52
 
53 53
         return call_user_func_array($function, array_merge(array($this->getArrayCopy()), $arguments));
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     public function hasKey($key)
65 65
     {
66
-        return array_key_exists($key, (array)$this);
66
+        return array_key_exists($key, (array) $this);
67 67
     }
68 68
 
69 69
     /**
@@ -87,6 +87,6 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public function getKeys()
89 89
     {
90
-        return array_keys((array)$this);
90
+        return array_keys((array) $this);
91 91
     }
92 92
 }
Please login to merge, or discard this patch.
src/ConfigInterface.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * ConfigInterface Interface.
4
- *
5
- * @package   phpfeature
6
- * @author    Alain Schlesser <[email protected]>
7
- * @license   GPL-2.0+
8
- * @link      http://www.brightnucleus.com/
9
- * @copyright 2016 Alain Schlesser, Bright Nucleus
10
- */
3
+	 * ConfigInterface Interface.
4
+	 *
5
+	 * @package   phpfeature
6
+	 * @author    Alain Schlesser <[email protected]>
7
+	 * @license   GPL-2.0+
8
+	 * @link      http://www.brightnucleus.com/
9
+	 * @copyright 2016 Alain Schlesser, Bright Nucleus
10
+	 */
11 11
 
12 12
 /**
13 13
  * Interface ConfigInterface
@@ -19,47 +19,47 @@  discard block
 block discarded – undo
19 19
 interface ConfigInterface
20 20
 {
21 21
 
22
-    /**
23
-     * Creates a copy of the ArrayObject.
24
-     *
25
-     * Returns a copy of the array. When the ArrayObject refers to an object an
26
-     * array of the public properties of that object will be returned.
27
-     * This is implemented by \ArrayObject.
28
-     *
29
-     * @since 0.1.0
30
-     *
31
-     * @return array Copy of the array.
32
-     */
33
-    public function getArrayCopy();
22
+	/**
23
+	 * Creates a copy of the ArrayObject.
24
+	 *
25
+	 * Returns a copy of the array. When the ArrayObject refers to an object an
26
+	 * array of the public properties of that object will be returned.
27
+	 * This is implemented by \ArrayObject.
28
+	 *
29
+	 * @since 0.1.0
30
+	 *
31
+	 * @return array Copy of the array.
32
+	 */
33
+	public function getArrayCopy();
34 34
 
35
-    /**
36
-     * Check whether the Config has a specific key.
37
-     *
38
-     * @since 0.1.0
39
-     *
40
-     * @param string $key The key to check the existence for.
41
-     *
42
-     * @return bool
43
-     */
44
-    public function hasKey($key);
35
+	/**
36
+	 * Check whether the Config has a specific key.
37
+	 *
38
+	 * @since 0.1.0
39
+	 *
40
+	 * @param string $key The key to check the existence for.
41
+	 *
42
+	 * @return bool
43
+	 */
44
+	public function hasKey($key);
45 45
 
46
-    /**
47
-     * Get the value of a specific key.
48
-     *
49
-     * @since 0.1.0
50
-     *
51
-     * @param string $key The key to get the value for.
52
-     *
53
-     * @return mixed
54
-     */
55
-    public function getKey($key);
46
+	/**
47
+	 * Get the value of a specific key.
48
+	 *
49
+	 * @since 0.1.0
50
+	 *
51
+	 * @param string $key The key to get the value for.
52
+	 *
53
+	 * @return mixed
54
+	 */
55
+	public function getKey($key);
56 56
 
57
-    /**
58
-     * Get the an array with all the keys
59
-     *
60
-     * @since 0.1.0
61
-     *
62
-     * @return mixed
63
-     */
64
-    public function getKeys();
57
+	/**
58
+	 * Get the an array with all the keys
59
+	 *
60
+	 * @since 0.1.0
61
+	 *
62
+	 * @return mixed
63
+	 */
64
+	public function getKeys();
65 65
 }
Please login to merge, or discard this patch.
src/FeatureInterface.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * FeatureInterface Interface
4
- *
5
- * @package   phpfeature
6
- * @author    Alain Schlesser <[email protected]>
7
- * @license   GPL-2.0+
8
- * @link      http://www.brightnucleus.com/
9
- * @copyright 2016 Alain Schlesser, Bright Nucleus
10
- */
3
+	 * FeatureInterface Interface
4
+	 *
5
+	 * @package   phpfeature
6
+	 * @author    Alain Schlesser <[email protected]>
7
+	 * @license   GPL-2.0+
8
+	 * @link      http://www.brightnucleus.com/
9
+	 * @copyright 2016 Alain Schlesser, Bright Nucleus
10
+	 */
11 11
 
12 12
 /**
13 13
  * Interface FeatureInterface
@@ -19,33 +19,33 @@  discard block
 block discarded – undo
19 19
 interface FeatureInterface
20 20
 {
21 21
 
22
-    /**
23
-     * Check whether a feature or a collection of features is supported.
24
-     *
25
-     * Accepts either a string or an array of strings. Returns true if all the
26
-     * passed-in features are supported, or false if at least one of them is
27
-     * not.
28
-     *
29
-     * @since 0.1.0
30
-     *
31
-     * @param string|array $features What features to check the support of.
32
-     * @return bool
33
-     */
34
-    public function isSupported($features);
22
+	/**
23
+	 * Check whether a feature or a collection of features is supported.
24
+	 *
25
+	 * Accepts either a string or an array of strings. Returns true if all the
26
+	 * passed-in features are supported, or false if at least one of them is
27
+	 * not.
28
+	 *
29
+	 * @since 0.1.0
30
+	 *
31
+	 * @param string|array $features What features to check the support of.
32
+	 * @return bool
33
+	 */
34
+	public function isSupported($features);
35 35
 
36
-    /**
37
-     * Get the minimum required version that supports all of the requested
38
-     * features.
39
-     *
40
-     * Accepts either a string or an array of strings. Returns a
41
-     * SemanticVersion object for the version number that is known to support
42
-     * all the passed-in features, or false if at least one of
43
-     * them is not supported by any known version.
44
-     *
45
-     * @since 0.2.0
46
-     *
47
-     * @param string|array $features What features to check the support of.
48
-     * @return SemanticVersion|bool
49
-     */
50
-    public function getMinimumRequired($features);
36
+	/**
37
+	 * Get the minimum required version that supports all of the requested
38
+	 * features.
39
+	 *
40
+	 * Accepts either a string or an array of strings. Returns a
41
+	 * SemanticVersion object for the version number that is known to support
42
+	 * all the passed-in features, or false if at least one of
43
+	 * them is not supported by any known version.
44
+	 *
45
+	 * @since 0.2.0
46
+	 *
47
+	 * @param string|array $features What features to check the support of.
48
+	 * @return SemanticVersion|bool
49
+	 */
50
+	public function getMinimumRequired($features);
51 51
 }
Please login to merge, or discard this patch.
src/PHPFeature.php 2 patches
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * PHPFeature Class
4
- *
5
- * @package   phpfeature
6
- * @author    Alain Schlesser <[email protected]>
7
- * @license   GPL-2.0+
8
- * @link      http://www.brightnucleus.com/
9
- * @copyright 2016 Alain Schlesser, Bright Nucleus
10
- */
3
+	 * PHPFeature Class
4
+	 *
5
+	 * @package   phpfeature
6
+	 * @author    Alain Schlesser <[email protected]>
7
+	 * @license   GPL-2.0+
8
+	 * @link      http://www.brightnucleus.com/
9
+	 * @copyright 2016 Alain Schlesser, Bright Nucleus
10
+	 */
11 11
 
12 12
 /**
13 13
  * Class PHPFeature
@@ -19,247 +19,247 @@  discard block
 block discarded – undo
19 19
 class PHPFeature implements FeatureInterface
20 20
 {
21 21
 
22
-    /**
23
-     * RegEx pattern that matches the comparison string.
24
-     *
25
-     * @since 0.1.0
26
-     *
27
-     * @var string
28
-     */
29
-    const COMPARISON_PATTERN = '/^(?:(<=|lt|<|le|>=|gt|>|ge|=|==|eq|!=|<>|ne))([0-9].*)$/';
30
-
31
-    /**
32
-     * Reference to the Configuration object.
33
-     *
34
-     * @since 0.1.0
35
-     *
36
-     * @var ConfigInterface
37
-     */
38
-    protected $config;
39
-
40
-    /**
41
-     * Reference to the Version object.
42
-     *
43
-     * @since 0.1.0
44
-     *
45
-     * @var SemanticVersion
46
-     */
47
-    protected $version;
48
-
49
-    /**
50
-     * Instantiate a PHPFeature object.
51
-     *
52
-     * @since 0.1.0
53
-     *
54
-     * @param SemanticVersion|string|int|null $phpVersion  Version of PHP to
55
-     *                                                     check the features
56
-     *                                                     for.
57
-     * @param ConfigInterface|null            $config      Configuration that
58
-     *                                                     contains the known
59
-     *                                                     features.
60
-     * @throws RuntimeException If the PHP version could not be validated.
61
-     */
62
-    public function __construct($phpVersion = null, ConfigInterface $config = null)
63
-    {
64
-
65
-        // TODO: Better way to bootstrap this while still allowing DI?
66
-        if ( ! $config) {
67
-            $config = new Config(include(__DIR__ . '/../config/known_features.php'));
68
-        }
69
-
70
-        $this->config = $config;
71
-
72
-        if (null === $phpVersion) {
73
-            $phpVersion = phpversion();
74
-        }
75
-
76
-        if (is_integer($phpVersion)) {
77
-            $phpVersion = (string)$phpVersion;
78
-        }
79
-
80
-        if (is_string($phpVersion)) {
81
-            $phpVersion = new SemanticVersion($phpVersion, true);
82
-        }
83
-
84
-        $this->version = $phpVersion;
85
-    }
86
-
87
-    /**
88
-     * Check whether a feature or a collection of features is supported.
89
-     *
90
-     * Accepts either a string or an array of strings. Returns true if all the
91
-     * passed-in features are supported, or false if at least one of them is
92
-     * not.
93
-     *
94
-     * @since 0.1.0
95
-     *
96
-     * @param string|array $features    What features to check the support of.
97
-     * @return bool
98
-     * @throws InvalidArgumentException If the wrong type of argument is passed
99
-     *                                  in.
100
-     * @throws RuntimeException         If a requirement could not be parsed.
101
-     */
102
-    public function isSupported($features)
103
-    {
104
-
105
-        if (is_string($features)) {
106
-            $features = array($features);
107
-        }
108
-
109
-        if ( ! is_array($features)) {
110
-            throw new InvalidArgumentException(sprintf(
111
-                'Wrong type of argument passed in to is_supported(): "%1$s".',
112
-                gettype($features)
113
-            ));
114
-        }
115
-
116
-        $isSupported = true;
117
-
118
-        while ($isSupported && count($features) > 0) {
119
-            $feature = array_pop($features);
120
-            $isSupported &= (bool)$this->checkSupport($feature);
121
-        }
122
-
123
-        return (bool)$isSupported;
124
-    }
125
-
126
-    /**
127
-     * Get the minimum required version that supports all of the requested
128
-     * features.
129
-     *
130
-     * Accepts either a string or an array of strings. Returns a
131
-     * SemanticVersion object for the version number that is known to support
132
-     * all the passed-in features, or false if at least one of
133
-     * them is not supported by any known version.
134
-     *
135
-     * @since 0.2.0
136
-     *
137
-     * @param string|array $features    What features to check the support of.
138
-     * @return SemanticVersion|bool
139
-     * @throws InvalidArgumentException If the wrong type of argument is passed
140
-     *                                  in.
141
-     * @throws RuntimeException         If a requirement could not be parsed.
142
-     */
143
-    public function getMinimumRequired($features)
144
-    {
145
-
146
-        if (is_string($features)) {
147
-            $features = array($features);
148
-        }
149
-
150
-        if ( ! is_array($features)) {
151
-            throw new InvalidArgumentException(sprintf(
152
-                'Wrong type of argument passed in to get_minimum_required(): "%1$s".',
153
-                gettype($features)
154
-            ));
155
-        }
156
-
157
-        $minimumRequired = '0.0.0';
158
-        $isSupported     = true;
159
-
160
-        while (count($features) > 0) {
161
-            $feature = array_pop($features);
162
-            $isSupported &= (bool)$this->checkSupport($feature, $minimumRequired);
163
-        }
164
-
165
-        return $minimumRequired !== '0.0.0' ? new SemanticVersion($minimumRequired, true) : false;
166
-    }
167
-
168
-    /**
169
-     * Check whether a single feature is supported.
170
-     *
171
-     * @since 0.1.0
172
-     *
173
-     * @param string $feature         The feature to check.
174
-     * @param string $minimumRequired Optional. Minimum required version that
175
-     *                                supports all features.
176
-     * @return bool
177
-     * @throws RuntimeException If the requirement could not be parsed.
178
-     */
179
-    protected function checkSupport($feature, &$minimumRequired = null)
180
-    {
181
-
182
-        if ( ! $this->config->hasKey($feature)) {
183
-            return false;
184
-        }
185
-
186
-        $requirements = $this->config->getKey($feature);
187
-
188
-        if ( ! is_array($requirements)) {
189
-            $requirements = array($requirements);
190
-        }
191
-
192
-        $isSupported = true;
193
-
194
-        while (($isSupported || $minimumRequired) && count($requirements) > 0) {
195
-            $requirement = array_pop($requirements);
196
-            $isSupported &= (bool)$this->checkRequirement($requirement, $minimumRequired);
197
-        }
198
-
199
-        return (bool)$isSupported;
200
-    }
201
-
202
-    /**
203
-     * Check whether a single requirement is met.
204
-     *
205
-     * @since 0.1.0
206
-     *
207
-     * @param string $requirement     A requirement that is composed of an
208
-     *                                operator and a version milestone.
209
-     * @param string $minimumRequired Optional. Minimum required version that
210
-     *                                supports all features.
211
-     * @return bool
212
-     * @throws RuntimeException If the requirement could not be parsed.
213
-     */
214
-    protected function checkRequirement($requirement, &$minimumRequired = null)
215
-    {
216
-
217
-        $requirement = trim($requirement);
218
-        $pattern     = self::COMPARISON_PATTERN;
219
-
220
-        $arguments = array();
221
-        $result    = preg_match($pattern, $requirement, $arguments);
222
-
223
-        if ( ! $result || ! isset($arguments[1]) || ! isset($arguments[2])) {
224
-            throw new RuntimeException(sprintf(
225
-                'Could not parse the requirement "%1$s".',
226
-                (string)$requirement
227
-            ));
228
-        }
229
-
230
-        $operator  = isset($arguments[1]) ? (string)$arguments[1] : '>=';
231
-        $milestone = isset($arguments[2]) ? (string)$arguments[2] : '0.0.0';
232
-
233
-        $isSupported = (bool)version_compare($this->version->getVersion(), $milestone, $operator);
234
-
235
-        if ($minimumRequired) {
236
-            $requiredVersion = $this->getRequiredVersion($milestone, $operator);
237
-            if (version_compare($requiredVersion, $minimumRequired, '>')) {
238
-                $minimumRequired = $requiredVersion;
239
-            }
240
-        }
241
-
242
-        return $isSupported;
243
-    }
244
-
245
-    /**
246
-     * Get the required version for a single requirement.
247
-     *
248
-     * @since 0.2.0
249
-     *
250
-     * @param string $milestone A version milestone that is used to define the
251
-     *                          requirement.
252
-     * @param string $operator  An operator that gets applied to the milestone.
253
-     *                          Possible values: '<=', 'lt', '<', 'le', '>=',
254
-     *                          'gt', '>', 'ge', '=', '==', 'eq', '!=', '<>',
255
-     *                          'ne'
256
-     * @return string
257
-     */
258
-    protected function getRequiredVersion($milestone, $operator)
259
-    {
260
-
261
-        // TODO: Algorithm is still missing, the `$operator` is simply ignored
262
-        // and the pure `$milestone` is returned.
263
-        return $milestone;
264
-    }
22
+	/**
23
+	 * RegEx pattern that matches the comparison string.
24
+	 *
25
+	 * @since 0.1.0
26
+	 *
27
+	 * @var string
28
+	 */
29
+	const COMPARISON_PATTERN = '/^(?:(<=|lt|<|le|>=|gt|>|ge|=|==|eq|!=|<>|ne))([0-9].*)$/';
30
+
31
+	/**
32
+	 * Reference to the Configuration object.
33
+	 *
34
+	 * @since 0.1.0
35
+	 *
36
+	 * @var ConfigInterface
37
+	 */
38
+	protected $config;
39
+
40
+	/**
41
+	 * Reference to the Version object.
42
+	 *
43
+	 * @since 0.1.0
44
+	 *
45
+	 * @var SemanticVersion
46
+	 */
47
+	protected $version;
48
+
49
+	/**
50
+	 * Instantiate a PHPFeature object.
51
+	 *
52
+	 * @since 0.1.0
53
+	 *
54
+	 * @param SemanticVersion|string|int|null $phpVersion  Version of PHP to
55
+	 *                                                     check the features
56
+	 *                                                     for.
57
+	 * @param ConfigInterface|null            $config      Configuration that
58
+	 *                                                     contains the known
59
+	 *                                                     features.
60
+	 * @throws RuntimeException If the PHP version could not be validated.
61
+	 */
62
+	public function __construct($phpVersion = null, ConfigInterface $config = null)
63
+	{
64
+
65
+		// TODO: Better way to bootstrap this while still allowing DI?
66
+		if ( ! $config) {
67
+			$config = new Config(include(__DIR__ . '/../config/known_features.php'));
68
+		}
69
+
70
+		$this->config = $config;
71
+
72
+		if (null === $phpVersion) {
73
+			$phpVersion = phpversion();
74
+		}
75
+
76
+		if (is_integer($phpVersion)) {
77
+			$phpVersion = (string)$phpVersion;
78
+		}
79
+
80
+		if (is_string($phpVersion)) {
81
+			$phpVersion = new SemanticVersion($phpVersion, true);
82
+		}
83
+
84
+		$this->version = $phpVersion;
85
+	}
86
+
87
+	/**
88
+	 * Check whether a feature or a collection of features is supported.
89
+	 *
90
+	 * Accepts either a string or an array of strings. Returns true if all the
91
+	 * passed-in features are supported, or false if at least one of them is
92
+	 * not.
93
+	 *
94
+	 * @since 0.1.0
95
+	 *
96
+	 * @param string|array $features    What features to check the support of.
97
+	 * @return bool
98
+	 * @throws InvalidArgumentException If the wrong type of argument is passed
99
+	 *                                  in.
100
+	 * @throws RuntimeException         If a requirement could not be parsed.
101
+	 */
102
+	public function isSupported($features)
103
+	{
104
+
105
+		if (is_string($features)) {
106
+			$features = array($features);
107
+		}
108
+
109
+		if ( ! is_array($features)) {
110
+			throw new InvalidArgumentException(sprintf(
111
+				'Wrong type of argument passed in to is_supported(): "%1$s".',
112
+				gettype($features)
113
+			));
114
+		}
115
+
116
+		$isSupported = true;
117
+
118
+		while ($isSupported && count($features) > 0) {
119
+			$feature = array_pop($features);
120
+			$isSupported &= (bool)$this->checkSupport($feature);
121
+		}
122
+
123
+		return (bool)$isSupported;
124
+	}
125
+
126
+	/**
127
+	 * Get the minimum required version that supports all of the requested
128
+	 * features.
129
+	 *
130
+	 * Accepts either a string or an array of strings. Returns a
131
+	 * SemanticVersion object for the version number that is known to support
132
+	 * all the passed-in features, or false if at least one of
133
+	 * them is not supported by any known version.
134
+	 *
135
+	 * @since 0.2.0
136
+	 *
137
+	 * @param string|array $features    What features to check the support of.
138
+	 * @return SemanticVersion|bool
139
+	 * @throws InvalidArgumentException If the wrong type of argument is passed
140
+	 *                                  in.
141
+	 * @throws RuntimeException         If a requirement could not be parsed.
142
+	 */
143
+	public function getMinimumRequired($features)
144
+	{
145
+
146
+		if (is_string($features)) {
147
+			$features = array($features);
148
+		}
149
+
150
+		if ( ! is_array($features)) {
151
+			throw new InvalidArgumentException(sprintf(
152
+				'Wrong type of argument passed in to get_minimum_required(): "%1$s".',
153
+				gettype($features)
154
+			));
155
+		}
156
+
157
+		$minimumRequired = '0.0.0';
158
+		$isSupported     = true;
159
+
160
+		while (count($features) > 0) {
161
+			$feature = array_pop($features);
162
+			$isSupported &= (bool)$this->checkSupport($feature, $minimumRequired);
163
+		}
164
+
165
+		return $minimumRequired !== '0.0.0' ? new SemanticVersion($minimumRequired, true) : false;
166
+	}
167
+
168
+	/**
169
+	 * Check whether a single feature is supported.
170
+	 *
171
+	 * @since 0.1.0
172
+	 *
173
+	 * @param string $feature         The feature to check.
174
+	 * @param string $minimumRequired Optional. Minimum required version that
175
+	 *                                supports all features.
176
+	 * @return bool
177
+	 * @throws RuntimeException If the requirement could not be parsed.
178
+	 */
179
+	protected function checkSupport($feature, &$minimumRequired = null)
180
+	{
181
+
182
+		if ( ! $this->config->hasKey($feature)) {
183
+			return false;
184
+		}
185
+
186
+		$requirements = $this->config->getKey($feature);
187
+
188
+		if ( ! is_array($requirements)) {
189
+			$requirements = array($requirements);
190
+		}
191
+
192
+		$isSupported = true;
193
+
194
+		while (($isSupported || $minimumRequired) && count($requirements) > 0) {
195
+			$requirement = array_pop($requirements);
196
+			$isSupported &= (bool)$this->checkRequirement($requirement, $minimumRequired);
197
+		}
198
+
199
+		return (bool)$isSupported;
200
+	}
201
+
202
+	/**
203
+	 * Check whether a single requirement is met.
204
+	 *
205
+	 * @since 0.1.0
206
+	 *
207
+	 * @param string $requirement     A requirement that is composed of an
208
+	 *                                operator and a version milestone.
209
+	 * @param string $minimumRequired Optional. Minimum required version that
210
+	 *                                supports all features.
211
+	 * @return bool
212
+	 * @throws RuntimeException If the requirement could not be parsed.
213
+	 */
214
+	protected function checkRequirement($requirement, &$minimumRequired = null)
215
+	{
216
+
217
+		$requirement = trim($requirement);
218
+		$pattern     = self::COMPARISON_PATTERN;
219
+
220
+		$arguments = array();
221
+		$result    = preg_match($pattern, $requirement, $arguments);
222
+
223
+		if ( ! $result || ! isset($arguments[1]) || ! isset($arguments[2])) {
224
+			throw new RuntimeException(sprintf(
225
+				'Could not parse the requirement "%1$s".',
226
+				(string)$requirement
227
+			));
228
+		}
229
+
230
+		$operator  = isset($arguments[1]) ? (string)$arguments[1] : '>=';
231
+		$milestone = isset($arguments[2]) ? (string)$arguments[2] : '0.0.0';
232
+
233
+		$isSupported = (bool)version_compare($this->version->getVersion(), $milestone, $operator);
234
+
235
+		if ($minimumRequired) {
236
+			$requiredVersion = $this->getRequiredVersion($milestone, $operator);
237
+			if (version_compare($requiredVersion, $minimumRequired, '>')) {
238
+				$minimumRequired = $requiredVersion;
239
+			}
240
+		}
241
+
242
+		return $isSupported;
243
+	}
244
+
245
+	/**
246
+	 * Get the required version for a single requirement.
247
+	 *
248
+	 * @since 0.2.0
249
+	 *
250
+	 * @param string $milestone A version milestone that is used to define the
251
+	 *                          requirement.
252
+	 * @param string $operator  An operator that gets applied to the milestone.
253
+	 *                          Possible values: '<=', 'lt', '<', 'le', '>=',
254
+	 *                          'gt', '>', 'ge', '=', '==', 'eq', '!=', '<>',
255
+	 *                          'ne'
256
+	 * @return string
257
+	 */
258
+	protected function getRequiredVersion($milestone, $operator)
259
+	{
260
+
261
+		// TODO: Algorithm is still missing, the `$operator` is simply ignored
262
+		// and the pure `$milestone` is returned.
263
+		return $milestone;
264
+	}
265 265
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 
65 65
         // TODO: Better way to bootstrap this while still allowing DI?
66 66
         if ( ! $config) {
67
-            $config = new Config(include(__DIR__ . '/../config/known_features.php'));
67
+            $config = new Config(include(__DIR__.'/../config/known_features.php'));
68 68
         }
69 69
 
70 70
         $this->config = $config;
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
         }
75 75
 
76 76
         if (is_integer($phpVersion)) {
77
-            $phpVersion = (string)$phpVersion;
77
+            $phpVersion = (string) $phpVersion;
78 78
         }
79 79
 
80 80
         if (is_string($phpVersion)) {
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
 
118 118
         while ($isSupported && count($features) > 0) {
119 119
             $feature = array_pop($features);
120
-            $isSupported &= (bool)$this->checkSupport($feature);
120
+            $isSupported &= (bool) $this->checkSupport($feature);
121 121
         }
122 122
 
123
-        return (bool)$isSupported;
123
+        return (bool) $isSupported;
124 124
     }
125 125
 
126 126
     /**
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 
160 160
         while (count($features) > 0) {
161 161
             $feature = array_pop($features);
162
-            $isSupported &= (bool)$this->checkSupport($feature, $minimumRequired);
162
+            $isSupported &= (bool) $this->checkSupport($feature, $minimumRequired);
163 163
         }
164 164
 
165 165
         return $minimumRequired !== '0.0.0' ? new SemanticVersion($minimumRequired, true) : false;
@@ -193,10 +193,10 @@  discard block
 block discarded – undo
193 193
 
194 194
         while (($isSupported || $minimumRequired) && count($requirements) > 0) {
195 195
             $requirement = array_pop($requirements);
196
-            $isSupported &= (bool)$this->checkRequirement($requirement, $minimumRequired);
196
+            $isSupported &= (bool) $this->checkRequirement($requirement, $minimumRequired);
197 197
         }
198 198
 
199
-        return (bool)$isSupported;
199
+        return (bool) $isSupported;
200 200
     }
201 201
 
202 202
     /**
@@ -223,14 +223,14 @@  discard block
 block discarded – undo
223 223
         if ( ! $result || ! isset($arguments[1]) || ! isset($arguments[2])) {
224 224
             throw new RuntimeException(sprintf(
225 225
                 'Could not parse the requirement "%1$s".',
226
-                (string)$requirement
226
+                (string) $requirement
227 227
             ));
228 228
         }
229 229
 
230
-        $operator  = isset($arguments[1]) ? (string)$arguments[1] : '>=';
231
-        $milestone = isset($arguments[2]) ? (string)$arguments[2] : '0.0.0';
230
+        $operator  = isset($arguments[1]) ? (string) $arguments[1] : '>=';
231
+        $milestone = isset($arguments[2]) ? (string) $arguments[2] : '0.0.0';
232 232
 
233
-        $isSupported = (bool)version_compare($this->version->getVersion(), $milestone, $operator);
233
+        $isSupported = (bool) version_compare($this->version->getVersion(), $milestone, $operator);
234 234
 
235 235
         if ($minimumRequired) {
236 236
             $requiredVersion = $this->getRequiredVersion($milestone, $operator);
Please login to merge, or discard this patch.