AbstractSendableWriter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 37
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
getHttpHeaders() 0 1 ?
A send() 0 19 4
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