Completed
Pull Request — master (#3)
by
unknown
01:47
created

Circuit::resetFailure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the circuit-breaker package
5
 *
6
 * Copyright (c) 2016 Guillaume Cavana
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * Feel free to edit as you please, and have fun.
12
 *
13
 * @author Guillaume Cavana <[email protected]>
14
 */
15
16
namespace Eljam\CircuitBreaker;
17
18
/**
19
 * Class Circuit.
20
 */
21
class Circuit
22
{
23
    protected $name;
24
    protected $failures = 0;
25
    protected $lastFailure;
26
27
    /**
28
     * Constructor.
29
     *
30
     * @param string $name
31
     */
32
    public function __construct($name)
33
    {
34
        $this->name = $name;
35
    }
36
37
    /**
38
     * getName.
39
     *
40
     * @return string
41
     */
42
    public function getName()
43
    {
44
        return $this->name;
45
    }
46
47
    /**
48
     * getFailureCount.
49
     *
50
     * @return int
51
     */
52
    public function getFailures()
53
    {
54
        return (int) $this->failures;
55
    }
56
57
    /**
58
     * incrementFailure.
59
     */
60
    public function incrementFailure()
61
    {
62
        $this->failures += 1;
63
    }
64
65
    /**
66
     * resetFailure.
67
     */
68
    public function resetFailure()
69
    {
70
        $this->failures = 0;
71
    }
72
73
    /**
74
     * getLastFailure.
75
     *
76
     * @return int
77
     */
78
    public function getLastFailure()
79
    {
80
        return $this->lastFailure;
81
    }
82
83
    /**
84
     * setLastFailure.
85
     *
86
     * @param int $time
87
     */
88
    public function setLastFailure($time)
89
    {
90
        $this->lastFailure = $time;
91
    }
92
}
93