Completed
Push — master ( b90ec7...90c42f )
by Robbie
9s
created

CommentsGridFieldConfig::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 32
rs 8.8571
cc 1
eloc 17
nc 1
nop 1
1
<?php
2
3
namespace SilverStripe\Comments\Admin;
4
5
use Colymba\BulkManager\BulkManager;
6
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\ApproveHandler;
7
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\SpamHandler;
8
use SilverStripe\Core\Convert;
9
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
10
use SilverStripe\Forms\GridField\GridFieldDataColumns;
11
12
class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
13
{
14
    public function __construct($itemsPerPage = 25)
15
    {
16
        parent::__construct($itemsPerPage);
17
18
        // $this->addComponent(new GridFieldExportButton());
0 ignored issues
show
Unused Code Comprehensibility introduced by Christopher Pitt
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
19
20
        $this->addComponent(new CommentsGridFieldAction());
21
22
        // Format column
23
        $columns = $this->getComponentByType(GridFieldDataColumns::class);
24
        $columns->setFieldFormatting(array(
25
            'ParentTitle' => function ($value, &$item) {
26
                return sprintf(
27
                    '<a href="%s" class="cms-panel-link external-link action" target="_blank">%s</a>',
28
                    Convert::raw2att($item->Link()),
29
                    $item->obj('ParentTitle')->forTemplate()
30
                );
31
            }
32
        ));
33
34
        // Add bulk option
35
        $manager = new BulkManager(null, false);
36
37
        $spamAction = SpamHandler::create()->setLabel(_t(__CLASS__ . '.SPAM', 'Spam'));
0 ignored issues
show
Documentation Bug introduced by Robbie Averill
The method setLabel does not exist on object<SilverStripe\Comm...BulkAction\SpamHandler>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
38
        $approveAction = ApproveHandler::create()->setLabel(_t(__CLASS__ . '.APPROVE', 'Approve'));
0 ignored issues
show
Documentation Bug introduced by Robbie Averill
The method setLabel does not exist on object<SilverStripe\Comm...kAction\ApproveHandler>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
39
40
        $manager
41
            ->addBulkAction($spamAction)
42
            ->addBulkAction($approveAction);
43
44
        $this->addComponent($manager);
45
    }
46
}
47