setGridFieldUserColumnsFor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace SilverStripe\GridFieldAddOns;
4
5
use SilverStripe\ORM\DataExtension;
6
7
class GridFieldUserColumnsExtension extends DataExtension
8
{
9
10
    private static $db = [
11
        'GridFieldUserColumns' => 'Text'
12
    ];
13
14
    function getGridFieldUserColumnsFor($gridfielddataclass)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
15
    {
16
        if (!$this->owner->GridFieldUserColumns) {
17
            return false;
18
        }
19
        $columns = unserialize($this->owner->GridFieldUserColumns);
20
        return isset($columns[$gridfielddataclass]) ? $columns[$gridfielddataclass] : false;
21
    }
22
23
    function setGridFieldUserColumnsFor($gridfielddataclass, $newcolumns)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
24
    {
25
        $columns = $this->owner->GridFieldUserColumns ? unserialize($this->owner->GridFieldUserColumns) : array();
26
        $columns[$gridfielddataclass] = $newcolumns;
27
        $this->owner->GridFieldUserColumns = serialize($columns);
28
        $this->owner->write();
29
    }
30
}
31