Passed
Push — develop ( 4ec848...b3005b )
by BENARD
04:32
created

GameController::autocomplete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
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\Request;
10
use Symfony\Component\HttpFoundation\StreamedResponse;
11
use Symfony\Component\Routing\Annotation\Route;
12
use VideoGamesRecords\CoreBundle\Entity\Game;
13
use VideoGamesRecords\CoreBundle\Repository\GameRepository;
14
15
/**
16
 * Class GameController
17
 * @Route("/game")
18
 */
19
class GameController extends AbstractController
20
{
21
    private GameRepository $gameRepository;
22
    private FilesystemOperator $appStorage;
23
24
    private string $prefix = 'game/';
25
26
    public function __construct(GameRepository $gameRepository, FilesystemOperator $appStorage)
27
    {
28
        $this->gameRepository = $gameRepository;
29
        $this->appStorage = $appStorage;
30
    }
31
32
    /**
33
     * @param Request $request
34
     * @return mixed
35
     */
36
    public function listByLetter(Request $request): mixed
37
    {
38
        $letter = $request->query->get('letter', '0');
39
        $locale = $request->getLocale();
40
        return $this->gameRepository
41
            ->findWithLetter($letter, $locale)
42
            ->getResult();
43
    }
44
45
    /**
46
     * @Route(path="/{id}/picture", requirements={"id": "[1-9]\d*"}, name="vgr_core_game_picture", methods={"GET"})
47
     * @Cache(expires="+30 days")
48
     * @param Game $game
49
     * @return StreamedResponse
50
     * @throws FilesystemException
51
     */
52
    public function pictureAction(Game $game): StreamedResponse
53
    {
54
        $path = $this->prefix . $game->getPicture();
55
        if (!$this->appStorage->fileExists($path)) {
56
            $path = $this->prefix . 'default.png';
57
        }
58
59
        $stream = $this->appStorage->readStream($path);
60
        return new StreamedResponse(function() use ($stream) {
61
            fpassthru($stream);
62
        }, 200, ['Content-Type' => 'image/png']);
63
    }
64
}
65