CreatedAt   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 32
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCreatedAt() 13 13 6
A setCreatedAtBeforePersist() 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 ETNA\Doctrine\Extensions;
4
5
use Doctrine\ORM\Mapping\Column;
6
use Doctrine\ORM\Mapping\PrePersist;
7
8 View Code Duplication
trait CreatedAt
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...
9
{
10
    /**
11
     * @Column(type="datetime", name="created_at")
12
     */
13
    private $created_at;
14
15
    /**
16
     * Getter
17
     */
18
    public function getCreatedAt($format = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
19
    {
20
        switch (true) {
21
            case is_string($this->created_at):
22
            case is_object($this->created_at) && get_class($this->created_at) !== 'DateTime':
23
                throw new \Exception("created_at is not a datetime", 400);
24
            case $this->created_at === null:
25
            case $format === null:
26
                return $this->created_at;
27
            default:
28
                return $this->created_at->format($format);
29
        }
30
    }
31
32
    /**
33
     * @PrePersist
34
     */
35
    public function setCreatedAtBeforePersist()
36
    {
37
        $this->created_at = new \DateTime(date('Y-m-d H:i:s'));
38
    }
39
}
40