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

PageEntity   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 73
loc 73
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isNew() 4 4 1
A fromArray() 10 10 3
A toArray() 4 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\Page;
4
5
use DateTime;
6
7
/**
8
 * Class PageEntity
9
 *
10
 * @package Oc\Page
11
 */
12 View Code Duplication
class PageEntity
0 ignored issues
show
Duplication introduced by
This class 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...
13
{
14
    /**
15
     * @var int
16
     */
17
    public $id;
18
19
    /**
20
     * @var string
21
     */
22
    public $slug;
23
24
    /**
25
     * @var string
26
     */
27
    public $metaKeywords;
28
29
    /**
30
     * @var string
31
     */
32
    public $metaDescription;
33
34
    /**
35
     * @var string
36
     */
37
    public $metaSocial;
38
39
    /**
40
     * @var DateTime
41
     */
42
    public $updatedAt;
43
44
    /**
45
     * @var bool
46
     */
47
    public $active = true;
48
49
    /**
50
     * Checks if the entity is new.
51
     *
52
     * @return bool
53
     */
54
    public function isNew()
55
    {
56
        return $this->id === null;
57
    }
58
59
    /**
60
     * Sets all properties from array.
61
     *
62
     * @param array $data
63
     */
64
    public function fromArray(array $data)
65
    {
66
        foreach ($data as $key => $value) {
67
            if (!property_exists($this, $key)) {
68
                continue;
69
            }
70
71
            $this->{$key} = $value;
72
        }
73
    }
74
75
    /**
76
     * Returns all properties as array.
77
     *
78
     * @return array
79
     */
80
    public function toArray()
81
    {
82
        return get_object_vars($this);
83
    }
84
}
85