Stat   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 63
loc 63
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A createFromArray() 4 4 1
A getStart() 4 4 1
A getEnd() 4 4 1
A getCount() 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
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace FAPI\Boilerplate\Model\Stat;
11
12
use FAPI\Boilerplate\Model\CreatableFromArray;
13
14
/**
15
 * @author Tobias Nyholm <[email protected]>
16
 */
17 View Code Duplication
final class Stat implements CreatableFromArray
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...
18
{
19
    /**
20
     * @var \DateTimeInterface
21
     */
22
    private $start;
23
24
    /**
25
     * @var \DateTimeInterface
26
     */
27
    private $end;
28
29
    /**
30
     * @var int
31
     */
32
    private $count;
33
34
    /**
35
     * @param \DateTimeInterface $start
36
     * @param \DateTimeInterface $end
37
     * @param int                $count
38
     */
39
    private function __construct(\DateTimeInterface $start, \DateTimeInterface $end, int $count)
40
    {
41
        $this->start = $start;
42
        $this->end = $end;
43
        $this->count = $count;
44
    }
45
46
    /**
47
     * @param array $data
48
     *
49
     * @return Stat
50
     */
51
    public static function createFromArray(array $data): Stat
52
    {
53
        return new self(new \DateTimeImmutable($data['start']), new \DateTimeImmutable($data['end']), $data['count']);
54
    }
55
56
    /**
57
     * @return \DateTimeInterface
58
     */
59
    public function getStart(): \DateTimeInterface
60
    {
61
        return $this->start;
62
    }
63
64
    /**
65
     * @return \DateTimeInterface
66
     */
67
    public function getEnd(): \DateTimeInterface
68
    {
69
        return $this->end;
70
    }
71
72
    /**
73
     * @return int
74
     */
75
    public function getCount(): int
76
    {
77
        return $this->count;
78
    }
79
}
80