Passed
Push — master ( 75f6ef...2d6bc8 )
by Siim
10:44
created

BaseSaveDto::populate()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 8
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: siim
5
 * Date: 6.02.19
6
 * Time: 8:12
7
 */
8
9
namespace Sf4\Api\Dto\Response;
10
11
class BaseSaveDto extends AbstractResponseSaveDto
12
{
13
14
    /**
15
     * @param array|object|null $data
16
     */
17
    public function populate(array $data): void
18
    {
19
        if (isset($data[static::FIELD_STATUS])) {
20
            $this->setStatus($data[static::FIELD_STATUS]);
21
        }
22
        if (isset($data[static::FIELD_MESSAGE])) {
23
            $this->setMessage($data[static::FIELD_MESSAGE]);
24
        }
25
        if (isset($data[static::FIELD_NOTIFICATION])) {
26
            $this->setNotification($data[static::FIELD_NOTIFICATION]);
27
        }
28
    }
29
30
    /**
31
     * @return array
32
     */
33
    public function toArray(): array
34
    {
35
        return [
36
            static::FIELD_STATUS => $this->getStatus(),
37
            static::FIELD_MESSAGE => $this->getMessage(),
38
            static::FIELD_NOTIFICATION => $this->getNotification()->toArray()
39
        ];
40
    }
41
}
42