Completed
Push — master ( d292ba...467d47 )
by Anton
15s
created

ResponseTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 6
cts 8
cp 0.75
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 13 4
jsonSerialize() 0 1 ?
__toString() 0 1 ?
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Response;
12
13
/**
14
 * Response Trait
15
 *
16
 * @package  Bluz\Response
17
 * @author   Anton Shevchuk
18
 */
19
trait ResponseTrait
20
{
21
    /**
22
     * @return string
23
     */
24
    abstract public function jsonSerialize();
25
26
    /**
27
     * @return string
28
     */
29
    abstract public function __toString();
30
31
    /**
32
     * Render object as HTML or JSON
33
     *
34
     * @param  string $type
35
     *
36
     * @return string
37
     */
38 3
    public function render($type = 'HTML')
39
    {
40
        // switch statement by response type
41 3
        switch (strtoupper($type)) {
42 3
            case 'CLI':
43 3
            case 'JSON':
44
                return $this->jsonSerialize();
45 3
            case 'HTML':
46 3
                return $this->__toString();
47
            default:
48
                return '';
49
        }
50
    }
51
}
52