Completed
Push — master ( 4359be...3bba38 )
by Dev
05:22
created

MediaController::download()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 4
dl 0
loc 17
ccs 0
cts 13
cp 0
crap 6
rs 10
1
<?php
2
3
namespace PiedWeb\CMSBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\Translation\TranslatorInterface;
8
use PiedWeb\CMSBundle\Entity\PageInterface as Page;
9
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
10
use Symfony\Component\HttpFoundation\BinaryFileResponse;
11
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
12
13
class MediaController extends AbstractController
14
{
15
    protected $translator;
16
17
    public function download(
18
        string $path,
19
        Request $request,
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

19
        /** @scrutinizer ignore-unused */ Request $request,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
20
        TranslatorInterface $translator,
0 ignored issues
show
Unused Code introduced by
The parameter $translator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

20
        /** @scrutinizer ignore-unused */ TranslatorInterface $translator,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
        ParameterBagInterface $params
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

21
        /** @scrutinizer ignore-unused */ ParameterBagInterface $params

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
    ) {
23
24
        $pathToFile = $this->get('kernel')->getProjectDir().'/media/'.substr(str_replace('..', '', $path), strlen('media/'));
25
26
        if (!file_exists($pathToFile)) {
27
            throw $this->createNotFoundException('The media does not exist...');
28
        }
29
30
        $response = new BinaryFileResponse($pathToFile);
31
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
32
33
        return $response;
34
35
    }
36
}
37