HttpViolationHandler::callExit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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