HttpViolationHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 3
c 4
b 1
f 0
lcom 0
cbo 0
dl 0
loc 29
ccs 4
cts 4
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handleViolation() 0 5 1
A sendHeader() 0 5 1
A callExit() 0 4 1
1
<?php
2
namespace BehEh\Flaps\Violation;
3
4
use BehEh\Flaps\ViolationHandlerInterface;
5
6
/**
7
 * Handles violations by sending the corresponding HTTP header and exiting.
8
 *
9
 * @since 0.1
10
 * @author Benedict Etzel <[email protected]>
11
 */
12
class HttpViolationHandler implements ViolationHandlerInterface
13
{
14
15
    /**
16
     * Handles a violation by sending the corresponding HTTP header and exiting.
17
     */
18 1
    public function handleViolation()
19
    {
20 1
        $this->sendHeader();
21 1
        $this->callExit();
22 1
    }
23
24
    /**
25
     * @codeCoverageIgnore
26
     */
27
    protected function sendHeader()
28
    {
29
        header('HTTP/1.1 429 Too Many Requests');
30
        header('Content-Type: text/plain');
31
    }
32
33
    /**
34
     * @codeCoverageIgnore
35
     */
36
    protected function callExit()
37
    {
38
        die('Too many requests');
39
    }
40
}
41