ImageResponse::render()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Audio Player
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the LICENSE.md file.
7
 *
8
 * @author Marcel Scherello <[email protected]>
9
 * @author Olivier Paroz <[email protected]>
10
 * @copyright 2016-2021 Marcel Scherello
11
 */
12
13
namespace OCA\audioplayer\Http;
14
15
use OCP\AppFramework\Http\Response;
16
use OCP\AppFramework\Http;
17
18
/**
19
 * A renderer for cover arts
20
 */
21
class ImageResponse extends Response
22
{
23
24
    private $preview;
25
26
    /**
27
     * @param array $image image meta data
28
     * @param int $statusCode the Http status code, defaults to 200
29
     */
30
    public function __construct(array $image, $statusCode = Http::STATUS_OK)
31
    {
32
        $this->preview = $image['content'];
33
        $this->setStatus($statusCode);
34
        $this->addHeader('Content-type', $image['mimetype'] . '; charset=utf-8');
35
        $this->cacheFor(365 * 24 * 60 * 60);
36
        $etag = md5($image['content']);
37
        $this->setETag($etag);
38
    }
39
40
    /**
41
     * Returns the rendered image
42
     *
43
     * @return string the file
44
     */
45
    public function render()
46
    {
47
        if ($this->preview instanceof \OC_Image) {
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...
48
            return $this->preview->data();
49
        } else {
50
            return $this->preview;
51
        }
52
    }
53
}
54