Passed
Push — develop ( d64e19...d2a67e )
by BENARD
04:33
created

SerieController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A pictureAction() 0 11 2
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Controller;
4
5
use League\Flysystem\FilesystemException;
6
use League\Flysystem\FilesystemOperator;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
0 ignored issues
show
Bug introduced by
The type Sensio\Bundle\FrameworkE...dle\Configuration\Cache 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...
8
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9
use Symfony\Component\HttpFoundation\StreamedResponse;
10
use Symfony\Component\Routing\Annotation\Route;
11
use VideoGamesRecords\CoreBundle\Entity\Serie;
12
use VideoGamesRecords\CoreBundle\Repository\GameRepository;
13
14
/**
15
 * Class SerieController
16
 * @Route("/serie")
17
 */
18
class SerieController extends AbstractController
19
{
20
    private FilesystemOperator $appStorage;
21
22
    private string $prefix = 'serie/picture/';
23
24
    public function __construct(FilesystemOperator $appStorage)
25
    {
26
        $this->appStorage = $appStorage;
27
    }
28
29
30
    /**
31
     * @Route(path="/{id}/picture", requirements={"id": "[1-9]\d*"}, name="vgr_core_serie_picture", methods={"GET"})
32
     * @Cache(expires="+30 days")
33
     * @param Serie $serie
34
     * @return StreamedResponse
35
     * @throws FilesystemException
36
     */
37
    public function pictureAction(Serie $serie): StreamedResponse
38
    {
39
        $path = $this->prefix . $serie->getPicture();
40
        if (!$this->appStorage->fileExists($path)) {
41
            $path = $this->prefix . 'default.png';
42
        }
43
44
        $stream = $this->appStorage->readStream($path);
45
        return new StreamedResponse(function() use ($stream) {
46
            fpassthru($stream);
47
        }, 200, ['Content-Type' => 'image/png']);
48
    }
49
}
50