@@ -36,26 +36,26 @@ public function statusAction()
36
36
public function handleRequestAction ($ authKey , $ version )
37
37
{
38
38
if ($ authKey !== $ this ->container ->getParameter ('authorizationKey ' )) {
39
- return new Response (json_encode (array ( "success " => false , "message " => "Invalid authorization key. " ) ));
39
+ return new Response (json_encode ([ "success " => false , "message " => "Invalid authorization key. " ] ));
40
40
}
41
41
42
42
if ($ version !== $ this ->container ->getParameter ('version ' )) {
43
- return new Response (json_encode (array ( "success " => false , "message " => "Invalid api version. " ) ));
43
+ return new Response (json_encode ([ "success " => false , "message " => "Invalid api version. " ] ));
44
44
}
45
45
46
46
$ request = $ this ->getRequest ()->getContent ();
47
47
if (empty ($ request )) {
48
- return new Response (json_encode (array ( "success " => false , "message " => "Invalid input. " ) ));
48
+ return new Response (json_encode ([ "success " => false , "message " => "Invalid input. " ] ));
49
49
}
50
50
51
51
$ contents = json_decode ($ request , true );
52
52
53
53
if (json_last_error () !== JSON_ERROR_NONE ) {
54
- return new Response (json_encode (array ( "success " => false , "message " => "Wrong data. " ) ));
54
+ return new Response (json_encode ([ "success " => false , "message " => "Wrong data. " ] ));
55
55
}
56
56
57
57
if (!array_key_exists ("data " , $ contents )) {
58
- return new Response (json_encode (array ( "success " => false , "message " => "Insufficient data provided. " ) ));
58
+ return new Response (json_encode ([ "success " => false , "message " => "Insufficient data provided. " ] ));
59
59
}
60
60
61
61
if ($ contents ["type " ] == "compiler " ) {
@@ -66,7 +66,13 @@ public function handleRequestAction($authKey, $version)
66
66
return new Response ($ this ->getLibraryInfo (json_encode ($ contents ["data " ])));
67
67
}
68
68
69
- return new Response (json_encode (array ("success " => false , "message " => "Invalid request type (can handle only 'compiler' or 'library' requests) " )));
69
+ return new Response (
70
+ json_encode (
71
+ [
72
+ "success " => false ,
73
+ "message " => "Invalid request type (can handle only 'compiler' or 'library' requests) "
74
+ ]
75
+ ));
70
76
}
71
77
72
78
/**
@@ -85,7 +91,7 @@ protected function compile($contents)
85
91
86
92
$ files = $ contents ["files " ];
87
93
88
- $ userLibraries = array () ;
94
+ $ userLibraries = [] ;
89
95
90
96
if (array_key_exists ('libraries ' , $ contents )) {
91
97
$ userLibraries = $ contents ['libraries ' ];
@@ -102,7 +108,7 @@ protected function compile($contents)
102
108
103
109
$ decodedResponse = json_decode ($ data , true );
104
110
if (json_last_error () !== JSON_ERROR_NONE ) {
105
- return json_encode (array ( "success " => false , "message " => "Failed to get compiler response. " ) );
111
+ return json_encode ([ "success " => false , "message " => "Failed to get compiler response. " ] );
106
112
}
107
113
108
114
if ($ decodedResponse ["success " ] === false && !array_key_exists ("step " , $ decodedResponse )) {
@@ -146,15 +152,16 @@ protected function returnProvidedAndFetchedLibraries($projectFiles, $userLibrari
146
152
$ detectedHeaders = $ apiHandler ->readLibraries ($ projectFiles );
147
153
148
154
// declare arrays
149
- $ notFoundHeaders = array () ;
150
- $ foundHeaders = array () ;
151
- $ librariesFromLibman = array () ;
155
+ $ notFoundHeaders = [] ;
156
+ $ foundHeaders = [] ;
157
+ $ librariesFromLibman = [] ;
152
158
$ providedLibraries = array_keys ($ userLibraries );
153
159
$ libraries = $ userLibraries ;
154
160
155
161
foreach ($ detectedHeaders as $ header ) {
156
162
157
163
$ existsInRequest = false ;
164
+ // TODO We can do this in a better way
158
165
foreach ($ userLibraries as $ library ) {
159
166
foreach ($ library as $ libraryContent ) {
160
167
if ($ libraryContent ["filename " ] == $ header .".h " ) {
@@ -167,7 +174,7 @@ protected function returnProvidedAndFetchedLibraries($projectFiles, $userLibrari
167
174
if ($ existsInRequest === true ) {
168
175
continue ;
169
176
}
170
- $ requestContent = array ( "type " => "fetch " , "library " => $ header) ;
177
+ $ requestContent = [ "type " => "fetch " , "library " => $ header] ;
171
178
$ data = $ this ->getLibraryInfo (json_encode ($ requestContent ));
172
179
$ data = json_decode ($ data , true );
173
180
@@ -178,26 +185,27 @@ protected function returnProvidedAndFetchedLibraries($projectFiles, $userLibrari
178
185
179
186
$ foundHeaders [] = $ header . ".h " ;
180
187
$ librariesFromLibman [] = $ header ;
181
- $ filesToBeAdded = array () ;
188
+ $ filesToBeAdded = [] ;
182
189
foreach ($ data ["files " ] as $ file ) {
183
190
if (in_array (pathinfo ($ file ['filename ' ], PATHINFO_EXTENSION ), array ('cpp ' , 'h ' , 'c ' , 'S ' , 'inc ' )))
184
191
$ filesToBeAdded [] = $ file ;
185
192
}
186
193
$ libraries [$ header ] = $ filesToBeAdded ;
187
194
}
188
195
189
- return array (
196
+ return [
190
197
'libraries ' => $ libraries ,
191
198
'providedLibraries ' => $ providedLibraries ,
192
199
'fetchedLibraries ' => $ librariesFromLibman ,
193
200
'detectedHeaders ' => $ detectedHeaders ,
194
201
'foundHeaders ' => $ foundHeaders ,
195
- 'notFoundHeaders ' => $ notFoundHeaders );
202
+ 'notFoundHeaders ' => $ notFoundHeaders
203
+ ];
196
204
}
197
205
198
206
/**
199
- * Checks if project id and user id txt files exist in the request files .
200
- * If not, creates these files with null id
207
+ * Checks if project id and user id exist in the request.
208
+ * If not, adds the fields with null id
201
209
*
202
210
* @param array $requestContents
203
211
* @return array
0 commit comments