Passed
Push — new-api ( 34a0a9...30b18d )
by Sebastian
04:06
created

RenderingObserverTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 28
ccs 12
cts 12
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initObserver() 0 5 1
A notify() 0 10 4
1
<?php
2
declare(strict_types=1);
3
/*
4
 * citeproc-php
5
 *
6
 * @link        http://github.com/seboettg/citeproc-php for the source repository
7
 * @copyright   Copyright (c) 2020 Sebastian Böttger.
8
 * @license     https://opensource.org/licenses/MIT
9
 */
10
11
namespace Seboettg\CiteProc\Rendering\Observer;
12
13
use Seboettg\CiteProc\Config\RenderingMode;
14
use Seboettg\CiteProc\Config\RenderingState;
15
use Seboettg\Collection\ArrayList;
16
use Seboettg\Collection\ArrayList\ArrayListInterface;
17
18
trait RenderingObserverTrait
19
{
20
    /** @var RenderingMode */
21
    private $mode;
22
23
    /** @var ArrayListInterface */
24
    private $citationItems;
25
26
    /** @var RenderingState */
27
    private $state;
28
29 117
    public function initObserver(): void
30
    {
31 117
        $this->mode = RenderingMode::BIBLIOGRAPHY();
32 117
        $this->state = RenderingState::RENDERING();
33 117
        $this->citationItems = new ArrayList();
34 117
    }
35
36 109
    public function notify(RenderingEvent $event): void
37
    {
38 109
        if ($event instanceof ModeChangedEvent) {
39 109
            $this->mode = $event->getMode();
40
        }
41 109
        if ($event instanceof CitationItemsChanged) {
42 44
            $this->citationItems = $event->getCitationItems();
43
        }
44 109
        if ($event instanceof StateChangedEvent) {
45 58
            $this->state = $event->getRenderingState();
46
        }
47 109
    }
48
}
49