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

AbstractEntity   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 11 3
A toArray() 0 3 1
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