Observer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A subscribe() 0 6 1
A fire() 0 6 2
1
<?php
2
/**
3
 * This file is part of GitterApi package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Gitter\Support;
11
12
/**
13
 * Class Observer
14
 * @package Gitter\Support
15
 */
16
class Observer
17
{
18
    /**
19
     * @var array|\Closure[]
20
     */
21
    private $subscribers = [];
22
23
    /**
24
     * @param \Closure $closure
25
     * @return Observer
26
     */
27
    public function subscribe(\Closure $closure): Observer
28
    {
29
        $this->subscribers[] = $closure;
30
31
        return $this;
32
    }
33
34
    /**
35
     * @param $data
36
     * @return void
37
     */
38
    public function fire($data)
39
    {
40
        foreach ($this->subscribers as $subscriber) {
41
            $subscriber($data);
42
        }
43
    }
44
}
45