Passed
Push — sheepy/introspection ( 17b395...901708 )
by Simon
08:33 queued 05:46
created

GetterSetterTrait   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Test Coverage

Coverage 96%

Importance

Changes 0
Metric Value
wmc 11
eloc 21
dl 0
loc 118
ccs 24
cts 25
cp 0.96
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getClasses() 0 3 1
A addBoostedField() 0 9 3
A addClass() 0 8 2
A getBoostedFields() 0 3 1
A getFacetFields() 0 3 1
A setBoostedFields() 0 5 1
A setClasses() 0 5 1
A setFacetFields() 0 5 1
1
<?php
2
3
4
namespace Firesphere\SolrSearch\Traits;
5
6
use SilverStripe\Dev\Deprecation;
7
8
trait GetterSetterTrait
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $class = [];
14
15
    /**
16
     * Sets boosting at _index_ time or _query_ time. Depending on the usage of this trait
17
     * [
18
     *     'FieldName' => 2,
19
     * ]
20
     * @var array
21
     */
22
    protected $boostedFields = [];
23
24
    /**
25
     * Format:
26
     * SiteTree::class   => [
27
     *      'Field' => 'SiteTree_ChannelID',
28
     *      'Title' => 'Channel'
29
     * ],
30
     * @var array
31
     */
32
    protected $facetFields = [];
33
34
    /**
35
     * @param array $class
36
     * @return $this
37
     */
38 58
    public function setClasses($class): self
39
    {
40 58
        $this->class = $class;
41
42 58
        return $this;
43
    }
44
45
    /**
46
     * $options is not used anymore, added for backward compatibility
47
     * @param $class
48
     * @param array $options unused
49
     * @return $this
50
     */
51 59
    public function addClass($class, $options = array()): self
52
    {
53 59
        if (count($options)) {
54
            Deprecation::notice('5.0', 'Options are not used anymore');
55
        }
56 59
        $this->class[] = $class;
57
58 59
        return $this;
59
    }
60
61
    /**
62
     * @return array
63
     */
64 63
    public function getClasses(): array
65
    {
66 63
        return $this->class;
67
    }
68
69
    /**
70
     * Add a boosted field to be boosted at query time
71
     *
72
     * @param string $field
73
     * @param array|int $options
74
     * @param int|null $boost
75
     * @return $this
76
     */
77 2
    public function addBoostedField($field, $options = [], $boost = null): self
78
    {
79 2
        if ($boost === null && is_int($options)) {
80 1
            $boost = $options;
81
        }
82
83 2
        $this->boostedFields[$field] = $boost;
84
85 2
        return $this;
86
    }
87
88
    /**
89
     * @return array
90
     */
91 37
    public function getBoostedFields(): array
92
    {
93 37
        return $this->boostedFields;
94
    }
95
96
    /**
97
     * Boosted fields are used at index time, not at query time
98
     *
99
     * @param array $boostedFields
100
     * @return $this
101
     */
102 58
    public function setBoostedFields($boostedFields): self
103
    {
104 58
        $this->boostedFields = $boostedFields;
105
106 58
        return $this;
107
    }
108
109
    /**
110
     * @return array
111
     */
112 37
    public function getFacetFields(): array
113
    {
114 37
        return $this->facetFields;
115
    }
116
117
    /**
118
     * @param array $facetFields
119
     * @return $this
120
     */
121 58
    public function setFacetFields($facetFields): self
122
    {
123 58
        $this->facetFields = $facetFields;
124
125 58
        return $this;
126
    }
127
}
128