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

BaseSaveDto   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A populate() 0 10 4
A toArray() 0 6 1
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