From b73b70f5cb903e6bf3819873c716425b196928b2 Mon Sep 17 00:00:00 2001
From: Cristiano Magro <cristiano.magro@vola.it>
Date: Tue, 16 Jan 2018 16:19:35 +0100
Subject: [PATCH] PHPCBF Vola style formattazione codice
---
src/UploadFile/SetupUpload.class.php | 44 +++++++++++++++++++++++++++++++++-----------
1 files changed, 33 insertions(+), 11 deletions(-)
diff --git a/src/UploadFile/SetupUpload.class.php b/src/UploadFile/SetupUpload.class.php
index 8bd941a..9193095 100644
--- a/src/UploadFile/SetupUpload.class.php
+++ b/src/UploadFile/SetupUpload.class.php
@@ -8,7 +8,6 @@
* javascript di gestione del plupload
*
* @author Cristiano Magro
- *
*/
class SetupUpload {
@@ -58,10 +57,12 @@
/**
* Dimensione massima del singolo file caricato
- *
- * Accetta sia '1024' che '1 kb' effettuando la conversione interna
+ *
+ * Accetta sia '1024' che '1 kb' effettuando la conversione interna
* necessaria.
+ *
* @param string $x sia '1024' che '1 kb'
+ *
* @return \SetupUpload
*/
public function setSizeLimitFile($x) {
@@ -118,6 +119,7 @@
/**
* Restituisce il numero massimo di file previsti nella coda
+ *
* @return integer Max numero file
*/
public function getNumMaxFiles() {
@@ -126,12 +128,14 @@
/**
* Viene impostato il numero massimo di file caricabili
- * @param integer $numero
+ *
+ * @param integer $numero limite massimo file caricabili
+ *
* @return \SetupUpload fluent style
*/
public function setNumMaxFiles($numero) {
if (!is_integer($numero) || $numero <= 0) {
- throw new UploadFile_Exc();
+ throw new Upload_Exc_Error();
}
$this->numMaxFiles = $numero;
@@ -144,10 +148,12 @@
/**
* Dimensione Totale massima dei file caricabili
- *
- * Accetta sia '1024' che '1 kb' effettuando la conversione interna
+ *
+ * Accetta sia '1024' che '1 kb' effettuando la conversione interna
* necessaria.
+ *
* @param string $x sia '1024' che '1 kb'
+ *
* @return \SetupUpload
*/
public function setSizeMaxFilesByte($x) {
@@ -196,19 +202,35 @@
/**
* Converte una stringa nei corrispondenti bytes.
- *
+ *
* 1 Mb = 1024^2
- *
+ *
* @param string $strSize Stringa da convertire
+ *
+ * @throws UploadFile_Excs
+ *
* @return integer
*/
public static function str2Bytes($strSize) {
+ $Units = array('b' => 0, 'kb' => 1, 'mb' => 2, 'gb' => 3, 'tb' => 4);
+
$strUnit = strtolower($strSize);
$strUnit = preg_replace('/[^a-z]/', '', $strUnit);
+ $strValue = preg_replace('/[^0-9]/', '', $strSize);
+ $value = intval($strValue);
- $value = intval(preg_replace('/[^0-9]/', '', $strSize));
+ //validazione
+ if (strlen(trim($strSize)) === 0) {
+ //una stringa vuota non può essere convertita
+ throw new Upload_Exc_Error();
+ } elseif (strlen(trim($strValue)) === 0) {
+ //se non trovo la parte del valore della stringa non posso convertire
+ throw new Upload_Exc_Error();
+ } elseif (strlen($strUnit) >= 1 && !array_key_exists($strUnit, $Units)) {
+ //l'unita' non e' nota
+ throw new Upload_Exc_Error();
+ }
- $Units = array('b' => 0, 'kb' => 1, 'mb' => 2, 'gb' => 3, 'tb' => 4);
$Exponent = isset($Units[$strUnit]) ? $Units[$strUnit] : 0;
return ($value * pow(1024, $Exponent));
--
Gitblit v1.8.0