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

AbstractEntity   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 27.03 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 10
loc 37
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
isNew() 0 1 ?
A fromArray() 10 10 3
A toArray() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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