Passed
Branch master (b8d8a1)
by Chris
02:16
created
src/utils.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -155,6 +155,10 @@
 block discarded – undo
155 155
         return self::get_request_value_int( 'SERVER', $key, $default_value );
156 156
     }
157 157
 
158
+    /**
159
+     * @param string $request_method
160
+     * @param string $key
161
+     */
158 162
     public static function get_request_value_int( $request_method, $key, $default_value = null )
159 163
     {
160 164
         $value = self::get_request_value( $request_method, $key, null );
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -313,17 +313,17 @@
 block discarded – undo
313 313
      * @param  array $parsed_url An array created by urlpieces.
314 314
      * @return string            A URL string.
315 315
      */
316
-    public static function unparse_url( $parsed_url ) {
316
+    public static function unparse_url( $parsed_url ){
317 317
         //I don't know what you gave me so you can just have it back
318
-        if( ! is_array( $parsed_url ) ) {
318
+        if( ! is_array( $parsed_url ) ){
319 319
             return $parsed_url;
320 320
         }
321
-        $scheme   = isset( $parsed_url['scheme'])    ?       $parsed_url['scheme'] . '://' : '';
322
-        $host     = isset( $parsed_url['host'] )     ?       $parsed_url['host']           : '';
323
-        $port     = isset( $parsed_url['port'] )     ? ':' . $parsed_url['port']           : '';
324
-        $path     = isset( $parsed_url['path'] )     ?       $parsed_url['path']           : '';
325
-        $query    = isset( $parsed_url['query'] )    ? '?' . $parsed_url['query']          : '';
326
-        $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment']       : '';
321
+        $scheme   = isset( $parsed_url[ 'scheme' ] ) ? $parsed_url[ 'scheme' ] . '://' : '';
322
+        $host     = isset( $parsed_url[ 'host' ] ) ? $parsed_url[ 'host' ] : '';
323
+        $port     = isset( $parsed_url[ 'port' ] ) ? ':' . $parsed_url[ 'port' ] : '';
324
+        $path     = isset( $parsed_url[ 'path' ] ) ? $parsed_url[ 'path' ] : '';
325
+        $query    = isset( $parsed_url[ 'query' ] ) ? '?' . $parsed_url[ 'query' ] : '';
326
+        $fragment = isset( $parsed_url[ 'fragment' ] ) ? '#' . $parsed_url[ 'fragment' ] : '';
327 327
 
328 328
         //NOTE: user and pass were explicitly removed.
329 329
 
Please login to merge, or discard this patch.
Braces   +66 added lines, -64 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace Vendi\Shared;
10 10
 
11
-if( class_exists( '\Vendi\Shared\utils' ) )
12
-{
11
+if( class_exists( '\Vendi\Shared\utils' ) )
12
+{
13 13
     return;
14 14
 }
15 15
 
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
  * @version  2.1.0
50 50
  */
51 51
 
52
-class utils
53
-{
52
+class utils
53
+{
54 54
     public static $CUSTOM_POST = null;
55 55
 
56 56
     public static $CUSTOM_GET = null;
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
 
60 60
     public static $CUSTOM_SERVER = null;
61 61
 
62
-    public static function reset_all_custom_arrays()
63
-    {
62
+    public static function reset_all_custom_arrays()
63
+    {
64 64
         self::$CUSTOM_POST = null;
65 65
         self::$CUSTOM_GET = null;
66 66
         self::$CUSTOM_COOKIE = null;
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
74 74
      * @return mixed                        The value of the HTTP POST for the given $key or the $default.
75 75
      */
76
-    public static function get_post_value( $key, $default_value = '' )
77
-    {
76
+    public static function get_post_value( $key, $default_value = '' )
77
+    {
78 78
         return self::get_request_value( 'POST', $key, $default_value );
79 79
     }
80 80
 
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
85 85
      * @return mixed                        The value of the HTTP GET for the given $key or the $default.
86 86
      */
87
-    public static function get_get_value( $key, $default_value = '' )
88
-    {
87
+    public static function get_get_value( $key, $default_value = '' )
88
+    {
89 89
         return self::get_request_value( 'GET', $key, $default_value );
90 90
     }
91 91
 
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
96 96
      * @return mixed                        The value of the HTTP COOKIE for the given $key or the $default.
97 97
      */
98
-    public static function get_cookie_value( $key, $default_value = '' )
99
-    {
98
+    public static function get_cookie_value( $key, $default_value = '' )
99
+    {
100 100
         return self::get_request_value( 'COOKIE', $key, $default_value );
101 101
     }
102 102
 
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
107 107
      * @return mixed                        The value of the HTTP SERVER for the given $key or the $default.
108 108
      */
109
-    public static function get_server_value( $key, $default_value = '' )
110
-    {
109
+    public static function get_server_value( $key, $default_value = '' )
110
+    {
111 111
         return self::get_request_value( 'SERVER', $key, $default_value );
112 112
     }
113 113
 
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
120 120
      * @return mixed                        The value of the source for the given $key or the $default.
121 121
      */
122
-    public static function get_value_multiple_sources( $key, array $sources, $default_value = null )
123
-    {
124
-        foreach( $sources as $source )
125
-        {
122
+    public static function get_value_multiple_sources( $key, array $sources, $default_value = null )
123
+    {
124
+        foreach( $sources as $source )
125
+        {
126 126
             $value = self::get_request_value( $source, $key, null );
127
-            if( null !== $value )
128
-            {
127
+            if( null !== $value )
128
+            {
129 129
                 return $value;
130 130
             }
131 131
         }
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
      * @param  integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null.
140 140
      * @return integer|mixed                The value of the HTTP POST for the given $key or the $default.
141 141
      */
142
-    public static function get_post_value_int( $key, $default_value = null )
143
-    {
142
+    public static function get_post_value_int( $key, $default_value = null )
143
+    {
144 144
         return self::get_request_value_int( 'POST', $key, $default_value );
145 145
     }
146 146
 
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
      * @param  integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null.
151 151
      * @return integer|mixed                The value of the HTTP GET for the given $key or the $default.
152 152
      */
153
-    public static function get_get_value_int( $key, $default_value = null )
154
-    {
153
+    public static function get_get_value_int( $key, $default_value = null )
154
+    {
155 155
         return self::get_request_value_int( 'GET', $key, $default_value );
156 156
     }
157 157
 
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
      * @param  integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null.
162 162
      * @return integer|mixed                The value of the HTTP COOKIE for the given $key or the $default.
163 163
      */
164
-    public static function get_cookie_value_int( $key, $default_value = null )
165
-    {
164
+    public static function get_cookie_value_int( $key, $default_value = null )
165
+    {
166 166
         return self::get_request_value_int( 'COOKIE', $key, $default_value );
167 167
     }
168 168
 
@@ -172,70 +172,70 @@  discard block
 block discarded – undo
172 172
      * @param  integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null.
173 173
      * @return integer|mixed                The value of the HTTP SERVER for the given $key or the $default.
174 174
      */
175
-    public static function get_server_value_int( $key, $default_value = null )
176
-    {
175
+    public static function get_server_value_int( $key, $default_value = null )
176
+    {
177 177
         return self::get_request_value_int( 'SERVER', $key, $default_value );
178 178
     }
179 179
 
180
-    public static function get_request_value_int( $request_method, $key, $default_value = null )
181
-    {
180
+    public static function get_request_value_int( $request_method, $key, $default_value = null )
181
+    {
182 182
         $value = self::get_request_value( $request_method, $key, null );
183
-        if( self::is_integer_like( $value ) )
184
-        {
183
+        if( self::is_integer_like( $value ) )
184
+        {
185 185
             return (int)$value;
186 186
         }
187 187
 
188 188
         return $default_value;
189 189
     }
190 190
 
191
-    public static function get_request_value( $request_method, $key, $default_value = null )
192
-    {
191
+    public static function get_request_value( $request_method, $key, $default_value = null )
192
+    {
193 193
         $request_obj = self::get_request_object( $request_method );
194 194
 
195
-        if( null === $request_obj || ! is_array( $request_obj ) || ! array_key_exists( $key, $request_obj ) )
196
-        {
195
+        if( null === $request_obj || ! is_array( $request_obj ) || ! array_key_exists( $key, $request_obj ) )
196
+        {
197 197
             return $default_value;
198 198
         }
199 199
 
200 200
         $ret = $request_obj[ $key ];
201 201
 
202
-        if( is_string( $ret ) )
203
-        {
202
+        if( is_string( $ret ) )
203
+        {
204 204
             $ret = trim( $ret );
205 205
         }
206 206
 
207 207
         return $ret;
208 208
     }
209 209
 
210
-    public static function get_request_object( $request_method )
211
-    {
210
+    public static function get_request_object( $request_method )
211
+    {
212 212
         $obj = null;
213
-        switch( $request_method )
214
-        {
213
+        switch( $request_method )
214
+        {
215 215
             case 'GET':
216
-                if( is_array( self::$CUSTOM_GET ) )
217
-                {
216
+                if( is_array( self::$CUSTOM_GET ) )
217
+                {
218 218
                     return self::$CUSTOM_GET;
219 219
                 }
220 220
                 return ( isset( $_GET ) && is_array( $_GET ) && count( $_GET ) > 0 ? $_GET : null );
221 221
 
222 222
             case 'POST':
223
-                if( is_array( self::$CUSTOM_POST ) )
224
-                {
223
+                if( is_array( self::$CUSTOM_POST ) )
224
+                {
225 225
                     return self::$CUSTOM_POST;
226 226
                 }
227 227
                 return ( isset( $_POST ) && is_array( $_POST ) && count( $_POST ) > 0 ? $_POST : null );
228 228
 
229 229
             case 'COOKIE':
230
-                if( is_array( self::$CUSTOM_COOKIE ) )
231
-                {
230
+                if( is_array( self::$CUSTOM_COOKIE ) )
231
+                {
232 232
                     return self::$CUSTOM_COOKIE;
233 233
                 }
234 234
                 return ( isset( $_COOKIE ) && is_array( $_COOKIE ) && count( $_COOKIE ) > 0 ? $_COOKIE : null );
235 235
 
236 236
             case 'SERVER':
237
-                if( is_array( self::$CUSTOM_SERVER ) )
238
-                {
237
+                if( is_array( self::$CUSTOM_SERVER ) )
238
+                {
239 239
                     return self::$CUSTOM_SERVER;
240 240
                 }
241 241
                 return ( isset( $_SERVER ) && is_array( $_SERVER ) && count( $_SERVER ) > 0 ? $_SERVER : null );
@@ -251,8 +251,8 @@  discard block
 block discarded – undo
251 251
      * @param  string  $method The server method to test for. Generally one of GET, POST, HEAD, PUT, DELETE.
252 252
      * @return boolean         Returns true if the REQUEST_METHOD server variable is set to the supplied $method, otherwise false.
253 253
      */
254
-    public static function is_request_method( $method )
255
-    {
254
+    public static function is_request_method( $method )
255
+    {
256 256
         return $method === self::get_server_value( 'REQUEST_METHOD' );
257 257
     }
258 258
 
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
      *
267 267
      * @return boolean Returns true if the REQUEST_METHOD server variable is set to POST, otherwise false.
268 268
      */
269
-    public static function is_post( )
270
-    {
269
+    public static function is_post( )
270
+    {
271 271
         return self::is_request_method( 'POST' );
272 272
     }
273 273
 
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
      * @param  mixed  $input The value to test.
280 280
      * @return boolean       True if $input is an integer or a string that contains only digits possibly starting with a dash.
281 281
      */
282
-    public static function is_integer_like( $input )
283
-    {
282
+    public static function is_integer_like( $input )
283
+    {
284 284
         return
285 285
                 is_int( $input )
286 286
                 ||
@@ -291,13 +291,13 @@  discard block
 block discarded – undo
291 291
                 );
292 292
     }
293 293
 
294
-    public static function get_all_headers()
295
-    {
294
+    public static function get_all_headers()
295
+    {
296 296
         $headers = array();
297
-        foreach( array( '_SERVER', '_GET', '_POST', '_COOKIE', '_ENV' ) as $key )
298
-        {
299
-            if( array_key_exists( $key, $GLOBALS ) )
300
-            {
297
+        foreach( array( '_SERVER', '_GET', '_POST', '_COOKIE', '_ENV' ) as $key )
298
+        {
299
+            if( array_key_exists( $key, $GLOBALS ) )
300
+            {
301 301
 
302 302
             }
303 303
             $headers[ $key ] = $GLOBALS[ $key ];
@@ -313,9 +313,11 @@  discard block
 block discarded – undo
313 313
      * @param  array $parsed_url An array created by urlpieces.
314 314
      * @return string            A URL string.
315 315
      */
316
-    public static function unparse_url( $parsed_url ) {
316
+    public static function unparse_url( $parsed_url )
317
+    {
317 318
         //I don't know what you gave me so you can just have it back
318
-        if( ! is_array( $parsed_url ) ) {
319
+        if( ! is_array( $parsed_url ) )
320
+        {
319 321
             return $parsed_url;
320 322
         }
321 323
         $scheme   = isset( $parsed_url['scheme'])    ?       $parsed_url['scheme'] . '://' : '';
Please login to merge, or discard this patch.