Queue::process()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stratadox\ObservationQueue;
6
7
use SplQueue;
8
9
class Queue implements QueuesObservations
10
{
11
    private $observations;
12
13
    public function __construct()
14
    {
15
        $this->observations = new SplQueue;
16
    }
17
18
    public function add($observer, string $method, ...$params) : void
19
    {
20
        $this->observations->enqueue(
21
            new Observation($observer, $method, ...$params)
22
        );
23
    }
24
25
    public function trigger() : void
26
    {
27
        while (!$this->observations->isEmpty()) {
28
            $this->process($this->observations->dequeue());
29
        }
30
    }
31
32
    private function process(Observation $observation) : void
33
    {
34
        $observation->trigger();
35
    }
36
}
37