From 3f664f3098ab74fa2722439e0387e6180feb2d58 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Tue, 26 Jun 2018 16:33:15 +0200 Subject: [PATCH] Miglioramenti documentazione --- lib/functions.php | 4 ++-- src/App.php | 12 +++++++----- src/Auth.php | 15 ++++++++------- src/Backup.php | 14 +++++++------- src/Database.php | 4 ++-- src/Intl/Formatter.php | 18 +++++++++--------- src/Modules.php | 5 ----- src/Update.php | 8 ++++---- src/Util/Ini.php | 14 ++++++++------ src/Util/Singleton.php | 2 +- src/Validate.php | 1 - 11 files changed, 48 insertions(+), 49 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index 9cebdcfa9..685e40980 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -514,7 +514,7 @@ function slashes($string) * * @since 2.3 * - * @return string + * @return mixed */ function prepare($parameter) { @@ -529,7 +529,7 @@ function prepare($parameter) * * @since 2.3 * - * @return string + * @return mixed */ function p($parameter) { diff --git a/src/App.php b/src/App.php index 543a1d7e6..340778b0b 100644 --- a/src/App.php +++ b/src/App.php @@ -7,11 +7,12 @@ */ class App { - /** @var int Identificativo del modulo corrente */ + /** @var array Identificativo del modulo corrente */ protected static $current_module; /** @var int Identificativo dell'elemento corrente */ protected static $current_element; + /** @var array Elenco degli assets del progetto */ protected static $assets = [ // CSS 'css' => [ @@ -39,7 +40,7 @@ class App /** * Restituisce l'identificativo del modulo attualmente in utilizzo. * - * @return int + * @return array */ public static function getCurrentModule() { @@ -60,7 +61,7 @@ class App public static function getCurrentElement() { if (empty(self::$current_element)) { - self::$current_element = filter('id_record'); + self::$current_element = intval(filter('id_record')); } return self::$current_element; @@ -196,7 +197,7 @@ class App /** * Restituisce un'insieme di array comprendenti le informazioni per la costruzione della query del modulo indicato. * - * @param int $id + * @param array $element * * @return array */ @@ -217,6 +218,7 @@ class App $summable = []; $search_inside = []; $search = []; + $format = []; $slow = []; $order_by = []; @@ -392,7 +394,7 @@ class App $original_file = str_replace('|custom|', '', $path); $custom_file = str_replace('|custom|', '/custom', $path); - $result = null; + $result = ''; if (file_exists($custom_file)) { $result = $custom_file; } elseif (file_exists($original_file)) { diff --git a/src/Auth.php b/src/Auth.php index 3788f2211..4ba2af761 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -33,7 +33,7 @@ class Auth extends \Util\Singleton 'options' => [], ]; - /** @var int Opzioni per la protezione contro attacchi brute-force */ + /** @var array Opzioni per la protezione contro attacchi brute-force */ protected static $brute = [ 'attemps' => 3, 'timeout' => 180, @@ -42,8 +42,8 @@ class Auth extends \Util\Singleton protected static $is_brute; /** @var array Informazioni riguardanti l'utente autenticato */ - protected $infos; - /** @var string Nome del primo modulo su cui l'utente ha permessi di navigazione */ + protected $infos = []; + /** @var string|null Nome del primo modulo su cui l'utente ha permessi di navigazione */ protected $first_module; protected function __construct() @@ -92,7 +92,7 @@ class Auth extends \Util\Singleton $database = Database::getConnection(); $log = []; - $log['username'] = (string) $username; + $log['username'] = $username; $log['ip'] = get_client_ip(); $log['stato'] = self::$status['failed']['code']; @@ -154,6 +154,7 @@ class Auth extends \Util\Singleton protected function password_check($password, $hash, $user_id = null) { $result = false; + $rehash = false; // Retrocompatibilità if ($hash == md5($password)) { @@ -286,7 +287,7 @@ class Auth extends \Util\Singleton public function destory() { if ($this->isAuthenticated() || !empty($_SESSION['id_utente'])) { - $this->infos = null; + $this->infos = []; $this->first_module = null; session_unset(); @@ -301,7 +302,7 @@ class Auth extends \Util\Singleton /** * Restituisce il nome del primo modulo navigabile dall'utente autenticato. * - * @return string + * @return string|null */ public function getFirstModule() { @@ -336,7 +337,7 @@ class Auth extends \Util\Singleton * * @param string $password * - * @return string + * @return string|bool */ public static function hashPassword($password) { diff --git a/src/Backup.php b/src/Backup.php index e0727f5ab..3ea1fffd4 100644 --- a/src/Backup.php +++ b/src/Backup.php @@ -30,7 +30,7 @@ class Backup throw new UnexpectedValueException(); } - return realpath($result); + return slashes($result); } /** @@ -46,7 +46,7 @@ class Backup throw new UnexpectedValueException(); } - return realpath($result); + return slashes($result); } /** @@ -169,13 +169,13 @@ class Backup // Lista dei file da inserire nel backup $files = Symfony\Component\Finder\Finder::create() ->files() - ->exclude((array) $ignores['dirs']) + ->exclude($ignores['dirs']) ->ignoreDotFiles(true) ->ignoreVCS(true) ->in(DOCROOT) ->in(self::getDatabaseDirectory()); - foreach ((array) $ignores['files'] as $value) { + foreach ($ignores['files'] as $value) { $files->notName($value); } @@ -200,8 +200,8 @@ class Backup /** * Effettua il backup in formato ZIP. * - * @param array $files Elenco dei file da includere - * @param string $destination Nome del file ZIP + * @param Iterator|array $files File da includere + * @param string $destination Nome del file ZIP * * @return bool */ @@ -213,7 +213,7 @@ class Backup $zip = new ZipArchive(); - $result = $zip->open($destination, ZIPARCHIVE::CREATE); + $result = $zip->open($destination, ZipArchive::CREATE); if ($result === true) { foreach ($files as $file) { $zip->addFile($file, $file->getRelativePathname()); diff --git a/src/Database.php b/src/Database.php index 155a66d45..6bac997bb 100644 --- a/src/Database.php +++ b/src/Database.php @@ -185,7 +185,7 @@ class Database extends Util\Singleton * * @since 2.3 * - * @return int + * @return string */ public function getMySQLVersion() { @@ -370,7 +370,7 @@ class Database extends Util\Singleton * * @since 2.3 * - * @return string + * @return mixed */ public function prepare($parameter) { diff --git a/src/Intl/Formatter.php b/src/Intl/Formatter.php index 2d9c1d8c6..43fe4281f 100644 --- a/src/Intl/Formatter.php +++ b/src/Intl/Formatter.php @@ -109,7 +109,7 @@ class Formatter * * @param string $value * - * @return string + * @return string|bool */ public function formatNumber($value, $decimals = null) { @@ -140,7 +140,7 @@ class Formatter * * @param string $value * - * @return string + * @return float|bool */ public function parseNumber($value) { @@ -243,7 +243,7 @@ class Formatter * * @param string $value * - * @return array + * @return string|bool */ public function customNumber($value, $current, $format) { @@ -313,7 +313,7 @@ class Formatter * * @param string $value * - * @return string + * @return string|bool */ public function formatTimestamp($value) { @@ -328,7 +328,7 @@ class Formatter * * @param string $value * - * @return string + * @return string|bool */ public function parseTimestamp($value) { @@ -393,7 +393,7 @@ class Formatter * * @param string $value * - * @return string + * @return string|bool */ public function formatDate($value) { @@ -412,7 +412,7 @@ class Formatter * * @param string $value * - * @return string + * @return string|bool */ public function parseDate($value) { @@ -477,7 +477,7 @@ class Formatter * * @param string $value * - * @return string + * @return string|bool */ public function formatTime($value) { @@ -496,7 +496,7 @@ class Formatter * * @param string $value * - * @return string + * @return string|bool */ public function parseTime($value) { diff --git a/src/Modules.php b/src/Modules.php index 0e902e187..1b3524cd6 100644 --- a/src/Modules.php +++ b/src/Modules.php @@ -7,11 +7,6 @@ */ class Modules { - /** @var int Identificativo del modulo corrente */ - protected static $current_module; - /** @var int Identificativo dell'elemento corrente */ - protected static $current_element; - /** @var array Elenco dei moduli disponibili */ protected static $modules = []; protected static $references = []; diff --git a/src/Update.php b/src/Update.php index 245329dbc..5ab923fbb 100644 --- a/src/Update.php +++ b/src/Update.php @@ -76,7 +76,7 @@ class Update $results = []; // Aggiornamenti del gestionale - $core = (array) glob(DOCROOT.'/update/*.{php,sql}', GLOB_BRACE); + $core = glob(DOCROOT.'/update/*.{php,sql}', GLOB_BRACE); foreach ($core as $value) { $infos = pathinfo($value); $value = str_replace('_', '.', $infos['filename']); @@ -102,7 +102,7 @@ class Update $results = []; // Aggiornamenti dei moduli - $modules = (array) glob(DOCROOT.'/modules/*/update/*.{php,sql}', GLOB_BRACE); + $modules = glob(DOCROOT.'/modules/*/update/*.{php,sql}', GLOB_BRACE); foreach ($modules as $value) { $infos = pathinfo($value); @@ -172,7 +172,7 @@ class Update */ public static function isVersion($string) { - return preg_match('/^\d+(?:\.\d+)+$/', $string); + return preg_match('/^\d+(?:\.\d+)+$/', $string) === 1; } /** @@ -382,7 +382,7 @@ class Update * Normalizza l'infrastruttura del database indicato, generalizzando charset e collation all'interno del database e delle tabelle ed effettuando una conversione delle tabelle all'engine InnoDB. * Attenzione: se l'engine InnoDB non è supportato, il server ignorerà la conversione dell'engine e le foreign key del gestionale non funzioneranno adeguatamente. * - * @param [type] $database_name + * @param string $database_name */ protected static function normalizeDatabase($database_name) { diff --git a/src/Util/Ini.php b/src/Util/Ini.php index 6201cdbbd..90b359981 100644 --- a/src/Util/Ini.php +++ b/src/Util/Ini.php @@ -53,7 +53,7 @@ class Ini */ public static function read($string) { - return parse_ini_string($string, true); + return (array) parse_ini_string($string, true); } /** @@ -67,7 +67,9 @@ class Ini { $filename = (file_exists($filename)) ? $filename : DOCROOT.'/files/my_impianti/'.$filename; - return self::read(file_get_contents($filename)); + $contents = file_get_contents($filename); + + return !empty($contents) ? self::read($contents) : []; } /** @@ -81,11 +83,11 @@ class Ini $results = []; // Lettura dei files nella cartella indicata - $exclude = (!empty($exclude)) ? $exclude : []; - $exclude = (is_string($exclude)) ? explode(',', $list) : $exclude; + $exclude = !empty($exclude) ? $exclude : []; + $exclude = is_array($exclude) ? $exclude : explode(',', $exclude); // Aggiungo tutti i componenti di possibile installazione - $files = (array) glob(realpath($dir).'/*.ini'); + $files = glob(realpath($dir).'/*.ini'); foreach ($files as $file) { if (!in_array(basename($file), $exclude)) { $results[] = [basename($file), self::getValue(self::readFile($file), 'Nome')]; @@ -98,7 +100,7 @@ class Ini /** * Ottiene il valore di un campo contenuto all'interno della struttura INI. * - * @param string $content + * @param array $content * @param string $value * * @return mixed diff --git a/src/Util/Singleton.php b/src/Util/Singleton.php index c3342aafb..c74aaf376 100644 --- a/src/Util/Singleton.php +++ b/src/Util/Singleton.php @@ -9,7 +9,7 @@ namespace Util; */ abstract class Singleton { - /** @var Util\Singleton Oggetti istanziati */ + /** @var Singleton Oggetti istanziati */ protected static $instance = []; /** diff --git a/src/Validate.php b/src/Validate.php index d57498e36..88ec13e61 100644 --- a/src/Validate.php +++ b/src/Validate.php @@ -32,7 +32,6 @@ class Validate return false; } } catch (VATCheckUnavailableException $e) { - return; } $access_key = Settings::get('apilayer API key for VAT number');