Passed
Push — master ( e14a05...ed0db1 )
by Gabor
05:13
created

AbstractEntity::fromArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 3
rs 9.4285
c 0
b 0
f 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 6
    public function toArray(): array
34
    {
35 6
        return $this->container;
36
    }
37
38
    /**
39
     * Fills entity from an arrray.
40
     *
41
     * @param array $arrayData
42
     */
43 23
    public function fromArray(array $arrayData): void
44
    {
45 23
        foreach ($arrayData as $key => $value) {
46 23
            if (!array_key_exists($key, $this->container)) {
47 1
                throw new InvalidArgumentException(
48 1
                    sprintf('"%s" is not defined in '.get_called_class(), $key),
49 1
                    1000
50
                );
51
            }
52
53 22
            $this->container[$key] = $value;
54
        }
55 22
    }
56
}
57