Completed
Push — master ( 59ea22...c6592e )
by Siim
14:08
created

BaseSaveDto::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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
use Sf4\Api\Notification\BaseNotification;
12
13
class BaseSaveDto extends AbstractResponseSaveDto
14
{
15
16
    public function __construct()
17
    {
18
        $this->setNotification(new BaseNotification());
19
    }
20
21
    /**
22
     * @param array|object|null $data
23
     */
24
    public function populate(array $data): void
25
    {
26
        if (isset($data[static::FIELD_STATUS])) {
27
            $this->setStatus($data[static::FIELD_STATUS]);
28
        }
29
        if (isset($data[static::FIELD_MESSAGE])) {
30
            $this->setMessage($data[static::FIELD_MESSAGE]);
31
        }
32
        if (isset($data[static::FIELD_NOTIFICATION])) {
33
            $this->setNotification($data[static::FIELD_NOTIFICATION]);
34
        }
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public function toArray(): array
41
    {
42
        return [
43
            static::FIELD_STATUS => $this->getStatus(),
44
            static::FIELD_MESSAGE => $this->getMessage(),
45
            static::FIELD_NOTIFICATION => $this->getNotification()->toArray()
46
        ];
47
    }
48
}
49