Passed
Push — master ( 55cccf...e8fe62 )
by Thomas
02:53
created

GenericBulkAction::getI18nLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 1
c 1
b 1
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace LeKoala\Tabulator\BulkActions;
4
5
use SilverStripe\Control\HTTPRequest;
6
use LeKoala\Tabulator\AbstractBulkAction;
7
8
/**
9
 *  Generic bulk action that can run a callable
10
 */
11
class GenericBulkAction extends AbstractBulkAction
12
{
13
    protected string $name = '';
14
    protected string $label = '';
15
    protected $callable = null;
16
    protected bool $xhr = true;
17
18
    public function __construct($name, $label, $callable = null)
19
    {
20
        parent::__construct();
21
22
        $this->name = $name;
23
        $this->label = $label;
24
25
        if ($callable) {
26
            $this->callable = $callable;
27
        }
28
    }
29
30
    public function getI18nLabel(): string
31
    {
32
        return $this->getLabel();
33
    }
34
35
    public function process(HTTPRequest $request): string
36
    {
37
        $records = $this->getRecords() ?? [];
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getRecords() targeting LeKoala\Tabulator\AbstractBulkAction::getRecords() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
38
        $i = 0;
39
        foreach ($records as $record) {
40
            if ($this->callable) {
41
                $this->callable($record, $this->tabulatorGrid);
0 ignored issues
show
Bug introduced by
The method callable() does not exist on LeKoala\Tabulator\BulkActions\GenericBulkAction. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

41
                $this->/** @scrutinizer ignore-call */ 
42
                       callable($record, $this->tabulatorGrid);
Loading history...
42
            }
43
            $i++;
44
        }
45
        $result = _t(__CLASS__ . ".RECORDSPROCSSED", "{count} records processed", ["count" => $i]);
46
        return $result;
47
    }
48
49
    /**
50
     * Get the value of callable
51
     */
52
    public function getCallable()
53
    {
54
        return $this->callable;
55
    }
56
57
    /**
58
     * Set the value of callable
59
     *
60
     * @param callable $callable
61
     */
62
    public function setCallable($callable): self
63
    {
64
        $this->callable = $callable;
65
        return $this;
66
    }
67
}
68