From ffdf0b8476bf9c03dc984c0f9f575b9136bc3c88 Mon Sep 17 00:00:00 2001 From: Shikiryu Date: Wed, 29 Jun 2016 21:31:16 +0200 Subject: [PATCH] Avoid variables with short names and unused functions --- app/code/Transport/Email.php | 64 +++--------------------------- app/code/backup/BackupAbstract.php | 8 ++-- app/code/backup/Mysql.php | 10 ++--- 3 files changed, 15 insertions(+), 67 deletions(-) diff --git a/app/code/Transport/Email.php b/app/code/Transport/Email.php index 4fa3c80..1ce2b4b 100644 --- a/app/code/Transport/Email.php +++ b/app/code/Transport/Email.php @@ -7,8 +7,8 @@ use Shikiryu\Backup\Backup\BackupAbstract; class Email extends TransportAbstract { - private $to; - private $from; + private $email_to; + private $email_from; private $encoding; private $subject; private $message; @@ -149,66 +149,14 @@ class Email extends TransportAbstract parent::__construct($backup, $config); $this->setFiles($this->backup->getFilesToBackup()); $this->setStreams($this->backup->getStreamsToBackup()); - $this->to = $this->config['to']; - $this->from = $this->config['from']; + $this->email_to = $this->config['to']; + $this->email_from = $this->config['from']; $this->encoding = $this->config['encoding']; $this->subject = $this->config['subject']; $this->message = $this->config['message']; $this->encoding = $this->config['encoding']; } - /** - * Add a recipient - * - * @param string $to - * - * @return $this - */ - private function addTo($to) - { - $this->to = $to; - return $this; - } - - /** - * Add the sender - * - * @param $from - * - * @return $this - */ - private function setFrom($from) - { - $this->from = $from; - return $this; - } - - /** - * Add the subject - * - * @param $sub - * - * @return $this - */ - private function setSubject($sub) - { - $this->subject = strip_tags($sub); - return $this; - } - - /** - * Add the message (in text) - * - * @param $mes - * - * @return $this - */ - private function setMessage($mes) - { - $this->message = strip_tags($mes); - return $this; - } - private function setFiles($files = array()) { if (is_array($files) && !empty($files)) { @@ -255,7 +203,7 @@ class Email extends TransportAbstract $this->files = array(TEMP_DIR.$zip_name=>$zip_name); $random_hash = md5(date('r', time())); - $headers = "From: " . $this->from . "\r\nReply-To: " . $this->from; + $headers = "From: " . $this->email_from . "\r\nReply-To: " . $this->email_from; $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"" . $random_hash . "\""; $output = " @@ -288,7 +236,7 @@ Content-Disposition: attachment; filename=" . $name . " " . chunk_split(base64_encode($stream)); } $output.="--$random_hash--"; - return mail($this->to, $this->subject, $output, $headers); + return mail($this->email_to, $this->subject, $output, $headers); } } diff --git a/app/code/backup/BackupAbstract.php b/app/code/backup/BackupAbstract.php index f8e262e..d00d7cf 100644 --- a/app/code/backup/BackupAbstract.php +++ b/app/code/backup/BackupAbstract.php @@ -56,19 +56,19 @@ abstract class BackupAbstract /** * Check if all files got the minimum given size. * - * @param int $fs + * @param int $file_size * * @return bool */ - public function checkMinimumFilesize($fs) + public function checkMinimumFilesize($file_size) { foreach ($this->_filesToBackup as $file => $name) { - if (filesize($file) < $fs) { + if (filesize($file) < $file_size) { return false; } } foreach ($this->_streamsToBackup as $name => $file) { - if (mb_strlen($file, 'utf-8') < $fs) { + if (mb_strlen($file, 'utf-8') < $file_size) { return false; } } diff --git a/app/code/backup/Mysql.php b/app/code/backup/Mysql.php index df8f8bf..897dafb 100644 --- a/app/code/backup/Mysql.php +++ b/app/code/backup/Mysql.php @@ -15,7 +15,7 @@ class Mysql extends BackupAbstract */ protected $tables; protected $host; - protected $db; + protected $database; protected $login; protected $pwd; @@ -35,7 +35,7 @@ class Mysql extends BackupAbstract if(!empty($tables)) { $this->tables = $tables; } - $this->_streamsToBackup[sprintf('db-%s.sql', $this->db)] = $this->getFromTables(); + $this->_streamsToBackup[sprintf('db-%s.sql', $this->database)] = $this->getFromTables(); return $this; } @@ -49,7 +49,7 @@ class Mysql extends BackupAbstract foreach($this->pdo->query('SHOW TABLES') as $table) { $this->tables[] = $table; } - $this->_streamsToBackup[sprintf('db-%s.sql', $this->db)] = $this->getFromTables(); + $this->_streamsToBackup[sprintf('db-%s.sql', $this->database)] = $this->getFromTables(); return $this; } @@ -71,7 +71,7 @@ class Mysql extends BackupAbstract $result2->execute(); $row2 = $result2->fetch(); $return.= "\n\n" . $row2[1] . ";\n\n"; - foreach($result as $i=>$row){ + foreach($result as $row){ $return.= 'INSERT INTO ' . $table . ' VALUES('; for ($j = 0; $j < $num_fields; $j++) { $row[$j] = addslashes($row[$j]); @@ -102,7 +102,7 @@ class Mysql extends BackupAbstract protected function preBuild() { - $this->pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->db, $this->login, $this->pwd); + $this->pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->database, $this->login, $this->pwd); } protected function postBuild()