ImageResponse   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A render() 0 6 2
1
<?php
2
/**
3
 * Nextcloud - 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 2017
11
 */
12
13
namespace OCA\Gallery\Http;
14
15
use OCP\AppFramework\Http\Response;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Http\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use OCP\AppFramework\Http;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Http was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
/**
19
 * A renderer for images
20
 *
21
 * @package OCA\Gallery\Http
22
 */
23
class ImageResponse extends Response {
24
25
	/**
26
	 * @var \OC_Image|string
0 ignored issues
show
Bug introduced by
The type OC_Image was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
	 */
28
	private $preview;
29
30
	/**
31
	 * Constructor
32
	 *
33
	 * @param array $image image meta data
34
	 * @param int $statusCode the HTTP status code, defaults to 200
35
	 */
36
	public function __construct(array $image, $statusCode = Http::STATUS_OK) {
37
		$name = $image['name'];
38
		$this->preview = $image['preview'];
39
40
		$this->setStatus($statusCode);
41
		$this->addHeader('Content-type', $image['mimetype'] . '; charset=utf-8');
42
		$this->addHeader('Content-Disposition',
43
						 'attachment; filename*=UTF-8\'\'' . rawurlencode($name) . '; filename="'
44
						 . rawurlencode($name) . '"'
45
		);
46
	}
47
48
	/**
49
	 * Returns the rendered image
50
	 *
51
	 * @return string the file
52
	 */
53
	public function render() {
54
		if ($this->preview instanceof \OC_Image) {
55
			// Uses imagepng() to output the image
56
			return $this->preview->data();
57
		} else {
58
			return $this->preview;
59
		}
60
	}
61
62
}
63