Passed
Pull Request — master (#211)
by Alexander
02:39
created

StateResetter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getResetters() 0 3 1
A __construct() 0 3 1
A reset() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Di;
6
7
/**
8
 * State resetter allows to reset state of the services that are currently stored in the container and have "reset"
9
 * callback defined. The reset should be triggered after each request-response cycle in case you build long-running
10
 * applications with tools like [Swoole](https://www.swoole.co.uk/) or [RoadRunner](https://roadrunner.dev/).
11
 */
12
class StateResetter
13
{
14
    private array $resetters;
15
16 3
    public function __construct(array $resetters)
17
    {
18 3
        $this->resetters = $resetters;
19 3
    }
20
21 3
    public function reset(): void
22
    {
23 3
        foreach ($this->resetters as $resetter) {
24 3
            $resetter();
25
        }
26 3
    }
27
28 1
    public function getResetters(): array
29
    {
30 1
        return $this->resetters;
31
    }
32
}
33