Passed
Pull Request — master (#5)
by Cody
03:17
created

Configuration   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 335
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 61
c 0
b 0
f 0
dl 0
loc 335
rs 9.84
wmc 32
1
<?php
2
3
namespace andreskrey\Readability;
4
5
use Psr\Log\LoggerAwareTrait;
6
use Psr\Log\LoggerInterface;
7
use Psr\Log\NullLogger;
8
9
/**
10
 * Class Configuration.
11
 */
12
class Configuration
13
{
14
    use LoggerAwareTrait;
15
16
    /**
17
     * @var int
18
     */
19
    protected $maxTopCandidates = 5;
20
21
    /**
22
     * @var int
23
     */
24
    protected $charThreshold = 500;
25
26
    /**
27
     * @var bool
28
     */
29
    protected $articleByLine = false;
30
31
    /**
32
     * @var bool
33
     */
34
    protected $stripUnlikelyCandidates = true;
35
36
    /**
37
     * @var bool
38
     */
39
    protected $cleanConditionally = true;
40
41
    /**
42
     * @var bool
43
     */
44
    protected $weightClasses = true;
45
46
    /**
47
     * @var bool
48
     */
49
    protected $fixRelativeURLs = false;
50
51
    /**
52
     * @var bool
53
     */
54
    protected $substituteEntities = false;
55
56
    /**
57
     * @var bool
58
     */
59
    protected $normalizeEntities = false;
60
61
    /**
62
     * @var bool
63
     */
64
    protected $summonCthulhu = false;
65
66
    /**
67
     * @var string
68
     */
69
    protected $originalURL = 'http://fakehost';
70
71
    /**
72
     * Configuration constructor.
73
     *
74
     * @param array $params
75
     */
76
    public function __construct(array $params = [])
77
    {
78
        foreach ($params as $key => $value) {
79
            $setter = sprintf('set%s', $key);
80
            if (method_exists($this, $setter)) {
81
                call_user_func([$this, $setter], $value);
82
            }
83
        }
84
    }
85
86
    /**
87
     * Returns an array-representation of configuration.
88
     *
89
     * @return array
90
     */
91
    public function toArray()
92
    {
93
        $out = [];
94
        foreach ($this as $key => $value) {
95
            $getter = sprintf('get%s', $key);
96
            if (!is_object($value) && method_exists($this, $getter)) {
97
                $out[$key] = call_user_func([$this, $getter]);
98
            }
99
        }
100
101
        return $out;
102
    }
103
104
    /**
105
     * @return LoggerInterface
106
     */
107
    public function getLogger()
108
    {
109
        // If no logger has been set, just return a null logger
110
        if ($this->logger === null) {
111
            return new NullLogger();
112
        }
113
114
        return $this->logger;
115
    }
116
117
    /**
118
     * @param LoggerInterface $logger
119
     *
120
     * @return Configuration
121
     */
122
    public function setLogger(LoggerInterface $logger)
123
    {
124
        $this->logger = $logger;
125
126
        return $this;
127
    }
128
129
    /**
130
     * @return int
131
     */
132
    public function getMaxTopCandidates()
133
    {
134
        return $this->maxTopCandidates;
135
    }
136
137
    /**
138
     * @param int $maxTopCandidates
139
     *
140
     * @return $this
141
     */
142
    public function setMaxTopCandidates($maxTopCandidates)
143
    {
144
        $this->maxTopCandidates = $maxTopCandidates;
145
146
        return $this;
147
    }
148
149
    /**
150
     * @return int
151
     */
152
    public function getCharThreshold()
153
    {
154
        return $this->charThreshold;
155
    }
156
157
    /**
158
     * @param int $charThreshold
159
     *
160
     * @return $this
161
     */
162
    public function setCharThreshold($charThreshold)
163
    {
164
        $this->charThreshold = $charThreshold;
165
166
        return $this;
167
    }
168
169
    /**
170
     * @return bool
171
     */
172
    public function getArticleByLine()
173
    {
174
        return $this->articleByLine;
175
    }
176
177
    /**
178
     * @param bool $articleByLine
179
     *
180
     * @return $this
181
     */
182
    public function setArticleByLine($articleByLine)
183
    {
184
        $this->articleByLine = $articleByLine;
185
186
        return $this;
187
    }
188
189
    /**
190
     * @return bool
191
     */
192
    public function getStripUnlikelyCandidates()
193
    {
194
        return $this->stripUnlikelyCandidates;
195
    }
196
197
    /**
198
     * @param bool $stripUnlikelyCandidates
199
     *
200
     * @return $this
201
     */
202
    public function setStripUnlikelyCandidates($stripUnlikelyCandidates)
203
    {
204
        $this->stripUnlikelyCandidates = $stripUnlikelyCandidates;
205
206
        return $this;
207
    }
208
209
    /**
210
     * @return bool
211
     */
212
    public function getCleanConditionally()
213
    {
214
        return $this->cleanConditionally;
215
    }
216
217
    /**
218
     * @param bool $cleanConditionally
219
     *
220
     * @return $this
221
     */
222
    public function setCleanConditionally($cleanConditionally)
223
    {
224
        $this->cleanConditionally = $cleanConditionally;
225
226
        return $this;
227
    }
228
229
    /**
230
     * @return bool
231
     */
232
    public function getWeightClasses()
233
    {
234
        return $this->weightClasses;
235
    }
236
237
    /**
238
     * @param bool $weightClasses
239
     *
240
     * @return $this
241
     */
242
    public function setWeightClasses($weightClasses)
243
    {
244
        $this->weightClasses = $weightClasses;
245
246
        return $this;
247
    }
248
249
    /**
250
     * @return bool
251
     */
252
    public function getFixRelativeURLs()
253
    {
254
        return $this->fixRelativeURLs;
255
    }
256
257
    /**
258
     * @param bool $fixRelativeURLs
259
     *
260
     * @return $this
261
     */
262
    public function setFixRelativeURLs($fixRelativeURLs)
263
    {
264
        $this->fixRelativeURLs = $fixRelativeURLs;
265
266
        return $this;
267
    }
268
269
    /**
270
     * @return bool
271
     */
272
    public function getSubstituteEntities()
273
    {
274
        return $this->substituteEntities;
275
    }
276
277
    /**
278
     * @param bool $substituteEntities
279
     *
280
     * @return $this
281
     */
282
    public function setSubstituteEntities($substituteEntities)
283
    {
284
        $this->substituteEntities = $substituteEntities;
285
286
        return $this;
287
    }
288
289
    /**
290
     * @return bool
291
     */
292
    public function getNormalizeEntities()
293
    {
294
        return $this->normalizeEntities;
295
    }
296
297
    /**
298
     * @param bool $normalizeEntities
299
     *
300
     * @return $this
301
     */
302
    public function setNormalizeEntities($normalizeEntities)
303
    {
304
        $this->normalizeEntities = $normalizeEntities;
305
306
        return $this;
307
    }
308
309
    /**
310
     * @return string
311
     */
312
    public function getOriginalURL()
313
    {
314
        return $this->originalURL;
315
    }
316
317
    /**
318
     * @param string $originalURL
319
     *
320
     * @return $this
321
     */
322
    public function setOriginalURL($originalURL)
323
    {
324
        $this->originalURL = $originalURL;
325
326
        return $this;
327
    }
328
329
    /**
330
     * @return bool
331
     */
332
    public function getSummonCthulhu()
333
    {
334
        return $this->summonCthulhu;
335
    }
336
337
    /**
338
     * @param bool $summonCthulhu
339
     *
340
     * @return $this
341
     */
342
    public function setSummonCthulhu($summonCthulhu)
343
    {
344
        $this->summonCthulhu = $summonCthulhu;
345
346
        return $this;
347
    }
348
}
349