Completed
Push — master ( 9c68e4...6c4058 )
by James
02:53
created

EventObserver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 30
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A update() 0 5 2
1
<?php
2
3
namespace Fatindeed\GitlabWebhookHandler;
4
5
use SplSubject, SplObserver;
6
use TimoReymann\GitlabWebhookLibrary\Specification\Event;
7
8
/**
9
 * @see https://www.php.net/manual/zh/class.splobserver.php
10
 */
11
abstract class EventObserver implements SplObserver
12
{
13
    /**
14
     * Event type to be handled
15
     * 
16
     * @var array
17
     */
18
    protected $eventTypes = [];
19
20
    /**
21
     * Receive update from subject
22
     * 
23
     * @param  \SplSubject $subject
24
     * @return void
25
     */
26 2
    public function update(SplSubject $subject): void
27
    {
28 2
        $event = $subject->getEvent();
0 ignored issues
show
Bug introduced by
The method getEvent() does not exist on SplSubject. It seems like you code against a sub-type of SplSubject such as Fatindeed\GitlabWebhookHandler\EventSubject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        /** @scrutinizer ignore-call */ 
29
        $event = $subject->getEvent();
Loading history...
29 2
        if (in_array(get_class($event), $this->eventTypes)) {
30 2
            $this->process($event);
31
        }
32 2
    }
33
34
    /**
35
     * Process web hook event
36
     * 
37
     * @param  \TimoReymann\GitlabWebhookLibrary\Specification\Event $event
38
     * @return void
39
     */
40
    abstract public function process(Event $event): void;
41
}