AbstractSendableWriter::send()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 12
cp 0
rs 9.6333
c 0
b 0
f 0
cc 4
nc 6
nop 2
crap 20
1
<?php
2
3
/*
4
 * soluble-flexstore library
5
 *
6
 * @author    Vanvelthem Sébastien
7
 * @link      https://github.com/belgattitude/soluble-flexstore
8
 * @copyright Copyright (c) 2016-2017 Vanvelthem Sébastien
9
 * @license   MIT License https://github.com/belgattitude/soluble-flexstore/blob/master/LICENSE.md
10
 *
11
 */
12
13
namespace Soluble\FlexStore\Writer;
14
15
use Soluble\FlexStore\Writer\Http\SimpleHeaders;
16
17
abstract class AbstractSendableWriter extends AbstractWriter implements HttpSendableInterface
18
{
19
    /**
20
     * Return (default) headers for sending store data via http.
21
     *
22
     * @return \Soluble\FlexStore\Writer\Http\SimpleHeaders
23
     */
24
    abstract public function getHttpHeaders();
25
26
    /**
27
     * Send the store data via http.
28
     *
29
     * @throws \Exception if error occurs in getData
30
     *
31
     * @param SimpleHeaders $headers
32
     * @param bool          $die_after
33
     */
34
    public function send(SimpleHeaders $headers = null, $die_after = true)
35
    {
36
        if ($headers === null) {
37
            $headers = $this->getHttpHeaders();
38
        }
39
40
        ob_end_clean();
41
42
        try {
43
            $data = $this->getData();
44
        } catch (\Exception $e) {
45
            throw $e;
46
        }
47
        $headers->outputHeaders($replace = true);
48
        echo $data;
49
        if ($die_after) {
50
            die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method send() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
51
        }
52
    }
53
}
54