Skip to content

Commit

Permalink
Refactor code, and remove redundant else clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
Gisonrg committed Jan 31, 2016
1 parent 1abdc5e commit 7e96742
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions Symfony/src/Codebender/LibraryBundle/Handler/DefaultHandler.php
Expand Up @@ -54,7 +54,8 @@ public function getLibraryCode($library, $disabled, $renderView = false)
//TODO handle the case of different .h filenames and folder names
if ($filename == "ArduinoRobot") {
$filename = "Robot_Control";
} elseif ($filename == "ArduinoRobotMotorBoard") {
}
if ($filename == "ArduinoRobotMotorBoard") {
$filename = "Robot_Motor";
}
if ($filename == 'BlynkSimpleSerial' || $filename == 'BlynkSimpleCC3000') {
Expand Down Expand Up @@ -197,19 +198,22 @@ public function checkIfBuiltInExists($library)
$arduino_library_files = $this->container->getParameter('builtin_libraries') . "/";
if (is_dir($arduino_library_files . "/libraries/" . $library)) {
return json_encode(array("success" => true, "message" => "Library found"));
} else {
return json_encode(array("success" => false, "message" => "No Library named " . $library . " found."));
}

return json_encode(array("success" => false, "message" => "No Library named " . $library . " found."));
}

public function checkIfExternalExists($library, $getDisabled = false)
{
$lib = $this->entityManager->getRepository('CodebenderLibraryBundle:ExternalLibrary')->findBy(array('machineName' => $library));
$lib = $this->entityManager
->getRepository('CodebenderLibraryBundle:ExternalLibrary')
->findBy(array('machineName' => $library));

if (empty($lib) || (!$getDisabled && !$lib[0]->getActive())) {
return json_encode(array("success" => false, "message" => "No Library named " . $library . " found."));
} else {
return json_encode(array("success" => true, "message" => "Library found"));
}

return json_encode(array("success" => true, "message" => "Library found"));
}

public function fetchLibraryFiles($finder, $directory, $getContent = true)
Expand Down Expand Up @@ -339,7 +343,11 @@ public function getGithubRepoCode($owner, $repo, $branch, $path)
if ($path == '') {
$path = $repo;
}
$libraryContents = array('name' => pathinfo($path, PATHINFO_BASENAME), 'type' => 'dir', 'contents' => array());
$libraryContents = array(
'name' => pathinfo($path, PATHINFO_BASENAME),
'type' => 'dir',
'contents' => array()
);
foreach ($contents as $element) {
if ($element['type'] == 'file') {
$code = $this->getGithubFileCode($owner, $repo, $element['path'], $element['sha']);
Expand Down Expand Up @@ -371,7 +379,7 @@ private function getGithubFileCode($owner, $repo, $path, $blobSha)
$jsonDecodedContent = $this->curlGitRequest($url);

if (json_last_error() != JSON_ERROR_NONE) {
return ['success' => false, 'message' => 'Invalid Git API response (cannot decode)'];
return array('success' => false, 'message' => 'Invalid Git API response (cannot decode)');
}

if (array_key_exists('message', $jsonDecodedContent)) {
Expand Down

0 comments on commit 7e96742

Please sign in to comment.