HiddenDownloader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A download() 0 9 3
1
<?php
2
3
namespace Sunnysideup\ArrayToCsvDownload\Control;
4
use SilverStripe\Security\Security;
5
use SilverStripe\Security\Permission;
6
use Sunnysideup\ArrayToCsvDownload\Api\ArrayToCSV;
7
use SilverStripe\Control\Director;
8
use SilverStripe\Control\Controller;
9
use SilverStripe\Control\HTTPRequest;
10
11
use SilverStripe\Core\Config\Config;
12
13
class HiddenDownloader extends Controller
14
{
15
16
    private static $allowed_actions = [
17
        'download' => true,
18
    ];
19
20
21
    public function download(HTTPRequest $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

21
    public function download(/** @scrutinizer ignore-unused */ HTTPRequest $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...
22
    {
23
        if(! Permission::check('ADMIN')) {
24
            return Security::permissionFailure($this);
25
        }
26
        $fileName = $this->request->param('ID').'.csv';
27
        $hiddenDownloadDir = Config::inst()->get(ArrayToCSV::class, 'hidden_download_dir') ?: '_csv_download_dir';
28
        $path = Controller::join_links(Director::baseFolder(), $hiddenDownloadDir, $fileName);
29
        return HTTPRequest::send_file(file_get_contents($path), $fileName, 'text/csv');
30
    }
31
}
32