Passed
Pull Request — master (#191)
by Simon
12:27 queued 06:24
created

SolrIndexTrait::isDebug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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