Completed
Pull Request — master (#187)
by Roeland
64:43
created

Preview::getPreview()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 4
crap 2
1
<?php
2
/**
3
 * Gallery
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Olivier Paroz <[email protected]>
9
 *
10
 * @copyright Olivier Paroz 2014-2016
11
 */
12
13
namespace OCA\Gallery\Preview;
14
15
use OCP\Files\File;
16
use OCP\Files\NotFoundException;
17
use OCP\Image;
18
use OCP\IPreview;
19
20
/**
21
 * Generates previews
22
 *
23
 * @package OCA\Gallery\Preview
24
 */
25
class Preview {
26
27
	/**
28
	 * @var IPreview
29
	 */
30
	private $previewManager;
31
32
	/**
33
	 * Constructor
34
	 *
35
	 * @param IPreview $previewManager
36
	 */
37
	public function __construct(
38
		IPreview $previewManager
39
	) {
40
		$this->previewManager = $previewManager;
41
	}
42
43
	/**
44
	 * Returns true if the passed mime type is supported
45
	 *
46
	 * @param string $mimeType
47
	 *
48
	 * @return boolean
49
	 */
50
	public function isMimeSupported($mimeType = '*') {
51
		return $this->previewManager->isMimeSupported($mimeType);
52
	}
53
54
	/**
55
	 * @param File $file
56
	 * @param int $maxX
57
	 * @param int $maxY
58
	 * @param bool $keepAspect
59
	 * @return false|array<string,string|\OC_Image>
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use false|array.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
60
	 */
61
	public function getPreview(File $file, $maxX, $maxY, $keepAspect) {
62
		try {
63
			$preview = $this->previewManager->getPreview($file, $maxX, $maxY, !$keepAspect);
64
		} catch (NotFoundException $e) {
0 ignored issues
show
Bug introduced by
The class OCP\Files\NotFoundException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
65
			return false;
66 35
		}
67
68
		$img = new Image($preview->getContent());
69
		return [
70
			'preview'  => $img,
71 35
			'mimetype' => $img->mimeType()
72 35
		];
73 35
	}
74 35
75
}
76