Completed
Pull Request — master (#313)
by Thomas
18:19 queued 08:41
created
htdocs/okapi/services/caches/mark.php 1 patch
Braces   +21 added lines, -18 removed lines patch added patch discarded remove patch
@@ -31,55 +31,58 @@
 block discarded – undo
31 31
         # on it - this will also throw a proper exception if it doesn't exist.
32 32
 
33 33
         $cache_code = $request->get_parameter('cache_code');
34
-        if ($cache_code == null)
35
-            throw new ParamMissing('cache_code');
34
+        if ($cache_code == null) {
35
+                    throw new ParamMissing('cache_code');
36
+        }
36 37
         $geocache = OkapiServiceRunner::call('services/caches/geocache', new OkapiInternalRequest(
37 38
             $request->consumer, $request->token, array('cache_code' => $cache_code, 'fields' => 'internal_id')));
38 39
 
39 40
         # watched
40 41
 
41
-        if ($tmp = $request->get_parameter('watched'))
42
-        {
43
-            if (!in_array($tmp, array('true', 'false', 'unchanged')))
44
-                throw new InvalidParam('watched', $tmp);
45
-            if ($tmp == 'true')
46
-                Db::execute("
42
+        if ($tmp = $request->get_parameter('watched')) {
43
+            if (!in_array($tmp, array('true', 'false', 'unchanged'))) {
44
+                            throw new InvalidParam('watched', $tmp);
45
+            }
46
+            if ($tmp == 'true') {
47
+                            Db::execute("
47 48
                     insert ignore into cache_watches (cache_id, user_id)
48 49
                     values (
49 50
                         '".Db::escape_string($geocache['internal_id'])."',
50 51
                         '".Db::escape_string($request->token->user_id)."'
51 52
                     );
52 53
                 ");
53
-            elseif ($tmp == 'false')
54
-                Db::execute("
54
+            } elseif ($tmp == 'false') {
55
+                            Db::execute("
55 56
                     delete from cache_watches
56 57
                     where
57 58
                         cache_id = '".Db::escape_string($geocache['internal_id'])."'
58 59
                         and user_id = '".Db::escape_string($request->token->user_id)."';
59 60
                 ");
61
+            }
60 62
         }
61 63
 
62 64
         # ignored
63 65
 
64
-        if ($tmp = $request->get_parameter('ignored'))
65
-        {
66
-            if (!in_array($tmp, array('true', 'false', 'unchanged')))
67
-                throw new InvalidParam('ignored', $tmp);
68
-            if ($tmp == 'true')
69
-                Db::execute("
66
+        if ($tmp = $request->get_parameter('ignored')) {
67
+            if (!in_array($tmp, array('true', 'false', 'unchanged'))) {
68
+                            throw new InvalidParam('ignored', $tmp);
69
+            }
70
+            if ($tmp == 'true') {
71
+                            Db::execute("
70 72
                     insert ignore into cache_ignore (cache_id, user_id)
71 73
                     values (
72 74
                         '".Db::escape_string($geocache['internal_id'])."',
73 75
                         '".Db::escape_string($request->token->user_id)."'
74 76
                     );
75 77
                 ");
76
-            elseif ($tmp == 'false')
77
-                Db::execute("
78
+            } elseif ($tmp == 'false') {
79
+                            Db::execute("
78 80
                     delete from cache_ignore
79 81
                     where
80 82
                         cache_id = '".Db::escape_string($geocache['internal_id'])."'
81 83
                         and user_id = '".Db::escape_string($request->token->user_id)."'
82 84
                 ");
85
+            }
83 86
         }
84 87
 
85 88
         $result = array(
Please login to merge, or discard this patch.
htdocs/okapi/services/users/by_internal_ids.php 1 patch
Braces   +16 added lines, -13 removed lines patch added patch discarded remove patch
@@ -23,14 +23,18 @@  discard block
 block discarded – undo
23 23
     public static function call(OkapiRequest $request)
24 24
     {
25 25
         $internal_ids = $request->get_parameter('internal_ids');
26
-        if (!$internal_ids) throw new ParamMissing('internal_ids');
26
+        if (!$internal_ids) {
27
+            throw new ParamMissing('internal_ids');
28
+        }
27 29
         $internal_ids = explode("|", $internal_ids);
28
-        if (count($internal_ids) > 500)
29
-            throw new InvalidParam('internal_ids', "Maximum allowed number of referenced users ".
30
+        if (count($internal_ids) > 500) {
31
+                    throw new InvalidParam('internal_ids', "Maximum allowed number of referenced users ".
30 32
                 "is 500. You provided ".count($internal_ids)." references.");
33
+        }
31 34
         $fields = $request->get_parameter('fields');
32
-        if (!$fields)
33
-            throw new ParamMissing('fields');
35
+        if (!$fields) {
36
+                    throw new ParamMissing('fields');
37
+        }
34 38
 
35 39
         # There's no need to validate the fields parameter as the 'users'
36 40
         # method does this (it will raise a proper exception on invalid values).
@@ -41,8 +45,7 @@  discard block
 block discarded – undo
41 45
             where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', $internal_ids))."')
42 46
         ");
43 47
         $internalid2useruuid = array();
44
-        while ($row = Db::fetch_assoc($rs))
45
-        {
48
+        while ($row = Db::fetch_assoc($rs)) {
46 49
             $internalid2useruuid[$row['user_id']] = $row['uuid'];
47 50
         }
48 51
         Db::free_result($rs);
@@ -55,12 +58,12 @@  discard block
 block discarded – undo
55 58
         # Map user_uuids to internal_ids. Also check which internal_ids were not found
56 59
         # and mark them with null.
57 60
         $results = array();
58
-        foreach ($internal_ids as $internal_id)
59
-        {
60
-            if (!isset($internalid2useruuid[$internal_id]))
61
-                $results[$internal_id] = null;
62
-            else
63
-                $results[$internal_id] = $id_results[$internalid2useruuid[$internal_id]];
61
+        foreach ($internal_ids as $internal_id) {
62
+            if (!isset($internalid2useruuid[$internal_id])) {
63
+                            $results[$internal_id] = null;
64
+            } else {
65
+                            $results[$internal_id] = $id_results[$internalid2useruuid[$internal_id]];
66
+            }
64 67
         }
65 68
 
66 69
         return Okapi::formatted_response($request, $results);
Please login to merge, or discard this patch.
htdocs/okapi/services/users/user.php 1 patch
Braces   +6 added lines, -9 removed lines patch added patch discarded remove patch
@@ -26,16 +26,12 @@  discard block
 block discarded – undo
26 26
     public static function call(OkapiRequest $request)
27 27
     {
28 28
         $user_uuid = $request->get_parameter('user_uuid');
29
-        if (!$user_uuid)
30
-        {
31
-            if ($request->token)
32
-            {
29
+        if (!$user_uuid) {
30
+            if ($request->token) {
33 31
                 $tmp = OkapiServiceRunner::call('services/users/by_internal_id', new OkapiInternalRequest(
34 32
                     $request->consumer, null, array('internal_id' => $request->token->user_id, 'fields' => 'uuid')));
35 33
                 $user_uuid = $tmp['uuid'];
36
-            }
37
-            else
38
-            {
34
+            } else {
39 35
                 throw new BadRequest("You must either: 1. supply the user_uuid argument, or "
40 36
                     ."2. sign your request with an Access Token.");
41 37
             }
@@ -49,8 +45,9 @@  discard block
 block discarded – undo
49 45
             $request->consumer, $request->token, array('user_uuids' => $user_uuid,
50 46
             'fields' => $fields)));
51 47
         $result = $results[$user_uuid];
52
-        if ($result == null)
53
-            throw new InvalidParam('user_uuid', "There is no user by this ID.");
48
+        if ($result == null) {
49
+                    throw new InvalidParam('user_uuid', "There is no user by this ID.");
50
+        }
54 51
         return Okapi::formatted_response($request, $result);
55 52
     }
56 53
 }
Please login to merge, or discard this patch.
htdocs/okapi/services/users/by_usernames.php 1 patch
Braces   +17 added lines, -15 removed lines patch added patch discarded remove patch
@@ -24,14 +24,18 @@  discard block
 block discarded – undo
24 24
     public static function call(OkapiRequest $request)
25 25
     {
26 26
         $usernames = $request->get_parameter('usernames');
27
-        if (!$usernames) throw new ParamMissing('usernames');
27
+        if (!$usernames) {
28
+            throw new ParamMissing('usernames');
29
+        }
28 30
         $usernames = explode("|", $usernames);
29
-        if (count($usernames) > 500)
30
-            throw new InvalidParam('usernames', "Maximum allowed number of referenced users ".
31
+        if (count($usernames) > 500) {
32
+                    throw new InvalidParam('usernames', "Maximum allowed number of referenced users ".
31 33
                 "is 500. You provided ".count($usernames)." usernames.");
34
+        }
32 35
         $fields = $request->get_parameter('fields');
33
-        if (!$fields)
34
-            throw new ParamMissing('fields');
36
+        if (!$fields) {
37
+                    throw new ParamMissing('fields');
38
+        }
35 39
 
36 40
         # There's no need to validate the fields parameter as the 'users'
37 41
         # method does this (it will raise a proper exception on invalid values).
@@ -42,16 +46,14 @@  discard block
 block discarded – undo
42 46
             where username collate ".Settings::get('DB_CHARSET')."_general_ci in ('".implode("','", array_map('\okapi\Db::escape_string', $usernames))."')
43 47
         ");
44 48
         $lower_username2useruuid = array();
45
-        while ($row = Db::fetch_assoc($rs))
46
-        {
49
+        while ($row = Db::fetch_assoc($rs)) {
47 50
             $lower_username2useruuid[mb_strtolower($row['username'], 'utf-8')] = $row['uuid'];
48 51
         }
49 52
         Db::free_result($rs);
50 53
 
51 54
         # Retrieve data for the found user_uuids.
52 55
 
53
-        if (count($lower_username2useruuid) > 0)
54
-        {
56
+        if (count($lower_username2useruuid) > 0) {
55 57
             $id_results = OkapiServiceRunner::call('services/users/users', new OkapiInternalRequest(
56 58
                 $request->consumer, $request->token, array('user_uuids' => implode("|", array_values($lower_username2useruuid)),
57 59
                 'fields' => $fields)));
@@ -63,12 +65,12 @@  discard block
 block discarded – undo
63 65
         # and mark them with null.
64 66
 
65 67
         $results = array();
66
-        foreach ($usernames as $username)
67
-        {
68
-            if (!isset($lower_username2useruuid[mb_strtolower($username, 'utf-8')]))
69
-                $results[$username] = null;
70
-            else
71
-                $results[$username] = $id_results[$lower_username2useruuid[mb_strtolower($username, 'utf-8')]];
68
+        foreach ($usernames as $username) {
69
+            if (!isset($lower_username2useruuid[mb_strtolower($username, 'utf-8')])) {
70
+                            $results[$username] = null;
71
+            } else {
72
+                            $results[$username] = $id_results[$lower_username2useruuid[mb_strtolower($username, 'utf-8')]];
73
+            }
72 74
         }
73 75
 
74 76
         return Okapi::formatted_response($request, $results);
Please login to merge, or discard this patch.
htdocs/okapi/services/apiref/issue.php 1 patch
Braces   +9 added lines, -11 removed lines patch added patch discarded remove patch
@@ -26,19 +26,19 @@  discard block
 block discarded – undo
26 26
     public static function call(OkapiRequest $request)
27 27
     {
28 28
         $issue_id = $request->get_parameter('issue_id');
29
-        if (!$issue_id)
30
-            throw new ParamMissing('issue_id');
31
-        if ((!preg_match("/^[0-9]+$/", $issue_id)) || (strlen($issue_id) > 6))
32
-            throw new InvalidParam('issue_id');
29
+        if (!$issue_id) {
30
+                    throw new ParamMissing('issue_id');
31
+        }
32
+        if ((!preg_match("/^[0-9]+$/", $issue_id)) || (strlen($issue_id) > 6)) {
33
+                    throw new InvalidParam('issue_id');
34
+        }
33 35
 
34 36
         $cache_key = "apiref/issue#".$issue_id;
35 37
         $result = Cache::get($cache_key);
36
-        if ($result == null)
37
-        {
38
+        if ($result == null) {
38 39
             # Download the number of comments from GitHub Issue Tracker.
39 40
 
40
-            try
41
-            {
41
+            try {
42 42
                 $extra_headers = array();
43 43
                 $extra_headers[] = "Accept: application/vnd.github.v3.html+json";
44 44
                 $extra_headers[] = "User-Agent: https://github.com/opencaching/okapi/";
@@ -55,9 +55,7 @@  discard block
 block discarded – undo
55 55
                 $context = stream_context_create($opts);
56 56
                 $json = file_get_contents("https://api.github.com/repos/opencaching/okapi/issues/$issue_id",
57 57
                     false, $context);
58
-            }
59
-            catch (ErrorException $e)
60
-            {
58
+            } catch (ErrorException $e) {
61 59
                 throw new BadRequest("Sorry, we could not retrieve issue stats from the GitHub site. ".
62 60
                     "This is probably due to a temporary connection problem. Try again later or contact ".
63 61
                     "us if this seems permanent.");
Please login to merge, or discard this patch.
htdocs/okapi/services/apiref/method.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -185,14 +185,14 @@
 block discarded – undo
185 185
                 if (($include_list === null) && (count($exclude_list) == 0))
186 186
                 {
187 187
                     $arg['description'] = "<i>Inherited from <a href='".$referenced_method_info['ref_url'].
188
-                        "#arg_". $arg['name'] . "'>".$referenced_method_info['name']."</a> method.</i>";
188
+                        "#arg_".$arg['name']."'>".$referenced_method_info['name']."</a> method.</i>";
189 189
                 }
190 190
                 elseif (
191 191
                     (($include_list === null) || in_array($arg['name'], $include_list))
192 192
                     && (!in_array($arg['name'], $exclude_list))
193 193
                 ) {
194 194
                     $arg['description'] = "<i>Same as in the <a href='".$referenced_method_info['ref_url'].
195
-                        "#arg_". $arg['name'] . "'>".$referenced_method_info['name']."</a> method.</i>";
195
+                        "#arg_".$arg['name']."'>".$referenced_method_info['name']."</a> method.</i>";
196 196
                 } else {
197 197
                     continue;
198 198
                 }
Please login to merge, or discard this patch.
Braces   +51 added lines, -44 removed lines patch added patch discarded remove patch
@@ -102,12 +102,10 @@  discard block
 block discarded – undo
102 102
             case 'methodretref':
103 103
                 $elements = explode('#', $arr[1]);
104 104
                 $result = '';
105
-                if ($elements[0] != '')
106
-                {
105
+                if ($elements[0] != '') {
107 106
                     $result .= Settings::get('SITE_URL')."okapi/".$elements[0].'.html';
108 107
                 }
109
-                if (count($elements) > 1)
110
-                {
108
+                if (count($elements) > 1) {
111 109
                     $result .= '#';
112 110
                     switch ($plugin_name) {
113 111
                         case 'methodargref':
@@ -128,15 +126,19 @@  discard block
 block discarded – undo
128 126
     public static function call(OkapiRequest $request)
129 127
     {
130 128
         $methodname = $request->get_parameter('name');
131
-        if (!$methodname)
132
-            throw new ParamMissing('name');
133
-        if (!preg_match("#^services/[0-9a-z_/]*$#", $methodname))
134
-            throw new InvalidParam('name');
135
-        if (!OkapiServiceRunner::exists($methodname))
136
-            throw new InvalidParam('name', "Method does not exist: '$methodname'.");
129
+        if (!$methodname) {
130
+                    throw new ParamMissing('name');
131
+        }
132
+        if (!preg_match("#^services/[0-9a-z_/]*$#", $methodname)) {
133
+                    throw new InvalidParam('name');
134
+        }
135
+        if (!OkapiServiceRunner::exists($methodname)) {
136
+                    throw new InvalidParam('name', "Method does not exist: '$methodname'.");
137
+        }
137 138
         $options = OkapiServiceRunner::options($methodname);
138
-        if (!isset($options['min_auth_level']))
139
-            throw new Exception("Method $methodname is missing a required 'min_auth_level' option!");
139
+        if (!isset($options['min_auth_level'])) {
140
+                    throw new Exception("Method $methodname is missing a required 'min_auth_level' option!");
141
+        }
140 142
         $docs = simplexml_load_string(OkapiServiceRunner::docs($methodname));
141 143
         $exploded = explode("/", $methodname);
142 144
         $result = array(
@@ -149,45 +151,49 @@  discard block
 block discarded – undo
149 151
                 'oauth_token' => $options['min_auth_level'] >= 3,
150 152
             )
151 153
         );
152
-        if (!$docs->brief)
153
-            throw new Exception("Missing <brief> element in the $methodname.xml file.");
154
-        if ($docs->brief != self::get_inner_xml($docs->brief))
155
-            throw new Exception("The <brief> element may not contain HTML markup ($methodname.xml).");
156
-        if (strlen($docs->brief) > 80)
157
-            throw new Exception("The <brief> description may not be longer than 80 characters ($methodname.xml).");
158
-        if (strpos($docs->brief, "\n") !== false)
159
-            throw new Exception("The <brief> element may not contain new-lines ($methodname.xml).");
160
-        if (substr(trim($docs->brief), -1) == '.')
161
-            throw new Exception("The <brief> element should not end with a dot ($methodname.xml).");
154
+        if (!$docs->brief) {
155
+                    throw new Exception("Missing <brief> element in the $methodname.xml file.");
156
+        }
157
+        if ($docs->brief != self::get_inner_xml($docs->brief)) {
158
+                    throw new Exception("The <brief> element may not contain HTML markup ($methodname.xml).");
159
+        }
160
+        if (strlen($docs->brief) > 80) {
161
+                    throw new Exception("The <brief> description may not be longer than 80 characters ($methodname.xml).");
162
+        }
163
+        if (strpos($docs->brief, "\n") !== false) {
164
+                    throw new Exception("The <brief> element may not contain new-lines ($methodname.xml).");
165
+        }
166
+        if (substr(trim($docs->brief), -1) == '.') {
167
+                    throw new Exception("The <brief> element should not end with a dot ($methodname.xml).");
168
+        }
162 169
         $result['brief_description'] = self::get_inner_xml($docs->brief);
163
-        if ($docs->{'issue-id'})
164
-            $result['issue_id'] = (string)$docs->{'issue-id'};
165
-        else
166
-            $result['issue_id'] = null;
167
-        if (!$docs->desc)
168
-            throw new Exception("Missing <desc> element in the $methodname.xml file.");
170
+        if ($docs->{'issue-id'}) {
171
+                    $result['issue_id'] = (string)$docs->{'issue-id'};
172
+        } else {
173
+                    $result['issue_id'] = null;
174
+        }
175
+        if (!$docs->desc) {
176
+                    throw new Exception("Missing <desc> element in the $methodname.xml file.");
177
+        }
169 178
         $result['description'] = self::get_inner_xml($docs->desc);
170 179
         $result['arguments'] = array();
171 180
         foreach ($docs->req as $arg) { $result['arguments'][] = self::arg_desc($arg); }
172 181
         foreach ($docs->opt as $arg) { $result['arguments'][] = self::arg_desc($arg); }
173
-        foreach ($docs->{'import-params'} as $import_desc)
174
-        {
182
+        foreach ($docs->{'import-params'} as $import_desc) {
175 183
             $attrs = $import_desc->attributes();
176 184
             $referenced_methodname = $attrs['method'];
177 185
             $referenced_method_info = OkapiServiceRunner::call('services/apiref/method',
178 186
                 new OkapiInternalRequest(new OkapiInternalConsumer(), null, array('name' => $referenced_methodname)));
179 187
             $include_list = isset($attrs['params']) ? explode("|", $attrs['params']) : null;
180 188
             $exclude_list = isset($attrs['except']) ? explode("|", $attrs['except']) : array();
181
-            foreach ($referenced_method_info['arguments'] as $arg)
182
-            {
183
-                if ($arg['class'] == 'common-formatting')
184
-                    continue;
185
-                if (($include_list === null) && (count($exclude_list) == 0))
186
-                {
189
+            foreach ($referenced_method_info['arguments'] as $arg) {
190
+                if ($arg['class'] == 'common-formatting') {
191
+                                    continue;
192
+                }
193
+                if (($include_list === null) && (count($exclude_list) == 0)) {
187 194
                     $arg['description'] = "<i>Inherited from <a href='".$referenced_method_info['ref_url'].
188 195
                         "#arg_". $arg['name'] . "'>".$referenced_method_info['name']."</a> method.</i>";
189
-                }
190
-                elseif (
196
+                } elseif (
191 197
                     (($include_list === null) || in_array($arg['name'], $include_list))
192 198
                     && (!in_array($arg['name'], $exclude_list))
193 199
                 ) {
@@ -200,8 +206,7 @@  discard block
 block discarded – undo
200 206
                 $result['arguments'][] = $arg;
201 207
             }
202 208
         }
203
-        if ($docs->{'common-format-params'})
204
-        {
209
+        if ($docs->{'common-format-params'}) {
205 210
             $result['arguments'][] = array(
206 211
                 'name' => 'format',
207 212
                 'is_required' => false,
@@ -217,12 +222,14 @@  discard block
 block discarded – undo
217 222
                 'description' => "<i>Standard <a href='".Settings::get('SITE_URL')."okapi/introduction.html#common-formatting'>common formatting</a> argument.</i>"
218 223
             );
219 224
         }
220
-        foreach ($result['arguments'] as &$arg_ref)
221
-            if ($arg_ref['is_deprecated'])
225
+        foreach ($result['arguments'] as &$arg_ref) {
226
+                    if ($arg_ref['is_deprecated'])
222 227
                 $arg_ref['class'] .= " deprecated";
223
-        if (!$docs->returns)
224
-            throw new Exception("Missing <returns> element in the $methodname.xml file. ".
228
+        }
229
+        if (!$docs->returns) {
230
+                    throw new Exception("Missing <returns> element in the $methodname.xml file. ".
225 231
                 "If your method does not return anything, you should document in nonetheless.");
232
+        }
226 233
         $result['returns'] = self::get_inner_xml($docs->returns);
227 234
         return Okapi::formatted_response($request, $result);
228 235
     }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@
 block discarded – undo
136 136
             throw new InvalidParam('name', "Method does not exist: '$methodname'.");
137 137
         $options = OkapiServiceRunner::options($methodname);
138 138
         if (!isset($options['min_auth_level']))
139
-            throw new Exception("Method $methodname is missing a required 'min_auth_level' option!");
139
+            throw new Exception("method $methodname is missing a required 'min_auth_level' option!");
140 140
         $docs = simplexml_load_string(OkapiServiceRunner::docs($methodname));
141 141
         $exploded = explode("/", $methodname);
142 142
         $result = array(
Please login to merge, or discard this patch.
htdocs/okapi/services/apiref/method_index.php 1 patch
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,11 +28,9 @@
 block discarded – undo
28 28
         sort($methodnames);
29 29
         $cache_key = "api_ref/method_index#".md5(implode("#", $methodnames));
30 30
         $results = Cache::get($cache_key);
31
-        if ($results == null)
32
-        {
31
+        if ($results == null) {
33 32
             $results = array();
34
-            foreach ($methodnames as $methodname)
35
-            {
33
+            foreach ($methodnames as $methodname) {
36 34
                 $info = OkapiServiceRunner::call('services/apiref/method', new OkapiInternalRequest(
37 35
                     new OkapiInternalConsumer(), null, array('name' => $methodname)));
38 36
                 $results[] = array(
Please login to merge, or discard this patch.
htdocs/okapi/services/apisrv/stats.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,8 +26,7 @@
 block discarded – undo
26 26
     {
27 27
         $cachekey = "apisrv/stats";
28 28
         $result = Cache::get($cachekey);
29
-        if (!$result)
30
-        {
29
+        if (!$result) {
31 30
             $result = array(
32 31
                 'cache_count' => 0 + Db::select_value("
33 32
                     select count(*) from caches where status in (1,2,3)
Please login to merge, or discard this patch.
htdocs/okapi/services/apisrv/installations.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@
 block discarded – undo
113 113
             # Cache it for one day. Also, save a backup (valid for 30 days).
114 114
 
115 115
             Cache::set($cachekey, $results, 86400);
116
-            Cache::set($backupkey, $results, 86400*30);
116
+            Cache::set($backupkey, $results, 86400 * 30);
117 117
         }
118 118
 
119 119
         return Okapi::formatted_response($request, $results);
Please login to merge, or discard this patch.
Braces   +19 added lines, -23 removed lines patch added patch discarded remove patch
@@ -30,12 +30,10 @@  discard block
 block discarded – undo
30 30
         $cachekey = 'apisrv/installations';
31 31
         $backupkey = 'apisrv/installations-backup';
32 32
         $results = Cache::get($cachekey);
33
-        if (!$results)
34
-        {
33
+        if (!$results) {
35 34
             # Download the current list of OKAPI servers.
36 35
 
37
-            try
38
-            {
36
+            try {
39 37
                 $opts = array(
40 38
                     'http' => array(
41 39
                         'method' => "GET",
@@ -49,14 +47,11 @@  discard block
 block discarded – undo
49 47
                 if (!$doc) {
50 48
                     throw new ErrorException(); # just to get to the catch block
51 49
                 }
52
-            }
53
-            catch (ErrorException $e)
54
-            {
50
+            } catch (ErrorException $e) {
55 51
                 # GitHub failed on us. Try to respond with a backup list.
56 52
 
57 53
                 $results = Cache::get($backupkey);
58
-                if ($results)
59
-                {
54
+                if ($results) {
60 55
                     Cache::set($cachekey, $results, 12 * 3600); # so to retry no earlier than after 12 hours
61 56
                     return Okapi::formatted_response($request, $results);
62 57
                 }
@@ -77,31 +72,32 @@  discard block
 block discarded – undo
77 72
 
78 73
             $results = array();
79 74
             $i_was_included = false;
80
-            foreach ($doc->installation as $inst)
81
-            {
75
+            foreach ($doc->installation as $inst) {
82 76
                 $site_url = (string)$inst[0]['site_url'];
83
-                if ($inst[0]['okapi_base_url'])
84
-                    $okapi_base_url = (string)$inst[0]['okapi_base_url'];
85
-                else
86
-                    $okapi_base_url = $site_url."okapi/";
87
-                if ($inst[0]['site_name'])
88
-                    $site_name = (string)$inst[0]['site_name'];
89
-                else
90
-                    $site_name = Okapi::get_normalized_site_name($site_url);
77
+                if ($inst[0]['okapi_base_url']) {
78
+                                    $okapi_base_url = (string)$inst[0]['okapi_base_url'];
79
+                } else {
80
+                                    $okapi_base_url = $site_url."okapi/";
81
+                }
82
+                if ($inst[0]['site_name']) {
83
+                                    $site_name = (string)$inst[0]['site_name'];
84
+                } else {
85
+                                    $site_name = Okapi::get_normalized_site_name($site_url);
86
+                }
91 87
                 $results[] = array(
92 88
                     'site_url' => $site_url,
93 89
                     'site_name' => $site_name,
94 90
                     'okapi_base_url' => $okapi_base_url,
95 91
                 );
96
-                if ($site_url == Settings::get('SITE_URL'))
97
-                    $i_was_included = true;
92
+                if ($site_url == Settings::get('SITE_URL')) {
93
+                                    $i_was_included = true;
94
+                }
98 95
             }
99 96
 
100 97
             # If running on a local development installation, then include the local
101 98
             # installation URL.
102 99
 
103
-            if (!$i_was_included)
104
-            {
100
+            if (!$i_was_included) {
105 101
                 $results[] = array(
106 102
                     'site_url' => Settings::get('SITE_URL'),
107 103
                     'site_name' => "DEVELSITE",
Please login to merge, or discard this patch.