Completed
Push — master ( b13999...6c5a6e )
by Filipe
01:56
created

ProgressStateProviderMethods::notifyHandledEvent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * This file is part of CQRS-Tools package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
11
namespace Slick\CQRSTools\Application\Projection;
12
13
/**
14
 * ProgressStateProviderMethods
15
 *
16
 * @package Slick\CQRSTools\Application\Projection
17
 */
18
trait ProgressStateProviderMethods
19
{
20
    /** @var ProgressStateListener[]  */
21
    protected $listeners = [];
22
23
    /**
24
     * Registers a projectionist state listener
25
     *
26
     * @param $listener
27
     *
28
     * @return ProgressStateProvider|self|$this
29
     */
30
    public function register($listener): ProgressStateProvider
31
    {
32
        array_push($this->listeners, $listener);
33
        return $this;
34
    }
35
36
    /**
37
     * Notify listeners of progress max steps
38
     *
39
     * @param int $max
40
     */
41
    protected function notifyMaxSteps(int $max): void
42
    {
43
        foreach ($this->listeners as $listener) {
44
            $listener->setMaxSteps($max);
45
        }
46
    }
47
48
    /**
49
     * Notify listeners of progress advanced steps
50
     *
51
     * @param int $steps
52
     */
53
    protected function notifyAdvance(int $steps = 1): void
54
    {
55
        foreach ($this->listeners as $listener) {
56
            $listener->advance($steps);
57
        }
58
    }
59
60
    /**
61
     * Notify listeners of progress finish
62
     */
63
    protected function notifyFinish(): void
64
    {
65
        foreach ($this->listeners as $listener) {
66
            $listener->finish();
67
        }
68
    }
69
70
    /**
71
     * Notify listeners of handled vents
72
     *
73
     * @param int $processed
74
     */
75
    protected function notifyHandledEvent(int $processed = 1): void
76
    {
77
        foreach ($this->listeners as $listener) {
78
            $listener->addProcessedEvents($processed);
79
        }
80
    }
81
}
82