Passed
Push — hans/its-the-same ( 539df6...6e935a )
by Simon
06:28
created

SolrIndexTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Test Coverage

Coverage 95.45%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 18
c 3
b 0
f 0
dl 0
loc 118
ccs 21
cts 22
cp 0.9545
rs 10
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setService() 0 5 1
A getBatchLength() 0 3 1
A setBatchLength() 0 3 1
A setCores() 0 3 1
A setIndex() 0 3 1
A getCores() 0 3 1
A setDebug() 0 10 2
A getIndex() 0 3 1
1
<?php
2
/**
3
 * Trait SolrIndexTrait|Firesphere\SolrSearch\Traits\SolrIndexTrait Used to extract methods from the
4
 * {@link \Firesphere\SolrSearch\Tasks\SolrIndexTask} to make the code more readable
5
 *
6
 * @package Firesphere\SolrSearch\Traits
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\Indexes\BaseIndex;
14
use Firesphere\SolrSearch\Services\SolrCoreService;
15
16
/**
17
 * Trait SolrIndexTrait
18
 * Getters and Setters for the SolrIndexTask
19
 *
20
 * @package Firesphere\SolrSearch\Traits
21
 */
22
trait SolrIndexTrait
23
{
24
    /**
25
     * Debug mode enabled, default false
26
     *
27
     * @var bool
28
     */
29
    protected $debug = false;
30
    /**
31
     * Singleton of {@link SolrCoreService}
32
     *
33
     * @var SolrCoreService
34
     */
35
    protected $service;
36
    /**
37
     * @var BaseIndex Current core being indexed
38
     */
39
    protected $index;
40
    /**
41
     * @var int Number of CPU cores available
42
     */
43
    protected $cores = 1;
44
    /**
45
     * Default batch length
46
     *
47
     * @var int
48
     */
49
    protected $batchLength = 500;
50
51
    /**
52
     * Set the {@link SolrCoreService}
53
     *
54
     * @param SolrCoreService $service
55
     * @return self
56
     */
57 15
    public function setService(SolrCoreService $service): self
58
    {
59 15
        $this->service = $service;
60
61 15
        return $this;
62
    }
63
64
    /**
65
     * Set the debug mode
66
     *
67
     * @param bool $debug
68
     * @return self
69
     */
70 15
    public function setDebug(bool $debug): self
71
    {
72
        // Make the debug a configurable, forcing it to always be false from config
73 15
        if (SolrCoreService::config()->get('debug') === false) {
74
            $debug = false;
75
        }
76
77 15
        $this->debug = $debug;
78
79 15
        return $this;
80
    }
81
82
    /**
83
     * Get the Index class.
84
     *
85
     * @return BaseIndex
86
     */
87 14
    public function getIndex(): BaseIndex
88
    {
89 14
        return $this->index;
90
    }
91
92
    /**
93
     * Set the index class
94
     *
95
     * @param BaseIndex $index
96
     */
97 14
    public function setIndex(BaseIndex $index): void
98
    {
99 14
        $this->index = $index;
100 14
    }
101
102
    /**
103
     * Get the amount of CPU Cores configured
104
     *
105
     * @return int
106
     */
107 3
    public function getCores(): int
108
    {
109 3
        return $this->cores;
110
    }
111
112
    /**
113
     * Set the amount of CPU Cores to use
114
     *
115
     * @param int $cores
116
     */
117 15
    public function setCores(int $cores): void
118
    {
119 15
        $this->cores = $cores;
120 15
    }
121
122
    /**
123
     * Get the length of a single batch
124
     *
125
     * @return int
126
     */
127 13
    public function getBatchLength(): int
128
    {
129 13
        return $this->batchLength;
130
    }
131
132
    /**
133
     * Set the length of a single batch
134
     *
135
     * @param int $batchLength
136
     */
137 15
    public function setBatchLength(int $batchLength): void
138
    {
139 15
        $this->batchLength = $batchLength;
140 15
    }
141
}
142