ServerApi::isHeadersSent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Simply\Application;
4
5
/**
6
 * The default system api used to interact with the browser.
7
 * @author Riikka Kalliomäki <[email protected]>
8
 * @copyright Copyright (c) 2018 Riikka Kalliomäki
9
 * @license http://opensource.org/licenses/mit-license.php MIT License
10
 */
11
class ServerApi
12
{
13
    /**
14
     * Tells if the headers have been sent and no more headers can be provided.
15
     * @return bool True if no more headers can be provided, false otherwise
16
     */
17 1
    public function isHeadersSent(): bool
18
    {
19 1
        return headers_sent();
20
    }
21
22
    /**
23
     * Adds a header line to be sent to the browser.
24
     * @param string $line The header line to send to browser
25
     * @codeCoverageIgnore
26
     */
27
    public function sendHeaderLine(string $line): void
28
    {
29
        header($line, false);
30
    }
31
32
    /**
33
     * Outputs the given string to the browser.
34
     * @param string $output The string to output
35
     */
36 1
    public function output(string $output): void
37
    {
38 1
        echo $output;
39 1
    }
40
41
    /**
42
     * Tells if the connection to the user have been terminated and no more output can be sent.
43
     * @return bool True if no more output can be sent, false otherwise
44
     */
45 1
    public function isConnectionAborted(): bool
46
    {
47 1
        return connection_status() !== \CONNECTION_NORMAL;
48
    }
49
}
50