From f21f3db19ecaa7c184b81b6303be2c88f9cef176 Mon Sep 17 00:00:00 2001 From: TimZ99 Date: Wed, 11 Jul 2018 00:27:06 +0200 Subject: [PATCH] Typo fix, removed unused code & updated documentation --- src/includes/functions.inc.php | 2 +- .../Install/Controller/InstallController.php | 2 +- .../Controller/AbstractServerController.php | 2 +- .../Module/Server/Controller/LogController.php | 4 ++-- .../Module/Server/Controller/ServerController.php | 8 +++----- src/psm/Service/Database.php | 14 +++++++------- src/psm/Service/User.php | 2 +- src/psm/Txtmsg/CMBulkSMS.php | 15 +++++++-------- src/psm/Txtmsg/Core.php | 2 +- src/psm/Txtmsg/Smsglobal.php | 3 +-- src/psm/Util/Server/ServerValidator.php | 2 +- src/psm/Util/Server/Updater/StatusNotifier.php | 2 +- 12 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index d54fc9a62..e756daef5 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -669,7 +669,7 @@ function psm_GET($key, $alt = null) { /** * Try existence of a POST var, if not return the alternative * @param string $key - * @param string $alt + * @param string|array|bool $alt * @return mixed */ function psm_POST($key, $alt = null) { diff --git a/src/psm/Module/Install/Controller/InstallController.php b/src/psm/Module/Install/Controller/InstallController.php index 21d189735..81131af4e 100644 --- a/src/psm/Module/Install/Controller/InstallController.php +++ b/src/psm/Module/Install/Controller/InstallController.php @@ -58,7 +58,7 @@ function __construct(Database $db, \Twig_Environment $twig) { 'index', 'config', 'install' ), 'index'); - $this->twig->addGlobal('subtitle', psm_get_lang('system,', 'install')); + $this->twig->addGlobal('subtitle', psm_get_lang('system', 'install')); } /** diff --git a/src/psm/Module/Server/Controller/AbstractServerController.php b/src/psm/Module/Server/Controller/AbstractServerController.php index 39dc3be82..65be4c406 100644 --- a/src/psm/Module/Server/Controller/AbstractServerController.php +++ b/src/psm/Module/Server/Controller/AbstractServerController.php @@ -38,7 +38,7 @@ function __construct(Database $db, \Twig_Environment $twig) { /** * Get all servers for the current user - * @param int $server_id if true only that server will be retrieved. + * @param Countable|array|\PDOStatement $server_id (int) if true only that server will be retrieved. * @return array */ public function getServers($server_id = null) { diff --git a/src/psm/Module/Server/Controller/LogController.php b/src/psm/Module/Server/Controller/LogController.php index 49bbff81c..96f73e5b7 100644 --- a/src/psm/Module/Server/Controller/LogController.php +++ b/src/psm/Module/Server/Controller/LogController.php @@ -137,7 +137,7 @@ protected function executeDelete() { * Get all the log entries for a specific $type * * @param string $type status/email/sms - * @return array + * @return \PDOStatement array */ public function getEntries($type) { $sql_join = ''; @@ -172,7 +172,7 @@ public function getEntries($type) { * Get all the user entries for a specific $log_id * * @param $log_id - * @return array + * @return \PDOStatement array */ protected function getLogUsers($log_id) { return $this->db->query( diff --git a/src/psm/Module/Server/Controller/ServerController.php b/src/psm/Module/Server/Controller/ServerController.php index 886094a9d..e4dfc1dbf 100644 --- a/src/psm/Module/Server/Controller/ServerController.php +++ b/src/psm/Module/Server/Controller/ServerController.php @@ -239,8 +239,6 @@ protected function executeSave() { return $this->executeIndex(); } - $encrypted_password = ''; - if (!empty($_POST['website_password'])) { $new_password = psm_POST('website_password'); @@ -251,7 +249,7 @@ protected function executeSave() { if ($new_password == $hash) { $encrypted_password = $edit_server['website_password']; } else { - $encrypted_password = psm_password_encrypt($this->server_id.psm_get_conf('password_encrypt_key'), $new_password); + $encrypted_password = psm_password_encrypt(strval($this->server_id).psm_get_conf('password_encrypt_key'), $new_password); } } else { // We need the server id to encrypt the password. Encryption will be done after the server is added @@ -263,7 +261,7 @@ protected function executeSave() { 'label' => trim(strip_tags(psm_POST('label', ''))), 'ip' => trim(strip_tags(psm_POST('ip', ''))), 'timeout' => (isset($_POST['timeout']) && intval($_POST['timeout']) > 0) ? intval($_POST['timeout']) : null, - 'website_username' => psm_POST('website_username', null), + 'website_username' => psm_POST('website_username'), 'website_password' => $encrypted_password, 'port' => intval(psm_POST('port', 0)), 'type' => psm_POST('type', ''), @@ -332,7 +330,7 @@ protected function executeSave() { if (!empty($_POST['website_password'])) { $cleanWebsitePassword = array( 'website_password' => psm_password_encrypt( - $this->server_id.psm_get_conf('password_encrypt_key'), + strval($this->server_id).psm_get_conf('password_encrypt_key'), psm_POST('website_password') ), ); diff --git a/src/psm/Service/Database.php b/src/psm/Service/Database.php index 07beabfc1..4aba875a4 100644 --- a/src/psm/Service/Database.php +++ b/src/psm/Service/Database.php @@ -104,7 +104,7 @@ function __construct($host = null, $user = null, $pass = null, $db = null, $port * If you dont want to fetch a result, use exec(). * @param string $query SQL query * @param boolean $fetch automatically fetch results, or return PDOStatement? - * @return array|\PDOStatement if $fetch = true, array, otherwise \PDOStatement + * @return \PDOStatement|int|bool|array object */ public function query($query, $fetch = true) { // Execute query and process results @@ -140,7 +140,7 @@ public function query($query, $fetch = true) { /** * Execute SQL statement and return number of affected rows * @param string $query - * @return int|\PDOStatement + * @return int */ public function exec($query) { try { @@ -183,7 +183,7 @@ public function execute($query, $parameters, $fetch = true) { * @param string $limit limit. for example: 0,30 * @param array $orderby fields for the orderby clause * @param string $direction ASC or DESC. Defaults to ASC - * @return array multi dimensional array with results + * @return \PDOStatement array multi dimensional array with results */ public function select($table, $where = null, $fields = null, $limit = '', $orderby = null, $direction = 'ASC') { // build query @@ -253,7 +253,8 @@ public function delete($table, $where = null) { * Insert or update data to the database * @param string $table table name * @param array $data data to save or insert - * @param mixed $where either string ('user_id=2' or just '2' (works only with primary field)) or array with where clause (only when updating) + * @param string|array $where either string ('user_id=2' or just '2' (works only with primary field)) or array with where clause (only when updating) + * @return int|array|\PDOStatement */ public function save($table, array $data, $where = null) { if ($where === null) { @@ -280,9 +281,8 @@ public function save($table, array $data, $where = null) { if ($exec) { return $this->exec($query); - } else { - return $this->query($query); } + return $this->query($query); } /** @@ -294,7 +294,7 @@ public function save($table, array $data, $where = null) { * that do not match the fields provided in the first record will be * skipped. * - * @param type $table + * @param string $table * @param array $data * @return \PDOStatement * @see insert() diff --git a/src/psm/Service/User.php b/src/psm/Service/User.php index 7d983c48c..6906fd93d 100644 --- a/src/psm/Service/User.php +++ b/src/psm/Service/User.php @@ -374,7 +374,7 @@ public function verifyPasswordResetToken($user_id, $token) { /** * Change the password of a user - * @param int $user_id + * @param int|\PDOStatement $user_id * @param string $password * @return boolean TRUE on success, FALSE on failure */ diff --git a/src/psm/Txtmsg/CMBulkSMS.php b/src/psm/Txtmsg/CMBulkSMS.php index a57b76587..3ee1a83a2 100644 --- a/src/psm/Txtmsg/CMBulkSMS.php +++ b/src/psm/Txtmsg/CMBulkSMS.php @@ -37,11 +37,11 @@ * Requirements: cURL v7.18.1+ and OpenSSL 0.9.8j+ */ class CMBulkSMS extends Core { - /** @var bool|null True when cURL request succeeded */ - public $result; + /** @var bool True when cURL request succeeded */ + public $result = true; - /** @var string|null Contains error message if cURL request failed */ - public $error; + /** @var string Contains error message if cURL request failed */ + public $error = ''; /** @var bool Set to true for debug output/logging */ protected $debug = false; @@ -75,7 +75,7 @@ class CMBulkSMS extends Core { * * @see https://docs.cmtelecom.com/bulk-sms/v1.0#/send_a_message%7Csample_requests * @param string $message Your text message - * @return boolean True when cURL request was successful + * @return bool|string true when cURL request was successful, otherwise string with error message */ public function sendSMS($message) { // Check if recipient and text message are available @@ -210,12 +210,11 @@ protected function executeCurlRequest() { $cErrorCode = curl_errno($cr); curl_close($cr); - $this->result = true; // set result and log error if needed if ($cError) { $this->error = 'Response: CM SMS API:'.$cResponse.' cURL Error Code: '.$cErrorCode.'"'.$cError.'"'; error_log($this->error, E_USER_ERROR); - $this->result = $this->error; + $this->result = false; } // Debug output @@ -226,6 +225,6 @@ protected function executeCurlRequest() { echo $debug; } - return $this->result; + return $this->result ? $this->result : $this->error; } } diff --git a/src/psm/Txtmsg/Core.php b/src/psm/Txtmsg/Core.php index 8f7795045..b14fe1de5 100644 --- a/src/psm/Txtmsg/Core.php +++ b/src/psm/Txtmsg/Core.php @@ -56,7 +56,7 @@ public function setOriginator($originator) { /** * Add new recipient to the list * - * @param unknown_type $recipient + * @param string|int $recipient */ public function addRecipients($recipient) { array_push($this->recipients, $recipient); diff --git a/src/psm/Txtmsg/Smsglobal.php b/src/psm/Txtmsg/Smsglobal.php index da9a6276d..7cd3da47c 100644 --- a/src/psm/Txtmsg/Smsglobal.php +++ b/src/psm/Txtmsg/Smsglobal.php @@ -75,8 +75,7 @@ public function sendSMS($message) { $result = curl_exec($curl); $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); - - $result = curl_exec($curl); + $err = curl_errno($curl); if ($err != 0 || substr($result, 0, 5) != "OK: 0") { diff --git a/src/psm/Util/Server/ServerValidator.php b/src/psm/Util/Server/ServerValidator.php index cabf88298..1b6d71ade 100644 --- a/src/psm/Util/Server/ServerValidator.php +++ b/src/psm/Util/Server/ServerValidator.php @@ -45,7 +45,7 @@ public function __construct(\psm\Service\Database $db) { /** * Check if the server id exists - * @param int $server_id + * @param int|\PDOStatement $server_id * @return boolean * @throws \InvalidArgumentException */ diff --git a/src/psm/Util/Server/Updater/StatusNotifier.php b/src/psm/Util/Server/Updater/StatusNotifier.php index b07942b07..c8d65e3fc 100644 --- a/src/psm/Util/Server/Updater/StatusNotifier.php +++ b/src/psm/Util/Server/Updater/StatusNotifier.php @@ -366,7 +366,7 @@ protected function notifyByTelegram($users) { /** * Get all users for the provided server id * @param int $server_id - * @return array + * @return \PDOStatement array */ public function getUsers($server_id) { // find all the users with this server listed