From d19438bad12ad06ab6374024b88784259a5f5f2f Mon Sep 17 00:00:00 2001 From: Juan Date: Wed, 23 May 2018 13:09:55 +0200 Subject: [PATCH] PHP linting, bugs fixed --- debian/changelog | 2 +- package.json | 2 +- rest/core/account.php | 9 +++------ rest/core/login.php | 3 +-- rest/core/query.php | 9 +++------ rest/dms/add.php | 3 +-- rest/edi/clean.php | 3 +-- rest/edi/lib/message.php | 9 +++------ rest/edi/lib/method.php | 3 +-- rest/edi/load.php | 27 ++++++++++++--------------- rest/edi/update.php | 8 ++------ rest/image/image.php | 30 ++++++++++++------------------ rest/image/resize.php | 3 +-- rest/image/thumb.php | 3 +-- rest/misc/contact.php | 3 +-- rest/misc/mail.php | 3 +-- rest/tpv/confirm-mail.php | 3 +-- rest/tpv/confirm-soap.php | 3 +-- rest/tpv/soap-test.php | 3 +-- web/app.php | 3 +-- web/html-service.php | 6 ++---- web/html.php | 3 +-- web/json-service.php | 6 ++---- web/mailer.php | 3 +-- web/rest-service.php | 18 ++++++++++-------- web/service.php | 18 ++++++------------ web/util.php | 3 +-- 27 files changed, 72 insertions(+), 117 deletions(-) diff --git a/debian/changelog b/debian/changelog index a44286db..eb584afe 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (1.406.03) stable; urgency=low +hedera-web (1.406.04) stable; urgency=low * Initial Release. diff --git a/package.json b/package.json index 6687e44a..7610a901 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hedera-web", - "version": "1.406.03", + "version": "1.406.04", "description": "Verdnatura web page", "license": "GPL-3.0", "repository": { diff --git a/rest/core/account.php b/rest/core/account.php index c0f35398..1ea87b23 100644 --- a/rest/core/account.php +++ b/rest/core/account.php @@ -121,8 +121,7 @@ class Account { 'modtype' => LDAP_MODIFY_BATCH_REPLACE, 'values' => [$value] ]; - } - elseif (isset($curAttrs[$attribute])) { + } elseif (isset($curAttrs[$attribute])) { $modifs[] = [ 'attrib' => $attribute, 'modtype' => LDAP_MODIFY_BATCH_REMOVE_ALL @@ -130,8 +129,7 @@ class Account { } $updated = ldap_modify_batch($ds, $dn, $modifs); - } - else { + } else { $addAttrs = []; foreach($attrs as $attribute => $value) @@ -147,8 +145,7 @@ class Account { if (!$updated) throw new Exception("Can't update the LDAP entry: ". ldapError($ds)); - } - catch (Exception $e) { + } catch (Exception $e) { ldap_unbind($ds); throw $e; } diff --git a/rest/core/login.php b/rest/core/login.php index 098fe695..c5b01538 100644 --- a/rest/core/login.php +++ b/rest/core/login.php @@ -9,8 +9,7 @@ class Login extends Vn\Web\JsonRequest { ,strtolower($_POST['user']) ,$_POST['password'] ); - } - catch (Exception $e) { + } catch (Exception $e) { error_log($e->getMessage()); } diff --git a/rest/core/query.php b/rest/core/query.php index 56a5e98a..2ba22780 100644 --- a/rest/core/query.php +++ b/rest/core/query.php @@ -20,8 +20,7 @@ class Query extends Vn\Web\JsonRequest { if ($result !== FALSE) { $results[] = $this->transformResult($result); $result->free(); - } - else + } else $results[] = TRUE; } while ($db->moreResults() && $db->nextResult()); @@ -45,8 +44,7 @@ class Query extends Vn\Web\JsonRequest { // Checks for errors $db->checkError(); - } - catch (Vn\Db\Exception $e) { + } catch (Vn\Db\Exception $e) { if ($e->getCode() == 1644) { $dbMessage = $e->getMessage(); $sql = 'SELECT `description` FROM `message` WHERE `code` = #'; @@ -118,8 +116,7 @@ class Query extends Vn\Web\JsonRequest { ]; $tableIndex = count($resultMap['tables']) - 1; $tableMap[$column->table] = $tableIndex; - } - else + } else $tableIndex = $tableMap[$column->table]; if ($column->flags & MYSQLI_PRI_KEY_FLAG) diff --git a/rest/dms/add.php b/rest/dms/add.php index 59bb936c..dcb66483 100644 --- a/rest/dms/add.php +++ b/rest/dms/add.php @@ -96,8 +96,7 @@ class Add extends Vn\Web\JsonRequest { $db->query('COMMIT'); return $docId; - } - catch (Exception $e) { + } catch (Exception $e) { $db->query('ROLLBACK'); throw $e; } diff --git a/rest/edi/clean.php b/rest/edi/clean.php index a6e5d743..88823a76 100644 --- a/rest/edi/clean.php +++ b/rest/edi/clean.php @@ -27,8 +27,7 @@ class Clean extends Edi\Method { imap_expunge($imap); $count = count($messages); $deleted += $count; - } - else + } else $count = 0; echo "$count mails deleted from $folder mailbox\n"; diff --git a/rest/edi/lib/message.php b/rest/edi/lib/message.php index 22a0ba2d..c58700ba 100644 --- a/rest/edi/lib/message.php +++ b/rest/edi/lib/message.php @@ -57,8 +57,7 @@ class Message { if ($firstLoop) { if ($segment->name != $info->schema['mainTag']) throw new \Exception(); - } - else { + } else { for ($i = $info; $i; $i = $i->parentInfo) if (isset($i->schema['childs'][$segment->name])) { $info = new SectionInfo(); @@ -94,13 +93,11 @@ class Message { $endTag = $i; break; } - } - else + } else $info->section->segments[] = $segment; $firstLoop = FALSE; - }} - catch (\Exception $e) { + }} catch (\Exception $e) { throw new \Exception(sprintf('Parse error, something is wrong near "%s"', substr($string, $pos, 10))); } diff --git a/rest/edi/lib/method.php b/rest/edi/lib/method.php index 80fa1bfd..98e9e408 100644 --- a/rest/edi/lib/method.php +++ b/rest/edi/lib/method.php @@ -30,8 +30,7 @@ abstract class Method extends \Vn\Lib\Method { $this->ediRun($db); imap_expunge($imap); imap_close($imap); - } - else + } else error_log(imap_last_error()); } } diff --git a/rest/edi/load.php b/rest/edi/load.php index e5d45574..50f110ec 100644 --- a/rest/edi/load.php +++ b/rest/edi/load.php @@ -135,10 +135,10 @@ class Load extends Edi\Method { ); if ($res) - while ($row = $res->fetch_assoc()) { - $value = $lin->getValue('IMD', 2, Type::INTEGER, $row['feature']); - $ediValues['s'.$row['presentation_order']] = $value; - } + while ($row = $res->fetch_assoc()) { + $value = $lin->getValue('IMD', 2, Type::INTEGER, $row['feature']); + $ediValues['s'.$row['presentation_order']] = $value; + } else throw new Exception('Can\'t get the item features.'); @@ -157,8 +157,7 @@ class Load extends Edi\Method { } $db->query('COMMIT'); - } - catch (Exception $e) { + } catch (Exception $e) { $db->query('ROLLBACK'); $error = $e->getMessage(); break; @@ -172,8 +171,7 @@ class Load extends Edi\Method { if (!$error) { $folder = $this->imapConf['success_folder']; echo "Mail loaded with $count lines.\n"; - } - else { + } else { $folder = $this->imapConf['error_folder']; echo "Mail error: $error\n"; } @@ -195,13 +193,12 @@ class Load extends Edi\Method { $result[] = implode('.', $section); else $result[] = '1'; - } - elseif ($part->type == TYPEMULTIPART) - foreach($part->parts as $i => $subpart) { - array_push($section, $i + 1); - $this->imapFindParts($subpart, $matchTypes, $section, $result); - array_pop($section); - } + } elseif ($part->type == TYPEMULTIPART) + foreach($part->parts as $i => $subpart) { + array_push($section, $i + 1); + $this->imapFindParts($subpart, $matchTypes, $section, $result); + array_pop($section); + } } } diff --git a/rest/edi/update.php b/rest/edi/update.php index 562c293f..71352ac3 100644 --- a/rest/edi/update.php +++ b/rest/edi/update.php @@ -41,8 +41,7 @@ class Update extends Vn\Lib\Method { if ($row['updated']) { $updated = DateTime::createFromFormat('Y-m-d', $row['updated']); $updated->setTime(0, 0, 0, 0); - } - else + } else $updated = NULL; $remoteFile = "codes/$file.ZIP"; @@ -100,8 +99,7 @@ class Update extends Vn\Lib\Method { [$lastUpdated, $baseName] ); $db->query("COMMIT"); - } - catch (Exception $e) { + } catch (Exception $e) { $db->query('ROLLBACK'); error_log($e->getMessage()); } @@ -112,5 +110,3 @@ class Update extends Vn\Lib\Method { echo "Update completed\n"; } } - - diff --git a/rest/image/image.php b/rest/image/image.php index f0cd4387..1e5b3112 100644 --- a/rest/image/image.php +++ b/rest/image/image.php @@ -24,8 +24,7 @@ class Image { break; default: throw new UserException(s('Bad file format')); - } - else + } else throw new UserException(s('Image open error')); return $image; @@ -63,7 +62,7 @@ class Image { $dstWidth = $width; $dstHeight = $height; - if (!$crop) // Resize { + if (!$crop) { // Resize $ratio = NULL; if ($dstWidth > $maxWidth) { @@ -77,8 +76,7 @@ class Image { $dstHeight = $maxHeight; $dstWidth =(int)($dstWidth / $ratio); } - } - else // Cut & resize { + } else { // Cut & resize if ($width > $maxWidth) $dstWidth = $maxWidth; if ($height > $maxWidth) @@ -87,14 +85,12 @@ class Image { if ($width <= $maxWidth) { if ($height > $srcHeight) $srcHeight = $maxHeight; - } - elseif ($height <= $maxHeight) { + } elseif ($height <= $maxHeight) { if ($width > $maxWidth) $srcWidth = $maxWidth; - } - else { - $srcWidth =(int)($maxWidth *($height / $maxHeight)); - $srcHeight =(int)($maxHeight *($width / $maxWidth)); + } else { + $srcWidth = (int) ($maxWidth *($height / $maxHeight)); + $srcHeight = (int) ($maxHeight *($width / $maxWidth)); if ($srcWidth <= $width) $srcHeight = $height; @@ -103,12 +99,12 @@ class Image { } if ($width !== $srcWidth) - $srcX =(int)(($width / 2) -($srcWidth / 2)); + $srcX = (int) (($width / 2) -($srcWidth / 2)); if ($height !== $srcHeight) - $srcY =(int)(($height / 2) -($srcHeight / 2)); + $srcY = (int) (($height / 2) -($srcHeight / 2)); } - + $resizedImage = imagecreatetruecolor($dstWidth, $dstHeight); imagealphablending($resizedImage, FALSE); imagesavealpha($resizedImage, TRUE); @@ -116,11 +112,9 @@ class Image { 0, 0, $srcX, $srcY, $dstWidth, $dstHeight, $srcWidth, $srcHeight); $saved = imagepng($resizedImage, $dstFile); imagedestroy($resizedImage); - } - elseif (isset($symbolicSrc)) { + } elseif (isset($symbolicSrc)) { $saved = symlink($symbolicSrc, $dstFile); - } - else { + } else { imagesavealpha($image, TRUE); $saved = imagepng($image, $dstFile); } diff --git a/rest/image/resize.php b/rest/image/resize.php index 952d70ee..487adb57 100644 --- a/rest/image/resize.php +++ b/rest/image/resize.php @@ -55,8 +55,7 @@ class Resize extends Vn\Lib\Method { Image::resizeSave($image, $dstFile, $maxHeight, $maxWidth, $crop, $symbolicSrc); imagedestroy($image); $count++; - } - catch (\Exception $e) {} + } catch (\Exception $e) {} } echo "$count files resized.\n"; diff --git a/rest/image/thumb.php b/rest/image/thumb.php index 0e1cd2d6..20022508 100644 --- a/rest/image/thumb.php +++ b/rest/image/thumb.php @@ -85,8 +85,7 @@ class Thumb extends Vn\Web\RestRequest { if ($useXsendfile) { header("X-Sendfile: $dstFile"); header("Content-Type: image/png"); - } - else + } else header("Location: {$_SERVER['REQUEST_URI']}"); } } diff --git a/rest/misc/contact.php b/rest/misc/contact.php index 31ae1c5b..4705c930 100644 --- a/rest/misc/contact.php +++ b/rest/misc/contact.php @@ -42,8 +42,7 @@ class Contact extends Vn\Web\JsonRequest { $mail->SMTPAuth = TRUE; $mail->Username = $conf->user; $mail->Password = base64_decode($conf->password); - } - else + } else $mail->SMTPAuth = FALSE; if ($conf->secure) { diff --git a/rest/misc/mail.php b/rest/misc/mail.php index 155e0980..c9245aac 100644 --- a/rest/misc/mail.php +++ b/rest/misc/mail.php @@ -35,8 +35,7 @@ class Mail extends Vn\Lib\Method { throw new Exception('Send error: '.$mail->ErrorInfo); $count++; - } - catch (Exception $e) { + } catch (Exception $e) { $sent = 2; $status = $e->getMessage(); } diff --git a/rest/tpv/confirm-mail.php b/rest/tpv/confirm-mail.php index dc71a13a..fda13b4b 100644 --- a/rest/tpv/confirm-mail.php +++ b/rest/tpv/confirm-mail.php @@ -48,8 +48,7 @@ class ConfirmMail extends Vn\Lib\Method { try { $success = Tpv::confirm($db, $params); - } - catch (\Exception $e) { + } catch (\Exception $e) { trigger_error($e->getMessage(), E_USER_WARNING); } diff --git a/rest/tpv/confirm-soap.php b/rest/tpv/confirm-soap.php index 79d67499..07e44d2b 100644 --- a/rest/tpv/confirm-soap.php +++ b/rest/tpv/confirm-soap.php @@ -57,8 +57,7 @@ function procesaNotificacionSIS($XML) { // Confirms the transaction Tpv::confirm($db, $params); - } - catch (Exception $e) { + } catch (Exception $e) { $status = 'KO'; } diff --git a/rest/tpv/soap-test.php b/rest/tpv/soap-test.php index ab97760f..5a6bef44 100644 --- a/rest/tpv/soap-test.php +++ b/rest/tpv/soap-test.php @@ -20,8 +20,7 @@ if (isset($_POST['key'])) { $shaHash = sha1($shaString.$key); $isValid = $xml->{'Signature'} == $shaHash; -} -else { +} else { $key = ''; $result = ''; $shaHash = ''; diff --git a/web/app.php b/web/app.php index 22d0a06a..c47d31b2 100644 --- a/web/app.php +++ b/web/app.php @@ -37,8 +37,7 @@ class App extends \Vn\Lib\App { $className = __NAMESPACE__ .'\\'. hyphenToCamelCase($service, TRUE) .'Service'; $service = new $className($this); $service->run(); - } - else + } else http_response_code(400); } diff --git a/web/html-service.php b/web/html-service.php index 548e90d3..5eb3cc6e 100644 --- a/web/html-service.php +++ b/web/html-service.php @@ -52,8 +52,7 @@ class HtmlService extends Service { if ($updateBrowser) { header('Location: ?method=update-browser'); exit(0); - } - else + } else $_SESSION['skipBrowser'] = TRUE; } @@ -85,8 +84,7 @@ class HtmlService extends Service { $dir = $basePath; include_once __DIR__.'/html.php'; include("./$basePath/ui.php"); - } - else + } else header('Location: ./'); } diff --git a/web/html.php b/web/html.php index 282904ea..8635d2a5 100644 --- a/web/html.php +++ b/web/html.php @@ -41,8 +41,7 @@ function getWebpackAssets() { foreach($wpAssets as $name => $asset) if (property_exists($asset, 'js')) $assets->$name = $asset->js; - } - else { + } else { $devServerPath = "http://$host:$devServerPort/$buildDir"; $manifestJs = "$devServerPath/manifest.js"; $mainJs = "$devServerPath/main.js"; diff --git a/web/json-service.php b/web/json-service.php index 38257ec7..7fa3a85c 100644 --- a/web/json-service.php +++ b/web/json-service.php @@ -63,8 +63,7 @@ class JsonService extends RestService { $this->warnings = []; $this->warnings[] = $json; - } - else { + } else { http_response_code(500); $this->replyJson($json); exit(); @@ -79,8 +78,7 @@ class JsonService extends RestService { if (_ENABLE_DEBUG || $e instanceof Lib\UserException) { $json->exception = get_class($e); $json->message = $e->getMessage(); - } - else { + } else { $json->exception = 'Exception'; $json->message = s('Something went wrong'); } diff --git a/web/mailer.php b/web/mailer.php index 2070f53a..cba3a0df 100644 --- a/web/mailer.php +++ b/web/mailer.php @@ -27,8 +27,7 @@ class Mailer { $mail->SMTPAuth = TRUE; $mail->Username = $conf->user; $mail->Password = base64_decode($conf->password); - } - else + } else $mail->SMTPAuth = FALSE; if ($conf->secure) { diff --git a/web/rest-service.php b/web/rest-service.php index 0405ab59..6aa6f241 100644 --- a/web/rest-service.php +++ b/web/rest-service.php @@ -39,8 +39,7 @@ class RestService extends Service { throw new UserException(s('You don\'t have enough privileges')); $methodDb = $db; - } - else + } else $methodDb = $this->getUserDb($_SESSION['user']); if ($method::PARAMS !== NULL && !$method->checkParams($_REQUEST, $method::PARAMS)) @@ -52,8 +51,7 @@ class RestService extends Service { try { $res = $method->run($methodDb); - } - catch (Db\Exception $e) { + } catch (Db\Exception $e) { if ($e->getCode() == 1644) throw new UserException(s($e->getMessage())); } @@ -69,11 +67,15 @@ class RestService extends Service { function statusFromException($e) { try { throw $e; + } catch (SessionExpiredException $e) { + $status = 401; + } catch (BadLoginException $e) { + $status = 401; + } catch (Lib\UserException $e) { + $status = 400; + } catch (\Exception $e) { + $status = 500; } - catch (SessionExpiredException $e) { $status = 401; } - catch (BadLoginException $e) { $status = 401; } - catch (Lib\UserException $e) { $status = 400; } - catch (\Exception $e) { $status = 500; } http_response_code($status); } diff --git a/web/service.php b/web/service.php index 1a8c171e..70baf3ed 100644 --- a/web/service.php +++ b/web/service.php @@ -114,8 +114,7 @@ abstract class Service { if (isset($row['access'])) { setcookie('vnVisit', $row['visit'], time() + 31536000); // 1 Year $_SESSION['access'] = $row['access']; - } - else + } else $_SESSION['skipVisit'] = TRUE; } @@ -139,17 +138,14 @@ abstract class Service { try { $db->query('CALL account.userLogin(#, #)', [$user, $_POST['password']]); - } - catch (Db\Exception $e) { + } catch (Db\Exception $e) { if ($e->getMessage() == 'INVALID_CREDENTIALS') { sleep(3); throw new BadLoginException(); - } - else + } else throw $e; } - } - else { + } else { if (isset($_POST['token']) || isset($_GET['token'])) { if (isset($_POST['token'])) $token = $_POST['token']; @@ -160,8 +156,7 @@ abstract class Service { try { $jwtPayload = Jwt::decode($token, $key); - } - catch (\Exception $e) { + } catch (\Exception $e) { throw new BadLoginException($e->getMessage()); } @@ -276,8 +271,7 @@ abstract class Service { if (file_exists('package.json')) { $package = json_decode(file_get_contents('package.json')); $version = $package->version; - } - else + } else $version = '0.0.0'; apc_store("$appName.version", $version); diff --git a/web/util.php b/web/util.php index 582152d3..096f69b6 100644 --- a/web/util.php +++ b/web/util.php @@ -21,8 +21,7 @@ class Util { if ($useXsendfile) { header("X-Sendfile: $file"); header("Content-Type: $mimeType"); - } - else { + } else { header('Content-Description: File Transfer'); header("Content-Type: $mimeType"); header('Content-Disposition: attachment; filename="'. basename($file) .'"');