Passed
Push — new-api ( 4bfe18...7ec1cc )
by Sebastian
05:06
created

RenderingObserverTrait::notifyAll()   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
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\CiteProc\Context;
16
use Seboettg\Collection\ArrayList;
17
use Seboettg\Collection\ArrayList\ArrayListInterface;
18
19
trait RenderingObserverTrait
20
{
21
    /** @var RenderingMode */
22
    private $mode;
23
24
    /** @var ArrayListInterface */
25
    private $citationItems;
26
27
    /** @var RenderingState */
28
    private $state;
29
30
    /** @var Context */
31
    private $context;
32
33 177
    public function initObserver(): void
34
    {
35 177
        $this->mode = RenderingMode::BIBLIOGRAPHY();
36 177
        $this->state = RenderingState::RENDERING();
37 177
        $this->citationItems = new ArrayList();
38 177
    }
39
40 169
    public function notify(RenderingEvent $event): void
41
    {
42 169
        if ($event instanceof ModeChangedEvent) {
43 169
            $this->mode = $event->getMode();
44
        }
45 169
        if ($event instanceof CitationItemsChangedEvent) {
46 103
            $this->citationItems = $event->getCitationItems();
47
        }
48 169
        if ($event instanceof StateChangedEvent) {
49 60
            $this->state = $event->getRenderingState();
50
        }
51 169
    }
52
53 60
    public function notifyAll(RenderingEvent $event): void
54
    {
55 60
        $this->context->notifyObservers($event);
56 60
    }
57
58 177
    public function setContext(Context $context): void
59
    {
60 177
        $this->context = $context;
61 177
    }
62
}
63