ImportExamples::get_link()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
4
class ImportExamples extends ContentController
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
7
        "download" => "Admin"
8
    );
9
10
    public function download($request)
11
    {
12
        $importerClassName = $request->param("ID");
13
        $objectClassName = str_replace("Import", "", $importerClassName);
14
        if (class_exists($objectClassName)) {
15
            $obj = new $importerClassName($objectClassName);
16
            if ($obj instanceof CsvBulkLoader) {
17
                if ($fileData = $obj->getExportExampleData()) {
18
                    $fileName = $objectClassName.".csv";
19
                    return SS_HTTPRequest::send_file($fileData, $fileName, 'text/csv');
20
                } else {
21
                    user_error("Could not export import example", E_USER_ERROR);
22
                }
23
            } else {
24
                user_error("$obj->class is not an instance of CsvBulkLoader");
25
            }
26
        }
27
    }
28
29
    public static function get_link($className)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
30
    {
31
        return "ImportExamples/download/{$className}Import/";
32
    }
33
}
34