isValidDirectionForColumn()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
namespace musa11971\SortRequest;
4
5
use Illuminate\Support\Collection;
6
7
class SortableColumnCollection extends Collection
8
{
9
    /**
10
     * Checks whether the given column name can be sorted on.
11
     *
12
     * @param string $column
13
     * @return bool
14
     */
15
    function isValidColumn($column)
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...
16
    {
17
        $column = $this->find($column);
18
19
        return $column !== null;
20
    }
21
22
    /**
23
     * Checks whether the given direction is a valid one for the column.
24
     *
25
     * @param string $column
26
     * @param string $direction
27
     * @return bool
28
     */
29
    function isValidDirectionForColumn($column, $direction)
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...
30
    {
31
        $column = $this->find($column);
32
33
        if($column) {
34
            return in_array($direction, $column->sorter->getDirections());
35
        }
36
37
        return false;
38
    }
39
40
    /**
41
     * Returns the SortableColumn with the given name or null if not found.
42
     *
43
     * @param $column
44
     * @return SortableColumn|null
45
     */
46
    function find($column)
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...
47
    {
48
        foreach($this->items as $item) {
49
            if($item->name === $column) return $item;
50
        }
51
52
        return null;
53
    }
54
}