ImageResponse   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 30
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A render() 0 6 2
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-2020 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 Rello
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