Passed
Pull Request — master (#191)
by Simon
06:45 queued 04:28
created

SolrIndexTrait::setDebug()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 3
rs 10
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
    /**
32
     * Singleton of {@link SolrCoreService}
33
     *
34
     * @var SolrCoreService
35
     */
36
    protected $service;
37
    /**
38
     * @var BaseIndex Current core being indexed
39
     */
40
    protected $index;
41
    /**
42
     * @var int Number of CPU cores available
43
     */
44
    protected $cores = 1;
45
    /**
46
     * Default batch length
47
     *
48
     * @var int
49
     */
50
    protected $batchLength = 500;
51
52
    /**
53
     * Set the {@link SolrCoreService}
54
     *
55
     * @param SolrCoreService $service
56
     * @return self
57
     */
58 16
    public function setService(SolrCoreService $service): self
59
    {
60 16
        $this->service = $service;
61
62 16
        return $this;
63
    }
64
65
    /**
66
     * Set the debug mode
67
     *
68
     * @param bool $debug Set the task in debug mode
69
     * @param bool $force Force a task in debug mode, despite e.g. being Live and not CLI
70
     * @return self
71
     */
72 16
    public function setDebug(bool $debug, bool $force = false): self
73
    {
74
        // Make the debug a configurable, forcing it to always be false from config
75 16
        if (!$force && SolrCoreService::config()->get('debug') === false) {
76 1
            $debug = false;
77
        }
78
79 16
        $this->debug = $debug;
80
81 16
        return $this;
82
    }
83
84
    /**
85
     * Is this Index in debug mode
86
     * @return bool
87
     */
88 14
    public function isDebug(): bool
89
    {
90 14
        return $this->debug;
91
    }
92
93
    /**
94
     * Get the Index class.
95
     *
96
     * @return BaseIndex
97
     */
98 14
    public function getIndex(): BaseIndex
99
    {
100 14
        return $this->index;
101
    }
102
103
    /**
104
     * Set the index class
105
     *
106
     * @param BaseIndex $index
107
     */
108 14
    public function setIndex(BaseIndex $index): void
109
    {
110 14
        $this->index = $index;
111 14
    }
112
113
    /**
114
     * Get the amount of CPU Cores configured
115
     *
116
     * @return int
117
     */
118 3
    public function getCores(): int
119
    {
120 3
        return $this->cores;
121
    }
122
123
    /**
124
     * Set the amount of CPU Cores to use
125
     *
126
     * @param int $cores
127
     */
128 16
    public function setCores(int $cores): void
129
    {
130 16
        $this->cores = $cores;
131 16
    }
132
133
    /**
134
     * Get the length of a single batch
135
     *
136
     * @return int
137
     */
138 13
    public function getBatchLength(): int
139
    {
140 13
        return $this->batchLength;
141
    }
142
143
    /**
144
     * Set the length of a single batch
145
     *
146
     * @param int $batchLength
147
     */
148 16
    public function setBatchLength(int $batchLength): void
149
    {
150 16
        $this->batchLength = $batchLength;
151 16
    }
152
}
153