Completed
Pull Request — development (#546)
by Nick
06:21
created

AbstractEntity::fromArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Oc\Repository;
4
5
/**
6
 * Class AbstractEntity
7
 *
8
 * @package Oc\Repository
9
 */
10
abstract class AbstractEntity
11
{
12
    /**
13
     * Checks if the entity is new.
14
     *
15
     * @return bool
16
     */
17
    abstract public function isNew();
18
19
    /**
20
     * Sets all properties from array.
21
     *
22
     * @param array $data
23
     *
24
     * @return void
25
     */
26 View Code Duplication
    public function fromArray(array $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        foreach ($data as $key => $value) {
29
            if (!property_exists($this, $key)) {
30
                continue;
31
            }
32
33
            $this->{$key} = $value;
34
        }
35
    }
36
37
    /**
38
     * Returns all properties as array.
39
     *
40
     * @return array
41
     */
42
    public function toArray()
43
    {
44
        return get_object_vars($this);
45
    }
46
}
47