Passed
Push — master ( bb6f0e...232fc8 )
by Chris
02:03
created
src/utils.php 2 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -186,7 +186,8 @@
 block discarded – undo
186 186
     /**
187 187
      * Get the current request array or mock array if set.
188 188
      *
189
-     * @param  string    The server method to use, one of GET, POST, SERVER or COOKIE.
189
+     * @param  string    The server method to use, one of GET, POST, SERVER or COOKIE.
190
+     * @param string $request_method
190 191
      * @return arra|null The requested array or null.
191 192
      */
192 193
     public static function get_request_object( $request_method )
Please login to merge, or discard this patch.
Braces   +58 added lines, -56 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
-class utils
12
-{
11
+class utils
12
+{
13 13
     public static $CUSTOM_POST = null;
14 14
 
15 15
     public static $CUSTOM_GET = null;
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
     /**
22 22
      * Reset the internal arrays to default values.
23 23
      */
24
-    public static function reset_all_custom_arrays()
25
-    {
24
+    public static function reset_all_custom_arrays()
25
+    {
26 26
         self::$CUSTOM_POST = null;
27 27
         self::$CUSTOM_GET = null;
28 28
         self::$CUSTOM_COOKIE = null;
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
36 36
      * @return mixed                        The value of the HTTP POST for the given $key or the $default.
37 37
      */
38
-    public static function get_post_value( $key, $default_value = '' )
39
-    {
38
+    public static function get_post_value( $key, $default_value = '' )
39
+    {
40 40
         return self::get_request_value( 'POST', $key, $default_value );
41 41
     }
42 42
 
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
47 47
      * @return mixed                        The value of the HTTP GET for the given $key or the $default.
48 48
      */
49
-    public static function get_get_value( $key, $default_value = '' )
50
-    {
49
+    public static function get_get_value( $key, $default_value = '' )
50
+    {
51 51
         return self::get_request_value( 'GET', $key, $default_value );
52 52
     }
53 53
 
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
58 58
      * @return mixed                        The value of the HTTP COOKIE for the given $key or the $default.
59 59
      */
60
-    public static function get_cookie_value( $key, $default_value = '' )
61
-    {
60
+    public static function get_cookie_value( $key, $default_value = '' )
61
+    {
62 62
         return self::get_request_value( 'COOKIE', $key, $default_value );
63 63
     }
64 64
 
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
69 69
      * @return mixed                        The value of the HTTP SERVER for the given $key or the $default.
70 70
      */
71
-    public static function get_server_value( $key, $default_value = '' )
72
-    {
71
+    public static function get_server_value( $key, $default_value = '' )
72
+    {
73 73
         return self::get_request_value( 'SERVER', $key, $default_value );
74 74
     }
75 75
 
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
82 82
      * @return mixed                        The value of the source for the given $key or the $default.
83 83
      */
84
-    public static function get_value_multiple_sources( $key, array $sources, $default_value = null )
85
-    {
86
-        foreach( $sources as $source )
87
-        {
84
+    public static function get_value_multiple_sources( $key, array $sources, $default_value = null )
85
+    {
86
+        foreach( $sources as $source )
87
+        {
88 88
             $value = self::get_request_value( $source, $key, null );
89
-            if( null !== $value )
90
-            {
89
+            if( null !== $value )
90
+            {
91 91
                 return $value;
92 92
             }
93 93
         }
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
      * @param  integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null.
102 102
      * @return integer|mixed                The value of the HTTP POST for the given $key or the $default.
103 103
      */
104
-    public static function get_post_value_int( $key, $default_value = null )
105
-    {
104
+    public static function get_post_value_int( $key, $default_value = null )
105
+    {
106 106
         return self::get_request_value_int( 'POST', $key, $default_value );
107 107
     }
108 108
 
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
      * @param  integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null.
113 113
      * @return integer|mixed                The value of the HTTP GET for the given $key or the $default.
114 114
      */
115
-    public static function get_get_value_int( $key, $default_value = null )
116
-    {
115
+    public static function get_get_value_int( $key, $default_value = null )
116
+    {
117 117
         return self::get_request_value_int( 'GET', $key, $default_value );
118 118
     }
119 119
 
@@ -123,8 +123,8 @@  discard block
 block discarded – undo
123 123
      * @param  integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null.
124 124
      * @return integer|mixed                The value of the HTTP COOKIE for the given $key or the $default.
125 125
      */
126
-    public static function get_cookie_value_int( $key, $default_value = null )
127
-    {
126
+    public static function get_cookie_value_int( $key, $default_value = null )
127
+    {
128 128
         return self::get_request_value_int( 'COOKIE', $key, $default_value );
129 129
     }
130 130
 
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
      * @param  integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null.
135 135
      * @return integer|mixed                The value of the HTTP SERVER for the given $key or the $default.
136 136
      */
137
-    public static function get_server_value_int( $key, $default_value = null )
138
-    {
137
+    public static function get_server_value_int( $key, $default_value = null )
138
+    {
139 139
         return self::get_request_value_int( 'SERVER', $key, $default_value );
140 140
     }
141 141
 
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
      * @param  integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null.
147 147
      * @return integer|mixed                The value of the request method for the given $key or the $default.
148 148
      */
149
-    public static function get_request_value_int( $request_method, $key, $default_value = null )
150
-    {
149
+    public static function get_request_value_int( $request_method, $key, $default_value = null )
150
+    {
151 151
         $value = self::get_request_value( $request_method, $key, null );
152
-        if( self::is_integer_like( $value ) )
153
-        {
152
+        if( self::is_integer_like( $value ) )
153
+        {
154 154
             return (int)$value;
155 155
         }
156 156
 
@@ -164,19 +164,19 @@  discard block
 block discarded – undo
164 164
      * @param  integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null.
165 165
      * @return integer|mixed                The value of the request method for the given $key or the $default.
166 166
      */
167
-    public static function get_request_value( $request_method, $key, $default_value = null )
168
-    {
167
+    public static function get_request_value( $request_method, $key, $default_value = null )
168
+    {
169 169
         $request_obj = self::get_request_object( $request_method );
170 170
 
171
-        if( null === $request_obj || ! is_array( $request_obj ) || ! array_key_exists( $key, $request_obj ) )
172
-        {
171
+        if( null === $request_obj || ! is_array( $request_obj ) || ! array_key_exists( $key, $request_obj ) )
172
+        {
173 173
             return $default_value;
174 174
         }
175 175
 
176 176
         $ret = $request_obj[ $key ];
177 177
 
178
-        if( is_string( $ret ) )
179
-        {
178
+        if( is_string( $ret ) )
179
+        {
180 180
             $ret = trim( $ret );
181 181
         }
182 182
 
@@ -189,35 +189,35 @@  discard block
 block discarded – undo
189 189
      * @param  string    The server method to use, one of GET, POST, SERVER or COOKIE.
190 190
      * @return arra|null The requested array or null.
191 191
      */
192
-    public static function get_request_object( $request_method )
193
-    {
192
+    public static function get_request_object( $request_method )
193
+    {
194 194
         $obj = null;
195
-        switch( $request_method )
196
-        {
195
+        switch( $request_method )
196
+        {
197 197
             case 'GET':
198
-                if( is_array( self::$CUSTOM_GET ) )
199
-                {
198
+                if( is_array( self::$CUSTOM_GET ) )
199
+                {
200 200
                     return self::$CUSTOM_GET;
201 201
                 }
202 202
                 return ( isset( $_GET ) && is_array( $_GET ) && count( $_GET ) > 0 ? $_GET : null );
203 203
 
204 204
             case 'POST':
205
-                if( is_array( self::$CUSTOM_POST ) )
206
-                {
205
+                if( is_array( self::$CUSTOM_POST ) )
206
+                {
207 207
                     return self::$CUSTOM_POST;
208 208
                 }
209 209
                 return ( isset( $_POST ) && is_array( $_POST ) && count( $_POST ) > 0 ? $_POST : null );
210 210
 
211 211
             case 'COOKIE':
212
-                if( is_array( self::$CUSTOM_COOKIE ) )
213
-                {
212
+                if( is_array( self::$CUSTOM_COOKIE ) )
213
+                {
214 214
                     return self::$CUSTOM_COOKIE;
215 215
                 }
216 216
                 return ( isset( $_COOKIE ) && is_array( $_COOKIE ) && count( $_COOKIE ) > 0 ? $_COOKIE : null );
217 217
 
218 218
             case 'SERVER':
219
-                if( is_array( self::$CUSTOM_SERVER ) )
220
-                {
219
+                if( is_array( self::$CUSTOM_SERVER ) )
220
+                {
221 221
                     return self::$CUSTOM_SERVER;
222 222
                 }
223 223
                 return ( isset( $_SERVER ) && is_array( $_SERVER ) && count( $_SERVER ) > 0 ? $_SERVER : null );
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
      * @param  string  $method The server method to test for. Generally one of GET, POST, HEAD, PUT, DELETE.
234 234
      * @return boolean         Returns true if the REQUEST_METHOD server variable is set to the supplied $method, otherwise false.
235 235
      */
236
-    public static function is_request_method( $method )
237
-    {
236
+    public static function is_request_method( $method )
237
+    {
238 238
         return $method === self::get_server_value( 'REQUEST_METHOD' );
239 239
     }
240 240
 
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
      *
249 249
      * @return boolean Returns true if the REQUEST_METHOD server variable is set to POST, otherwise false.
250 250
      */
251
-    public static function is_post( )
252
-    {
251
+    public static function is_post( )
252
+    {
253 253
         return self::is_request_method( 'POST' );
254 254
     }
255 255
 
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
      * @param  mixed  $input The value to test.
262 262
      * @return boolean       True if $input is an integer or a string that contains only digits possibly starting with a dash.
263 263
      */
264
-    public static function is_integer_like( $input )
265
-    {
264
+    public static function is_integer_like( $input )
265
+    {
266 266
         return
267 267
                 is_int( $input )
268 268
                 ||
@@ -281,9 +281,11 @@  discard block
 block discarded – undo
281 281
      * @param  array $parsed_url An array created by urlpieces.
282 282
      * @return string            A URL string.
283 283
      */
284
-    public static function unparse_url( $parsed_url ) {
284
+    public static function unparse_url( $parsed_url )
285
+    {
285 286
         //I don't know what you gave me so you can just have it back
286
-        if( ! is_array( $parsed_url ) ) {
287
+        if( ! is_array( $parsed_url ) )
288
+        {
287 289
             return $parsed_url;
288 290
         }
289 291
         $scheme   = isset( $parsed_url['scheme'])    ?       $parsed_url['scheme'] . '://' : '';
Please login to merge, or discard this patch.