Completed
Push — master ( f2c57a...b4ecb3 )
by Gabriel
02:40
created

Category::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Waredesk\Models\Product;
4
5
use JsonSerializable;
6
use Waredesk\Entity;
7
use Waredesk\ReplaceableEntity;
8
9
class Category implements Entity, ReplaceableEntity, JsonSerializable
10
{
11
    private $id;
12
    private $name;
13
14 5
    public function __construct(string $id)
15
    {
16 5
        $this->id = $id;
17 5
    }
18
19
    public function __clone()
20
    {
21
    }
22
23 4
    public function getId(): ? string
24
    {
25 4
        return $this->id;
26
    }
27
28
    public function getName(): ? string
29
    {
30
        return $this->name;
31
    }
32
33 5
    public function reset(array $data = null)
34
    {
35 5
        if ($data) {
36 5
            foreach ($data as $key => $value) {
37
                switch ($key) {
38 5
                    case 'id':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
39 5
                        $this->id = $value;
40 5
                        break;
41 5
                    case 'name':
42 5
                        $this->name = $value;
43 5
                        break;
44
                }
45
            }
46
        }
47 5
    }
48
49 4
    public function jsonSerialize(): string
50
    {
51 4
        return $this->getId();
52
    }
53
}
54