Completed
Push — master ( 2ac042...4e5e3b )
by Nate
02:40
created

HandlerStack   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A push() 0 4 1
A execute() 0 6 2
1
<?php
2
/*
3
 * Copyright (c) 2015 Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
namespace Tebru\Retrofit\Generation;
8
9
use Tebru\Retrofit\Generation\Handler;
10
11
/**
12
 * Class HandlerStack
13
 *
14
 * @author Nate Brunette <[email protected]>
15
 */
16
class HandlerStack
17
{
18
    /**
19
     * @var Handler[]
20
     */
21
    private $stack = [];
22
23
    /**
24
     * @var HandlerContext
25
     */
26
    private $context;
27
28
    /**
29
     * Constructor
30
     *
31
     * @param HandlerContext $context
32
     */
33
    public function __construct(HandlerContext $context)
34
    {
35
        $this->context = $context;
36
    }
37
38
    /**
39
     * Add a handler to the stack
40
     *
41
     * @param Handler $handler
42
     */
43
    public function push(Handler $handler)
44
    {
45
        $this->stack[] = $handler;
46
    }
47
48
    /**
49
     * Loop through all handlers, providing the context
50
     */
51
    public function execute()
52
    {
53
        foreach ($this->stack as $handler) {
54
            $handler($this->context);
55
        }
56
    }
57
}
58