Queue   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A trigger() 0 4 2
A add() 0 4 1
A __construct() 0 3 1
A process() 0 3 1
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