BasicTypeResponse   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 36
ccs 0
cts 16
cp 0
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A setBody() 0 16 4
1
<?php
2
namespace Disque\Command\Response;
3
4
abstract class BasicTypeResponse extends BaseResponse implements ResponseInterface
5
{
6
    const TYPE_STRING = 0;
7
    const TYPE_INT = 1;
8
9
    /**
10
     * Basic data type for this response
11
     *
12
     * @var int
13
     */
14
    protected $type;
15
16
    /**
17
     * Set response body
18
     *
19
     * @param mixed $body Response body
20
     * @return void
21
     * @throws InvalidResponseException
22
     */
23
    public function setBody($body)
24
    {
25
        switch ($this->type) {
26
            case self::TYPE_INT:
27
                $error = !is_numeric($body);
28
                break;
29
            case self::TYPE_STRING:
30
            default:
31
                $error = !is_string($body);
32
                break;
33
        }
34
        if ($error) {
35
            throw new InvalidResponseException($this->command, $body);
36
        }
37
        parent::setBody($body);
38
    }
39
}