summaryrefslogtreecommitdiffstats
path: root/lib/private/Preview
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2017-03-19 20:30:46 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2017-03-19 20:30:46 +0100
commit0ad4b89d4168680e87e64919507895b8d7d5f158 (patch)
treed354eac840041bdcdee01bee242a3f233a7541d9 /lib/private/Preview
parent4cd13e76685f498c4f344bc786ecc8fe2cf91f7a (diff)
downloadnextcloud-server-0ad4b89d4168680e87e64919507895b8d7d5f158.tar.gz
nextcloud-server-0ad4b89d4168680e87e64919507895b8d7d5f158.zip
Some code cleanup
As suggested by the inspector Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Preview')
-rw-r--r--lib/private/Preview/Generator.php33
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php
index 9ccf6aaf4fe..fd75e51b638 100644
--- a/lib/private/Preview/Generator.php
+++ b/lib/private/Preview/Generator.php
@@ -26,6 +26,7 @@ namespace OC\Preview;
use OCP\Files\File;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IConfig;
@@ -163,9 +164,13 @@ class Generator {
continue;
}
- $path = strval($preview->width()) . '-' . strval($preview->height()) . '-max.png';
- $file = $previewFolder->newFile($path);
- $file->putContent($preview->data());
+ $path = (string)$preview->width() . '-' . (string)$preview->height() . '-max.png';
+ try {
+ $file = $previewFolder->newFile($path);
+ $file->putContent($preview->data());
+ } catch (NotPermittedException $e) {
+ throw new NotFoundException();
+ }
return $file;
}
@@ -190,7 +195,7 @@ class Generator {
* @return string
*/
private function generatePath($width, $height, $crop) {
- $path = strval($width) . '-' . strval($height);
+ $path = (string)$width . '-' . (string)$height;
if ($crop) {
$path .= '-crop';
}
@@ -251,18 +256,18 @@ class Generator {
/*
* Scale to the nearest power of two
*/
- $pow2height = pow(2, ceil(log($height) / log(2)));
- $pow2width = pow(2, ceil(log($width) / log(2)));
+ $pow2height = 2 ** ceil(log($height) / log(2));
+ $pow2width = 2 ** ceil(log($width) / log(2));
$ratioH = $height / $pow2height;
$ratioW = $width / $pow2width;
if ($ratioH < $ratioW) {
$width = $pow2width;
- $height = $height / $ratioW;
+ $height /= $ratioW;
} else {
$height = $pow2height;
- $width = $width / $ratioH;
+ $width /= $ratioH;
}
}
@@ -273,12 +278,12 @@ class Generator {
if ($height > $maxHeight) {
$ratio = $height / $maxHeight;
$height = $maxHeight;
- $width = $width / $ratio;
+ $width /= $ratio;
}
if ($width > $maxWidth) {
$ratio = $width / $maxWidth;
$width = $maxWidth;
- $height = $height / $ratio;
+ $height /= $ratio;
}
return [(int)round($width), (int)round($height)];
@@ -321,8 +326,12 @@ class Generator {
}
$path = $this->generatePath($width, $height, $crop);
- $file = $previewFolder->newFile($path);
- $file->putContent($preview->data());
+ try {
+ $file = $previewFolder->newFile($path);
+ $file->putContent($preview->data());
+ } catch (NotPermittedException $e) {
+ throw new NotFoundException();
+ }
return $file;
}