Completed
Push — develop ( 1d6342...00212e )
by Nate
03:35
created

ElementListTrait::getSortable()   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 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-element-lists/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-element-lists/
7
 */
8
9
namespace flipbox\craft\element\lists\fields;
10
11
use craft\base\ElementInterface;
12
use craft\base\FieldInterface;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 2.0.0
17
 *
18
 * @mixin FieldInterface
19
 */
20
trait ElementListTrait
21
{
22
    use ModifyElementQueryTrait,
23
        NormalizeValueTrait,
24
        InputTrait;
25
26
    /**
27
     * @var bool
28
     */
29
    protected $ignoreSearchKeywords = true;
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function getSearchKeywords($value, ElementInterface $element): string
35
    {
36
        if ($this->ignoreSearchKeywords === true) {
37
            return '';
38
        }
39
40
        return parent::getSearchKeywords($value, $element);
41
    }
42
43
    /**
44
     * Identify whether a sort order should be enforced.
45
     *
46
     * @return bool
47
     */
48
    public function ensureSortOrder(): bool
49
    {
50
        return $this->sortable;
0 ignored issues
show
Bug introduced by
The property sortable does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
51
    }
52
53
    /**
54
     * Allow the settings to identify whether the element should be sortable
55
     *
56
     * @param bool $sortable
57
     * @return $this
58
     */
59
    public function setSortable(bool $sortable)
60
    {
61
        $this->sortable = $sortable;
62
        return $this;
63
    }
64
65
    /**
66
     * Get the sortable attribute value
67
     *
68
     * @return bool
69
     */
70
    public function getSortable(): bool
71
    {
72
        return $this->sortable;
73
    }
74
}
75