Passed
Push — master ( aec283...98a649 )
by Thomas
22:11 queued 11:07
created

TabulatorExportButton   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 17
c 1
b 0
f 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 4 1
A forTemplate() 0 25 6
1
<?php
2
3
namespace LeKoala\Tabulator;
4
5
use LeKoala\ExcelImportExport\ExcelGridFieldExportButton;
0 ignored issues
show
Bug introduced by
The type LeKoala\ExcelImportExpor...elGridFieldExportButton 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...
6
use SilverStripe\ORM\DataObject;
7
use SilverStripe\ORM\RelationList;
8
use SilverStripe\View\ArrayData;
9
10
/**
11
 * This component provides a button for exporting data
12
 * Depends on excel-import-export module
13
 */
14
class TabulatorExportButton extends AbstractTabulatorTool
15
{
16
    public function forTemplate()
17
    {
18
        $grid = $this->tabulatorGrid;
19
        $singleton = singleton($grid->getModelClass());
20
        $context = [];
21
        if ($grid->getList() instanceof RelationList) {
22
            $record = $grid->getForm()->getRecord();
23
            if ($record && $record instanceof DataObject) {
0 ignored issues
show
introduced by
$record is always a sub-type of SilverStripe\ORM\DataObject.
Loading history...
24
                $context['Parent'] = $record;
25
            }
26
        }
27
28
        if (!$singleton->canCreate(null, $context)) {
29
            return false;
30
        }
31
32
        if (!$this->buttonName) {
33
            // provide a default button name, can be changed by calling {@link setButtonName()} on this component
34
            $this->buttonName = _t('Tabulator.ExportRecords', 'Export');
0 ignored issues
show
Bug Best Practice introduced by
The property buttonName does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
35
        }
36
37
        $data = new ArrayData([
38
            'ButtonName' => $this->buttonName,
39
        ]);
40
        return $this->renderWith($this->getViewerTemplates(), $data);
0 ignored issues
show
Bug introduced by
$data of type SilverStripe\View\ArrayData is incompatible with the type array expected by parameter $customFields of SilverStripe\View\ViewableData::renderWith(). ( Ignorable by Annotation )

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

40
        return $this->renderWith($this->getViewerTemplates(), /** @scrutinizer ignore-type */ $data);
Loading history...
41
    }
42
43
    public function index()
44
    {
45
        $btn = new ExcelGridFieldExportButton();
46
        return $btn->handleExport($this->tabulatorGrid);
47
    }
48
}
49