From 2ff97917e9e72b674de07ca05dc04dd3bea14f07 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 11 Jun 2013 10:56:16 +0200 Subject: [PATCH] code optimization --- lib/preview/images.php | 5 +---- lib/preview/movies.php | 5 ++--- lib/preview/mp3.php | 4 +--- lib/preview/pdf.php | 4 +--- lib/preview/svg.php | 4 +--- lib/preview/txt.php | 4 +--- 6 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/preview/images.php b/lib/preview/images.php index 080e424e5b..e4041538e9 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -26,10 +26,7 @@ class Image extends Provider { $image->loadFromFile($fileview->getLocalFile($path)); } - //check if image object is valid - if (!$image->valid()) return false; - - return $image; + return $image->valid() ? $image : false; } } diff --git a/lib/preview/movies.php b/lib/preview/movies.php index 8cd50263e2..cb959a962a 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -27,14 +27,13 @@ if(!is_null(shell_exec('ffmpeg -version'))) { $cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmppath); shell_exec($cmd); - unlink($abspath); $image = new \OC_Image($tmppath); - if (!$image->valid()) return false; + unlink($abspath); unlink($tmppath); - return $image; + return $image->valid() ? $image : false; } } diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 660e9fc3ce..60dfb5ff46 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -28,9 +28,7 @@ class MP3 extends Provider { unlink($tmppath); $image = new \OC_Image($picture); - if (!$image->valid()) return $this->getNoCoverThumbnail($maxX, $maxY); - - return $image; + return $image->valid() ? $image : $this->getNoCoverThumbnail($maxX, $maxY); } public function getNoCoverThumbnail($maxX, $maxY) { diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index f1d0a33dc6..3eabd20115 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -32,9 +32,7 @@ if (extension_loaded('imagick')) { //new image object $image = new \OC_Image($pdf); //check if image object is valid - if (!$image->valid()) return false; - - return $image; + return $image->valid() ? $image : false; } } diff --git a/lib/preview/svg.php b/lib/preview/svg.php index 76d81589ba..bafaf71b15 100644 --- a/lib/preview/svg.php +++ b/lib/preview/svg.php @@ -35,9 +35,7 @@ if (extension_loaded('imagick')) { //new image object $image = new \OC_Image($svg); //check if image object is valid - if (!$image->valid()) return false; - - return $image; + return $image->valid() ? $image : false; } } diff --git a/lib/preview/txt.php b/lib/preview/txt.php index f18da66c3b..c7b8fabc6b 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -42,9 +42,7 @@ class TXT extends Provider { $image = new \OC_Image($image); - if (!$image->valid()) return false; - - return $image; + return $image->valid() ? $image : false; } }