Passed
Push — feature/locators-issue-82 ( cc09c7...259e0f )
by Sebastian
04:29
created

Context::setBibliographySpecificOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * citeproc-php
4
 *
5
 * @link        http://github.com/seboettg/citeproc-php for the source repository
6
 * @copyright   Copyright (c) 2016 Sebastian Böttger.
7
 * @license     https://opensource.org/licenses/MIT
8
 */
9
10
namespace Seboettg\CiteProc;
11
12
use Seboettg\CiteProc\Data\DataList;
13
use Seboettg\CiteProc\Locale\Locale;
14
use Seboettg\CiteProc\Root\Info;
15
use Seboettg\CiteProc\Style\Bibliography;
16
use Seboettg\CiteProc\Style\Citation;
17
use Seboettg\CiteProc\Style\Macro;
18
use Seboettg\CiteProc\Style\Options\BibliographyOptions;
19
use Seboettg\CiteProc\Style\Options\CitationOptions;
20
use Seboettg\CiteProc\Style\Options\GlobalOptions;
21
use Seboettg\CiteProc\Style\Sort\Sort;
22
use Seboettg\CiteProc\Root\Root;
23
use Seboettg\CiteProc\Styles\Css\CssStyle;
24
use Seboettg\Collection\ArrayList;
25
26
/**
27
 * Class Context
28
 * @package Seboettg\CiteProc
29
 *
30
 * @author Sebastian Böttger <[email protected]>
31
 */
