Passed
Push — develop ( 7b3a44...b44bab )
by Pablo
02:19
created

Text::render()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 3
nc 2
nop 1
1
<?php
2
3
namespace Nails\Api\Api\Output;
4
5
use Nails\Api\Interfaces\Output;
6
use Nails\Environment;
7
8
/**
9
 * Class Text
10
 *
11
 * @package Nails\Api\Output
12
 */
13
class Text implements Output
14
{
15
    /** @var string */
16
    const SLUG = 'TEXT';
17
18
    /** @var string */
19
    const CONTENT_TYPE = 'text/html';
20
21
    // --------------------------------------------------------------------------
22
23
    /**
24
     * Returns the slug which will trigger the output format
25
     *
26
     * @return string
27
     */
28
    public static function getSlug(): string
29
    {
30
        return static::SLUG;
31
    }
32
33
    // --------------------------------------------------------------------------
34
35
    /**
36
     * Returns the content type for the output format
37
     *
38
     * @return string
39
     */
40
    public static function getContentType(): string
41
    {
42
        return static::CONTENT_TYPE;
43
    }
44
45
    // --------------------------------------------------------------------------
46
47
    /**
48
     * Formats the return value from the resposne data
49
     *
50
     * @param array $aResponse The response data
51
     *
52
     * @return string
53
     */
54
    public static function render(array $aOut): string
55
    {
56
        if (Environment::not(Environment::ENV_PROD) && defined('JSON_PRETTY_PRINT')) {
57
            return json_encode($aOut, JSON_PRETTY_PRINT);
58
59
        } else {
60
            return json_encode($aOut);
61
        }
62
    }
63
}
64