MediaController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 17
ccs 0
cts 10
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A download() 0 13 2
1
<?php
2
3
namespace PiedWeb\CMSBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6
use Symfony\Component\HttpFoundation\BinaryFileResponse;
7
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
8
9
class MediaController extends AbstractController
10
{
11
    protected $translator;
12
13
    public function download(string $path)
14
    {
15
        $projectDir = $this->get('kernel')->getProjectDir();
16
        $pathToFile = $projectDir.'/media/'.substr(str_replace('..', '', $path), \strlen('media/'));
17
18
        if (! file_exists($pathToFile)) {
19
            throw $this->createNotFoundException('The media does not exist...');
20
        }
21
22
        $response = new BinaryFileResponse($pathToFile);
23
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
24
25
        return $response;
26
    }
27
}
28