32
class Context
33
{
34
    /**
35
     * @var ArrayList
36
     */
37
    private $macros;
38
39
    /**
40
     * @var Locale
41
     */
42
    private $locale;
43
44
    /**
45
     * @var Bibliography
46
     */
47
    private $bibliography;
48
49
    /**
50
     * @var Citation
51
     */
52
    private $citation;
53
54
    /**
55
     * @var Sort
56
     */
57
    private $sorting;
58
59
    /**
60
     * @var string
61
     */
62
    private $mode;
63
64
    /**
65
     * @var DataList
66
     */
67
    private $citationData;
68
69
    /**
70
     * @var ArrayList
71
     */
72
    private $citationItems;
73
74
    /**
75
     * @var ArrayList
76
     */
77
    private $results;
78
79
    /**
80
     * @var Root
81
     */
82
    private $root;
83
84
    /**
85
     * @var GlobalOptions
86
     */
87
    private $globalOptions;
88
89
    /**
90
     * @var BibliographyOptions
91
     */
92
    private $bibliographySpecificOptions;
93
94
    /**
95
     * @var CitationOptions
96
     */
97
    private $citationSpecificOptions;
98
99
    /**
100
     * @var RenderingState
101
     */
102
    private $renderingState;
103
104
    /**
105
     * @var CssStyle
106
     */
107
    private $cssStyle;
108
109
    /**
110
     * @var Info
111
     */
112
    private $info;
113
114
    /**
115
     * @var array
116
     */
117
    protected $markupExtension = [];
118
119
    /**
120
     * @var bool
121
     */
122
    private $citationsAsArray = false;
123
124
    /**
125
     * @var ArrayList
126
     */
127
    private $citedItems;
128
129 170
    public function __construct($locale = null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$locale" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$locale"; expected 0 but found 1
Loading history...
130
    {
131 170
        if (!empty($locale)) {
132 160
            $this->locale = $locale;
133
        }
134
135 170
        $this->macros = new ArrayList();
136 170
        $this->citationData = new DataList();
137 170
        $this->results = new ArrayList();
138 170
        $this->renderingState = RenderingState::RENDERING();
139 170
        $this->citedItems = new ArrayList();
140 170
    }
141
142 60
    public function addMacro($key, $macro)
143
    {
144 60
        $this->macros->add($key, $macro);
145 60
    }
146
147
    /**
148
     * @param $key
149
     * @return Macro
150
     */
151 54
    public function getMacro($key)
152
    {
153 54
        return $this->macros->get($key);
154
    }
155
156
    /**
157
     * @param Locale $locale
158
     */
159 169
    public function setLocale(Locale $locale)
160
    {
161 169
        $this->locale = $locale;
162 169
    }
163
164
    /**
165
     * @return Locale
166
     */
167 120
    public function getLocale()
168
    {
169 120
        return $this->locale;
170
    }
171
172
    /**
173
     * @return Bibliography
174
     */
175 68
    public function getBibliography()
176
    {
177 68
        return $this->bibliography;
178
    }
179
180
    /**
181
     * @param Bibliography $bibliography
182
     */
183 75
    public function setBibliography(Bibliography $bibliography)
184
    {
185 75
        $this->bibliography = $bibliography;
186 75
    }
187
188
    /**
189
     * @return Citation
190
     */
191 156
    public function getCitation()
192
    {
193 156
        return $this->citation;
194
    }
195
196
    /**
197
     * @param Citation $citation
198
     */
199 152
    public function setCitation($citation)
200
    {
201 152
        $this->citation = $citation;
202 152
    }
203
204
    /**
205
     * @param $citationsAsArray
206
     */
207 160
    public function setCitationsAsArray($citationsAsArray = true)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$citationsAsArray" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$citationsAsArray"; expected 0 but found 1
Loading history...
208
    {
209 160
        $this->citationsAsArray = $citationsAsArray;
210 160
    }
211
212 1
    public function isCitationsAsArray()
213
    {
214 1
        return $this->citationsAsArray;
215
    }
216
217 55
    public function setSorting($sorting)
218
    {
219 55
        $this->sorting = $sorting;
220 55
    }
221
222 156
    public function getSorting()
223
    {
224 156
        return $this->sorting;
225
    }
226
227
    /**
228
     * return the render mode (citation|bibliography)
229
     * @return string
230
     */
231 164
    public function getMode()
232
    {
233 164
        return $this->mode;
234
    }
235
236
    /**
237
     * @param string $mode
238
     */
239 156
    public function setMode($mode)
240
    {
241 156
        $this->mode = $mode;
242 156
    }
243
244
    /**
245
     * returns true if the render mode is set to citation
246
     * @return bool
247
     */
248 128
    public function isModeCitation()
249
    {
250 128
        return $this->mode === "citation";
251
    }
252
253
    /**
254
     * returns true if the render mode is set to bibliography
255
     * @return bool
256
     */
257 156
    public function isModeBibliography()
258
    {
259 156
        return $this->mode === "bibliography";
260
    }
261
262
    /**
263
     * @return DataList
264
     */
265 99
    public function getCitationData()
266
    {
267 99
        return $this->citationData;
268
    }
269
270
    /**
271
     * @param ArrayList|DataList $citationData
272
     */
273 69
    public function setCitationData($citationData)
274
    {
275 69
        $this->citationData = $citationData;
276 69
    }
277
278
    /**
279
     * @return ArrayList
280
     */
281
    public function getCitationItems(): ArrayList
282
    {
283
        return $this->citationItems;
284
    }
285
286
    /**
287
     * @param ArrayList $citationItems
288
     */
289 104
    public function setCitationItems(ArrayList $citationItems): void
290
    {
291 104
        $this->citationItems = $citationItems;
292 104
    }
293
294
    public function hasCitationItems()
295
    {
296
        return ($this->citationData->count() > 0);
297
    }
298
299
    /**
300
     * @return ArrayList
301
     */
302
    public function getMacros()
303
    {
304
        return $this->macros;
305
    }
306
307
    /**
308
     * @return ArrayList
309
     */
310 156
    public function getResults()
311
    {
312 156
        return $this->results;
313
    }
314
315
    /**
316
     * @return Root
317
     */
318 160
    public function getRoot()
319
    {
320 160
        return $this->root;
321
    }
322
323
    /**
324
     * @param Root $root
325
     */
326 160
    public function setRoot(Root $root)
327
    {
328 160
        $this->root = $root;
329 160
    }
330
331
    /**
332
     * @return GlobalOptions
333
     */
334 102
    public function getGlobalOptions()
335
    {
336 102
        return $this->globalOptions;
337
    }
338
339
    /**
340
     * @param GlobalOptions $globalOptions
341
     */
342 160
    public function setGlobalOptions(GlobalOptions $globalOptions)
343
    {
344 160
        $this->globalOptions = $globalOptions;
345 160
    }
346
347
    /**
348
     * @return RenderingState
349
     */
350 131
    public function getRenderingState()
351
    {
352 131
        return $this->renderingState;
353
    }
354
355
    /**
356
     * @param RenderingState|string $renderingState
357
     */
358 58
    public function setRenderingState(RenderingState $renderingState)
359
    {
360 58
        $this->renderingState = $renderingState;
361 58
    }
362
363
    /**
364
     * @return BibliographyOptions
365
     */
366 159
    public function getBibliographySpecificOptions()
367
    {
368 159
        return $this->bibliographySpecificOptions;
369
    }
370
371
    /**
372
     * @param BibliographyOptions $bibliographySpecificOptions
373
     */
374 75
    public function setBibliographySpecificOptions(BibliographyOptions $bibliographySpecificOptions)
375
    {
376 75
        $this->bibliographySpecificOptions = $bibliographySpecificOptions;
377 75
    }
378
379
    /**
380
     * @return CitationOptions
381
     */
382
    public function getCitationSpecificOptions()
383
    {
384
        return $this->citationSpecificOptions;
385
    }
386
387
    /**
388
     * @param CitationOptions $citationSpecificOptions
389
     */
390 152
    public function setCitationSpecificOptions(CitationOptions $citationSpecificOptions)
391
    {
392 152
        $this->citationSpecificOptions = $citationSpecificOptions;
393 152
    }
394
395
    /**
396
     * @param CssStyle $cssStyle
397
     */
398 3
    public function setCssStyle(CssStyle $cssStyle)
399
    {
400 3
        $this->cssStyle = $cssStyle;
401 3
    }
402
403
    /**
404
     * @return CssStyle
405
     */
406 3
    public function getCssStyle()
407
    {
408 3
        return $this->cssStyle;
409
    }
410
411 152
    public function setInfo(Info $info)
412
    {
413 152
        $this->info = $info;
414 152
    }
415
416 1
    public function getInfo()
417
    {
418 1
        return $this->info;
419
    }
420
421
    /**
422
     * @return array
423
     */
424 160
    public function getMarkupExtension()
425
    {
426 160
        return $this->markupExtension;
427
    }
428
429
    /**
430
     * @param array $markupExtension
431
     */
432 160
    public function setMarkupExtension($markupExtension)
433
    {
434 160
        $this->markupExtension = $markupExtension;
435 160
    }
436
437 12
    public function getCitationItemById($id)
438
    {
439
        return $this->citationItems->filter(function ($item) use ($id) {
440 7
            return $item->id === $id;
441 12
        })->current();
442
    }
443
444
    /**
445
     * @return ArrayList
446
     */
447 1
    public function getCitedItems(): ArrayList
448
    {
449 1
        return $this->citedItems;
450
    }
451
452
    /**
453
     * @param ArrayList $citedItems
454
     */
455
    public function setCitedItems(ArrayList $citedItems): void
456
    {
457
        $this->citedItems = $citedItems;
458
    }
459
460 104
    public function appendCitedItem($citedItem)
461
    {
462 104
        $this->citedItems->append($citedItem);
463 104
        return $this;
464
    }
465
}
466