Completed
Push — master ( ad2c0d...49711d )
by Yaro
10:29
created

PreferencesHelperTrait::saveCurrentLocale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Yaro\Jarboe\Table\CrudTraits;
4
5
trait PreferencesHelperTrait
6
{
7
    private $tableIdentifier;
8
9
    /**
10
     * @param null $ident
11
     * @return mixed|void
12
     */
13 17
    public function tableIdentifier($ident = null)
14
    {
15 17
        if (is_null($ident)) {
16 4
            return $this->tableIdentifier;
17
        }
18
19 17
        $this->tableIdentifier = $ident;
20 17
    }
21
22
    public function getCurrentLocale()
23
    {
24
        return $this->preferences()->getCurrentLocale($this->tableIdentifier()) ?: key($this->getLocales());
0 ignored issues
show
Bug introduced by
It seems like getLocales() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
25
    }
26
27
    public function saveCurrentLocale($locale)
28
    {
29
        $this->preferences()->saveCurrentLocale($this->tableIdentifier(), $locale);
30
    }
31
32 1
    public function getPerPageParam()
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...
33
    {
34 1
        return $this->preferences()->getPerPageParam($this->tableIdentifier());
35
    }
36
37 1
    public function setPerPageParam($perPage)
38
    {
39 1
        $this->preferences()->setPerPageParam($this->tableIdentifier(), $perPage);
40 1
    }
41
42 1
    public function saveSearchFilterParams(array $params)
43
    {
44 1
        $this->preferences()->saveSearchFilterParams($this->tableIdentifier(), $params);
45 1
    }
46
47 1
    public function getOrderFilterParam($column)
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...
48
    {
49 1
        return $this->preferences()->getOrderFilterParam($this->tableIdentifier(), $column);
50
    }
51
52 1
    public function saveOrderFilterParam($column, $direction)
53
    {
54 1
        $this->preferences()->saveOrderFilterParam($this->tableIdentifier(), $column, $direction);
55 1
    }
56
57 1
    public function isSortableByWeightActive()
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...
58
    {
59 1
        return $this->preferences()->isSortableByWeightActive($this->tableIdentifier());
60
    }
61
62
    public function setSortableOrderState(bool $active)
63
    {
64
        $this->preferences()->setSortableOrderState($this->tableIdentifier(), $active);
65
    }
66
67
    abstract public function preferences();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
68
}
69