Notice   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 68
Duplicated Lines 19.12 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 13
loc 68
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A fromJson() 13 13 4
A fromProperties() 0 11 1
A setBody() 0 6 1
A getBody() 0 4 1
A setCreationDate() 0 6 1
A getCreationDate() 0 4 1
A setOwnerUserId() 0 6 1
A getOwnerUserId() 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
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
/*
14
 * This file is part of the Stack Exchange Api Client library.
15
 *
16
 * (c) Beñat Espiña <[email protected]>
17
 *
18
 * For the full copyright and license information, please view the LICENSE
19
 * file that was distributed with this source code.
20
 */
21
22
namespace BenatEspina\StackExchangeApiClient\Model;
23
24
/**
25
 * The notice model class.
26
 *
27
 * @author Beñat Espiña <[email protected]>
28
 */
29
class Notice implements Model
30
{
31
    protected $body;
32
    protected $creationDate;
33
    protected $ownerUserId;
34
35 View Code Duplication
    public static function fromJson(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...
36
    {
37
        $instance = new self();
38
        $instance
39
            ->setBody(array_key_exists('body', $data) ? $data['body'] : null)
40
            ->setCreationDate(array_key_exists('creation_date', $data)
41
                ? new \DateTimeImmutable('@' . $data['creation_date'])
42
                : null
43
            )
44
            ->setOwnerUserId(array_key_exists('owner_user_id', $data) ? $data['owner_user_id'] : null);
45
46
        return $instance;
47
    }
48
49
    public static function fromProperties($body, \DateTimeInterface $creationDate, $ownerUserId)
50
    {
51
        $instance = new self();
52
53
        $instance
54
            ->setBody($body)
55
            ->setCreationDate($creationDate)
56
            ->setOwnerUserId($ownerUserId);
57
58
        return $instance;
59
    }
60
61
    public function setBody($body)
62
    {
63
        $this->body = $body;
64
65
        return $this;
66
    }
67
68
    public function getBody()
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...
69
    {
70
        return $this->body;
71
    }
72
73
    public function setCreationDate(\DateTimeInterface $creationDate = null)
74
    {
75
        $this->creationDate = $creationDate;
76
77
        return $this;
78
    }
79
80
    public function getCreationDate()
81
    {
82
        return $this->creationDate;
83
    }
84
85
    public function setOwnerUserId($ownerUserId)
86
    {
87
        $this->ownerUserId = $ownerUserId;
88
89
        return $this;
90
    }
91
92
    public function getOwnerUserId()
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...
93
    {
94
        return $this->ownerUserId;
95
    }
96
}
97