Completed
Pull Request — master (#8)
by Damien
05:56
created

ElementListTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 63
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSearchKeywords() 0 8 2
A ensureSortOrder() 0 4 1
A setSortable() 0 5 1
A getSortable() 0 4 1
A serializeValue() 0 4 1
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
    /**
76
     * @inheritdoc
77
     */
78
    public function serializeValue($value, ElementInterface $element = null)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $element is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
    {
80
        return null;
81
    }
82
}
83