diff --git a/src/Command/TransferFileCommand.php b/src/Command/TransferFileCommand.php index 11e245c..737c187 100644 --- a/src/Command/TransferFileCommand.php +++ b/src/Command/TransferFileCommand.php @@ -90,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $serverId = $input->getArgument('targetserverid'); $method = $input->getOption('method'); $preserveModifiedTime = $input->getOption('preservemodifiedtime'); - $disableFileSizeCheck = $input->getOption('disablesizecheck'); + $disableFileSizeCheck = !($input->getOption('disablesizecheck')); $ftp = $this->ftpServiceBuilder->login($serverId); diff --git a/src/Service/Exception/NonMatchingFileSize.php b/src/Service/Exception/NonMatchingFileSize.php index 9a170d7..a8ee6e6 100644 --- a/src/Service/Exception/NonMatchingFileSize.php +++ b/src/Service/Exception/NonMatchingFileSize.php @@ -9,7 +9,11 @@ class NonMatchingFileSize extends \Exception public static function create(int $remoteFileSize, int $localFileSize): self { return new self( - sprintf('The download file size is diferent from the remote file size. Remote file has "%d" bytes, and the local file has "%d" bytes.', $remoteFileSize, $localFileSize) + sprintf( + 'The download file size is different from the remote file size. Remote file has "%d" bytes, and the local file has "%d" bytes.', + $remoteFileSize, + $localFileSize + ) ); } } diff --git a/src/Service/FTPService.php b/src/Service/FTPService.php index 59c3b55..18114eb 100644 --- a/src/Service/FTPService.php +++ b/src/Service/FTPService.php @@ -26,7 +26,7 @@ public function download( string $remotePath, string $localPath, bool $preserveModifiedTime, - bool $disableFileSizeCheck + bool $checkFileSize ): void { $remoteFiles = (array)$remotePath; if ($this->ftp->is_dir($remotePath)) { @@ -39,7 +39,7 @@ public function download( $remoteFile, rtrim($localPath, DIRECTORY_SEPARATOR) . $remoteFile, $preserveModifiedTime, - $disableFileSizeCheck + $checkFileSize ); } else { $realLocalPath = str_replace( @@ -69,7 +69,7 @@ public function download( ); } - $this->checkSize($disableFileSizeCheck, $remoteFile, $realLocalPath); + $this->checkSize($checkFileSize, $remoteFile, $realLocalPath); if ($preserveModifiedTime) { $originalFileModifiedTime = $this->ftp->filemtime($remoteFile); @@ -82,7 +82,7 @@ public function download( /** * @inheritDoc */ - public function upload(string $localPath, string $remotePath, bool $disableFileSizeCheck): void + public function upload(string $localPath, string $remotePath, bool $checkFileSize): void { $localFiles = (array)$localPath; if (is_dir($localPath)) { @@ -101,7 +101,7 @@ function (string $item) { foreach ($localFiles as $localFile) { if (is_dir($localFile)) { - $this->upload($localFile, rtrim($remotePath, DIRECTORY_SEPARATOR) . $localFile, $disableFileSizeCheck); + $this->upload($localFile, rtrim($remotePath, DIRECTORY_SEPARATOR) . $localFile, $checkFileSize); } else { $realRemotePath = str_replace( rtrim($localPath, DIRECTORY_SEPARATOR), @@ -129,7 +129,7 @@ function (string $item) { ); } - $this->checkSize($disableFileSizeCheck, $realRemotePath, $localPath); + $this->checkSize($checkFileSize, $realRemotePath, $localPath); } } } @@ -160,17 +160,17 @@ function (string $file) { } /** - * @param bool $disableFileSizeCheck + * @param bool $checkFileSize * @param $remoteFile * @param $realLocalPath * @throws NonMatchingFileSize */ - public function checkSize(bool $disableFileSizeCheck, string $remoteFile, string $realLocalPath): void + private function checkSize(bool $checkFileSize, string $remoteFile, string $realLocalPath): void { $sizeRemote = $this->ftp->size($remoteFile); $sizeLocal = filesize($realLocalPath); - if (!$disableFileSizeCheck && $sizeRemote !== $sizeLocal) { + if ($checkFileSize && $sizeRemote !== $sizeLocal) { throw NonMatchingFileSize::create($sizeRemote, $sizeLocal); } } diff --git a/src/Service/FTPServiceInterface.php b/src/Service/FTPServiceInterface.php index 30a47ce..6a64f34 100644 --- a/src/Service/FTPServiceInterface.php +++ b/src/Service/FTPServiceInterface.php @@ -11,7 +11,7 @@ interface FTPServiceInterface * @param string $remotePath * @param string $localPath * @param bool $preserveModifiedTime - * @param bool $disableFileSizeCheck + * @param bool $checkFileSize * @throws FTPCommandFailed * @throws FTPTransferFileFailed */ @@ -19,15 +19,15 @@ public function download( string $remotePath, string $localPath, bool $preserveModifiedTime, - bool $disableFileSizeCheck + bool $checkFileSize ): void; /** * @param string $localPath * @param string $remotePath - * @param bool $disableFileSizeCheck + * @param bool $checkFileSize * @throws FTPCommandFailed * @throws FTPTransferFileFailed */ - public function upload(string $localPath, string $remotePath, bool $disableFileSizeCheck): void; + public function upload(string $localPath, string $remotePath, bool $checkFileSize): void; }