GetSetSchemaFactoryTrait   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 147
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypesTemplate() 0 3 1
A setStore() 0 3 1
A setTemplate() 0 5 1
A setTypesTemplate() 0 5 1
A getClassID() 0 3 1
A getTemplate() 0 3 1
A getIDField() 0 3 1
A getDefaultField() 0 3 1
A getIndex() 0 3 1
A setIndex() 0 8 1
A getIndexName() 0 3 1
1
<?php
2
/**
3
 * Trait GetSetSchemaFactoryTrait|Firesphere\SolrSearch\Traits\GetSetSchemaFactoryTrait Getters and setters
4
 * for {@link \Firesphere\SolrSearch\Factories\SchemaFactory}
5
 *
6
 * @package Firesphere\Solr\Search
7
 * @author Simon `Firesphere` Erkelens; Marco `Sheepy` Hermo
8
 * @copyright Copyright (c) 2018 - now() Firesphere & Sheepy
9
 */
10
11
namespace Firesphere\SolrSearch\Traits;
12
13
use Firesphere\SolrSearch\Factories\SchemaFactory;
14
use Firesphere\SolrSearch\Indexes\BaseIndex;
15
use Firesphere\SolrSearch\Services\SolrCoreService;
16
17
/**
18
 * Trait GetSetSchemaFactoryTrait
19
 *
20
 * Getters and setters for the schema factory
21
 *
22
 * @package Firesphere\Solr\Search
23
 */
24
trait GetSetSchemaFactoryTrait
25
{
26
    /**
27
     * ABSOLUTE Path to template
28
     *
29
     * @var string
30
     */
31
    protected $template;
32
    /**
33
     * Store the value in Solr
34
     *
35
     * @var bool
36
     */
37
    protected $store = false;
38
    /**
39
     * Index to generate the schema for
40
     *
41
     * @var BaseIndex
42
     */
43
    protected $index;
44
    /**
45
     * ABSOLUTE Path to types.ss template
46
     *
47
     * @var string
48
     */
49
    protected $typesTemplate;
50
51
    /**
52
     * Set the store value
53
     *
54
     * @param bool $store
55
     */
56 54
    public function setStore(bool $store): void
57
    {
58 54
        $this->store = $store;
59 54
    }
60
61
    /**
62
     * Get the Index that's being used
63
     *
64
     * @return BaseIndex
65
     */
66 1
    public function getIndex()
67
    {
68 1
        return $this->index;
69
    }
70
71
    /**
72
     * Set the index that's being used and add the introspection for it
73
     *
74
     * @param BaseIndex $index
75
     * @return SchemaFactory
76
     */
77 54
    public function setIndex($index): self
78
    {
79 54
        $this->index = $index;
80
        // Add the index to the introspection as well, there's no need for a separate call here
81
        // We're loading this core, why would we want the introspection from a different index?
82 54
        $this->fieldResolver->setIndex($index);
83
84 54
        return $this;
85
    }
86
87
    /**
88
     * Get the name of the index being used
89
     *
90
     * @return string
91
     */
92 37
    public function getIndexName(): string
93
    {
94 37
        return $this->index->getIndexName();
95
    }
96
97
    /**
98
     * Get the default field to generate df components for
99
     *
100
     * @return string|array
101
     */
102 37
    public function getDefaultField()
103
    {
104 37
        return $this->index->getDefaultField();
105
    }
106
107
    /**
108
     * Get the Identifier Field for Solr
109
     *
110
     * @return string
111
     */
112 36
    public function getIDField(): string
113
    {
114 36
        return SolrCoreService::ID_FIELD;
115
    }
116
117
    /**
118
     * Get the Identifier Field for Solr
119
     *
120
     * @return string
121
     */
122 36
    public function getClassID(): string
123
    {
124 36
        return SolrCoreService::CLASS_ID_FIELD;
125
    }
126
127
    /**
128
     * Get the types template if defined
129
     *
130
     * @return string
131
     */
132 36
    public function getTypesTemplate()
133
    {
134 36
        return $this->typesTemplate;
135
    }
136
137
    /**
138
     * Set custom types template
139
     *
140
     * @param string $typesTemplate
141
     * @return SchemaFactory
142
     */
143 36
    public function setTypesTemplate($typesTemplate): self
144
    {
145 36
        $this->typesTemplate = $typesTemplate;
146
147 36
        return $this;
148
    }
149
150
    /**
151
     * Get the base template for the schema xml
152
     *
153
     * @return string
154
     */
155 36
    public function getTemplate()
156
    {
157 36
        return $this->template;
158
    }
159
160
    /**
161
     * Set a custom template for schema xml
162
     *
163
     * @param string $template
164
     * @return SchemaFactory
165
     */
166 36
    public function setTemplate($template): self
167
    {
168 36
        $this->template = $template;
169
170 36
        return $this;
171
    }
172
}
173