Completed
Push — master ( 6f2bb4...6400d0 )
by Anton
11s
created

ResponseTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 3
cts 7
cp 0.4286
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
jsonSerialize() 0 1 ?
__toString() 0 1 ?
A render() 0 12 4
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') : string
39
    {
40
        // switch statement by response type
41 3
        switch (strtoupper($type)) {
42
            case 'CLI':
43
            case 'JSON':
44
                return $this->jsonSerialize();
45
            case 'HTML':
46
            default:
47 3
                return $this->__toString();
48
        }
49
    }
50
}
51