Skip to content

Commit 4d71b85

Browse files
committed
PHP 5.5 arrays, added TODO, updated outdated comment
1 parent 0cc74ac commit 4d71b85

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

Symfony/src/Codebender/BuilderBundle/Controller/DefaultController.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,26 @@ public function statusAction()
3636
public function handleRequestAction($authKey, $version)
3737
{
3838
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."]));
4040
}
4141

4242
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."]));
4444
}
4545

4646
$request = $this->getRequest()->getContent();
4747
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."]));
4949
}
5050

5151
$contents = json_decode($request, true);
5252

5353
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."]));
5555
}
5656

5757
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."]));
5959
}
6060

6161
if ($contents["type"] == "compiler") {
@@ -66,7 +66,13 @@ public function handleRequestAction($authKey, $version)
6666
return new Response($this->getLibraryInfo(json_encode($contents["data"])));
6767
}
6868

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+
));
7076
}
7177

7278
/**
@@ -85,7 +91,7 @@ protected function compile($contents)
8591

8692
$files = $contents["files"];
8793

88-
$userLibraries = array();
94+
$userLibraries = [];
8995

9096
if (array_key_exists('libraries', $contents)) {
9197
$userLibraries = $contents['libraries'];
@@ -102,7 +108,7 @@ protected function compile($contents)
102108

103109
$decodedResponse = json_decode($data, true);
104110
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."]);
106112
}
107113

108114
if ($decodedResponse["success"] === false && !array_key_exists("step", $decodedResponse)) {
@@ -146,15 +152,16 @@ protected function returnProvidedAndFetchedLibraries($projectFiles, $userLibrari
146152
$detectedHeaders = $apiHandler->readLibraries($projectFiles);
147153

148154
// declare arrays
149-
$notFoundHeaders = array();
150-
$foundHeaders = array();
151-
$librariesFromLibman = array();
155+
$notFoundHeaders = [];
156+
$foundHeaders = [];
157+
$librariesFromLibman = [];
152158
$providedLibraries = array_keys($userLibraries);
153159
$libraries = $userLibraries;
154160

155161
foreach ($detectedHeaders as $header) {
156162

157163
$existsInRequest = false;
164+
// TODO We can do this in a better way
158165
foreach ($userLibraries as $library) {
159166
foreach ($library as $libraryContent) {
160167
if ($libraryContent["filename"] == $header.".h") {
@@ -167,7 +174,7 @@ protected function returnProvidedAndFetchedLibraries($projectFiles, $userLibrari
167174
if ($existsInRequest === true) {
168175
continue;
169176
}
170-
$requestContent = array("type" => "fetch", "library" => $header);
177+
$requestContent = ["type" => "fetch", "library" => $header];
171178
$data = $this->getLibraryInfo(json_encode($requestContent));
172179
$data = json_decode($data, true);
173180

@@ -178,26 +185,27 @@ protected function returnProvidedAndFetchedLibraries($projectFiles, $userLibrari
178185

179186
$foundHeaders[] = $header . ".h";
180187
$librariesFromLibman[] = $header;
181-
$filesToBeAdded = array();
188+
$filesToBeAdded = [];
182189
foreach ($data["files"] as $file) {
183190
if (in_array(pathinfo($file['filename'], PATHINFO_EXTENSION), array('cpp', 'h', 'c', 'S', 'inc')))
184191
$filesToBeAdded[] = $file;
185192
}
186193
$libraries[$header] = $filesToBeAdded;
187194
}
188195

189-
return array(
196+
return [
190197
'libraries' => $libraries,
191198
'providedLibraries' => $providedLibraries,
192199
'fetchedLibraries' => $librariesFromLibman,
193200
'detectedHeaders'=> $detectedHeaders,
194201
'foundHeaders' => $foundHeaders,
195-
'notFoundHeaders' => $notFoundHeaders);
202+
'notFoundHeaders' => $notFoundHeaders
203+
];
196204
}
197205

198206
/**
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
201209
*
202210
* @param array $requestContents
203211
* @return array

0 commit comments

Comments
 (0)