Passed
Push — develop ( cd2e6f...d56a5e )
by BENARD
04:22
created

Show   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 14
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 19 2
A __construct() 0 3 1
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Controller\Picture;
4
5
use Aws\S3\Exception\S3Exception;
6
use Aws\S3\S3Client;
7
use Exception;
8
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...
9
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10
use Symfony\Component\Routing\Annotation\Route;
11
use VideoGamesRecords\CoreBundle\Entity\Picture;
12
use VideoGamesRecords\CoreBundle\File\PictureCreatorFactory;
13
14
class Show extends AbstractController
15
{
16
    private S3Client $s3client;
17
18
    public function __construct(S3Client $s3client)
19
    {
20
        $this->s3client = $s3client;
21
    }
22
23
    /**
24
     * @Route(path="/proof/picture/{id}", requirements={"id": "[1-9]\d*"}, name="vgr_core_picture_index", methods={"GET"})
25
     * @Cache(expires="+30 days")
26
     * @param Picture $picture
27
     * @throws Exception
28
     */
29
    public function __invoke(Picture $picture): void
30
    {
31
        try {
32
            $result = $this->s3client->getObject(
33
                [
34
                    'Bucket' => $_ENV['AWS_S3_BUCKET_PROOF'],
35
                    'Key' => $picture->getPath(),
36
                ]
37
            );
38
39
            // Display the object in the browser.
40
            header("Content-Type: {$result['ContentType']}");
41
            echo $result['Body'];
42
        } catch (S3Exception $e) {
43
            chdir(__DIR__);
44
            $picture = PictureCreatorFactory::fromFile('../Resources/img/no_photo.gif');
45
            $picture->showPicture('gif');
46
        }
47
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
48
    }
49
}
50