Passed
Pull Request — hans/guzzle-to-psr (#261)
by
unknown
21:06
created

SolrIndexTrait::setIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\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\IndexTraits;
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\Solr\Search
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
    public function setService(SolrCoreService $service): self
58
    {
59
        $this->service = $service;
60
61
        return $this;
62
    }
63
64
    /**
65
     * Is this Index in debug mode
66
     *
67
     * @return bool
68
     */
69
    public function isDebug(): bool
70
    {
71
        return $this->debug;
72
    }
73
74
    /**
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
    {
83
        // Make the debug a configurable, forcing it to always be false from config
84
        if (!$force && SolrCoreService::config()->get('debug') === false) {
85
            $debug = false;
86
        }
87
88
        $this->debug = $debug;
89
90
        return $this;
91
    }
92
93
    /**
94
     * Get the Index class.
95
     *
96
     * @return BaseIndex
97
     */
98
    public function getIndex(): BaseIndex
99
    {
100
        return $this->index;
101
    }
102
103
    /**
104
     * Set the index class
105
     *
106
     * @param BaseIndex $index
107
     */
108
    public function setIndex(BaseIndex $index): void
109
    {
110
        $this->index = $index;
111
    }
112
113
    /**
114
     * Get the amount of CPU Cores configured
115
     *
116
     * @return int
117
     */
118
    public function getCores(): int
119
    {
120
        return $this->cores;
121
    }
122
123
    /**
124
     * 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
133
    /**
134
     * Get the length of a single batch
135
     *
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