BulkDeleteAction::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace LeKoala\Tabulator\BulkActions;
4
5
use SilverStripe\Control\HTTPRequest;
6
use LeKoala\Tabulator\AbstractBulkAction;
7
8
/**
9
 * Bulk action handler for deleting records.
10
 */
11
class BulkDeleteAction extends AbstractBulkAction
12
{
13
    protected string $name = 'delete';
14
    protected string $label = 'Delete';
15
    protected bool $xhr = true;
16
    protected bool $destructive = true;
17
18
    public function getI18nLabel(): string
19
    {
20
        return _t(__CLASS__ . '.DELETE_SELECT_LABEL', $this->getLabel());
21
    }
22
23
    public function process(HTTPRequest $request): string
24
    {
25
        $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...
26
        $i = 0;
27
        foreach ($records as $record) {
28
            $record->delete();
29
            $i++;
30
        }
31
        $result = _t(__CLASS__ . ".RECORDSDELETED", "{count} records deleted", ["count" => $i]);
32
        return $result;
33
    }
34
}
35