Completed
Push — master ( f806ab...8def13 )
by Anton
9s
created

ResponseTrait::render()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.25

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 4
eloc 9
nc 4
nop 1
dl 0
loc 13
ccs 6
cts 8
cp 0.75
crap 4.25
rs 9.2
c 1
b 1
f 1
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link https://github.com/bluzphp/framework
7
 */
8
9
/**
10
 * @namespace
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
     * @access public
24
     * @param  string $type
25
     * @return mixed
26
     */
27 2
    public function render($type = 'HTML')
28
    {
29
        // switch statement by response type
30 2
        switch (strtoupper($type)) {
31 2
            case 'CLI':
32 2
            case 'JSON':
33
                return $this->jsonSerialize();
0 ignored issues
show
Bug introduced by
It seems like jsonSerialize() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
34 2
            case 'HTML':
35 2
                return $this->__toString();
0 ignored issues
show
Bug introduced by
It seems like __toString() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
36
            default:
37
                return '';
38
        }
39
    }
40
}
41