ResponseTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 29
ccs 6
cts 7
cp 0.8571
rs 10
wmc 4

1 Method

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