BulkUnpublishAction   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
eloc 12
c 2
b 1
f 0
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 10 2
A getI18nLabel() 0 3 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 unpublishing records.
10
 */
11
class BulkUnpublishAction extends AbstractBulkAction
12
{
13
    protected string $name = 'unpublish';
14
    protected string $label = 'Unpublish';
15
    protected bool $xhr = true;
16
17
    public function getI18nLabel(): string
18
    {
19
        return _t(__CLASS__ . '.UNPUBLISH_SELECT_LABEL', $this->getLabel());
20
    }
21
22
    public function process(HTTPRequest $request): string
23
    {
24
        $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...
25
        $i = 0;
26
        foreach ($records as $record) {
27
            $record->doUnpublish();
28
            $i++;
29
        }
30
        $result = _t(__CLASS__ . ".RECORDSUNPUBLISHED", "{count} records unpublished", ["count" => $i]);
31
        return $result;
32
    }
33
}
34