Test Failed
Branch lab/data (a414ec)
by Gabor
07:41
created

AbstractEntity::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2018 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Data\Entity;
15
16
use InvalidArgumentException;
17
18
/**
19
 * Class AbstractEntity
20
 */
21
abstract class AbstractEntity implements EntityInterface
22
{
23
    /**
24
     * @var array
25
     */
26
    protected $container = [];
27
28
    /**
29
     * Returns entity data as an array.
30
     *
31
     * @return array
32
     */
33
    public function toArray(): array
34
    {
35
        return $this->container;
36
    }
37
38
    /**
39
     * Fills entity from an arrray.
40
     *
41
     * @param array $arrayData
42
     */
43
    public function fromArray(array $arrayData): void
44
    {
45
        foreach ($arrayData as $key => $value) {
46
            if (!array_key_exists($key, $this->container)) {
47
                throw new InvalidArgumentException(
48
                    sprintf('"%s" is not defined in ' . get_called_class(), $key),
49
                    1000
50
                );
51
            }
52
53
            $this->container[$key] = $value;
54
        }
55
    }
56
}
57