Completed
Push — master ( a95c92...e40b6a )
by Beñat
04:36
created

BountyTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 107
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
c 3
b 0
f 0
lcom 1
cbo 2
dl 107
loc 107
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setBodyAmount() 6 6 1
A getBodyAmount() 4 4 1
A setBountyClosesDate() 6 6 1
A getBountyClosesDate() 4 4 1
A setBountyUser() 6 6 1
A getBountyUser() 4 4 1
A loadBounty() 6 6 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
 * Copyright (c) 2015 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
namespace BenatEspina\StackExchangeApiClient\Model\Traits;
13
14
use BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface;
15
use BenatEspina\StackExchangeApiClient\Model\ShallowUser;
16
use BenatEspina\StackExchangeApiClient\Util\Util;
17
18
/**
19
 * Trait BountyTrait.
20
 *
21
 * @author Beñat Espiña <[email protected]>
22
 */
23 View Code Duplication
trait BountyTrait
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...
24
{
25
    /**
26
     * The bounty amount.
27
     *
28
     * @var int|null
29
     */
30
    protected $bodyAmount;
31
32
    /**
33
     * The bounty closes date.
34
     *
35
     * @var \DateTime|null
36
     */
37
    protected $bountyClosesDate;
38
39
    /**
40
     * Bounty user.
41
     *
42
     * @var \BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface|null
43
     */
44
    protected $bountyUser;
45
46
    /**
47
     * Sets body amount.
48
     *
49
     * @param int|null $bodyAmount The body amount
50
     *
51
     * @return $this self Object
52
     */
53
    public function setBodyAmount($bodyAmount)
54
    {
55
        $this->bodyAmount = $bodyAmount;
56
57
        return $this;
58
    }
59
60
    /**
61
     * Gets body amount.
62
     *
63
     * @return int|null
64
     */
65
    public function getBodyAmount()
66
    {
67
        return $this->bodyAmount;
68
    }
69
70
    /**
71
     * Sets bounty closes date.
72
     *
73
     * @param \DateTime|null $bountyClosesDate The bounty closes date
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $bountyClosesDate a bit more specific; maybe use \DateTime.
Loading history...
74
     *
75
     * @return $this self Object
76
     */
77
    public function setBountyClosesDate(\DateTime $bountyClosesDate)
78
    {
79
        $this->bountyClosesDate = $bountyClosesDate;
80
81
        return $this;
82
    }
83
84
    /**
85
     * Gets bounty closes date.
86
     *
87
     * @return \DateTime|null
88
     */
89
    public function getBountyClosesDate()
90
    {
91
        return $this->bountyClosesDate;
92
    }
93
94
    /**
95
     * Sets bounty user.
96
     *
97
     * @param \BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface|null $bountyUser The bounty user
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $bountyUser a bit more specific; maybe use ShallowUserInterface.
Loading history...
98
     *
99
     * @return $this self Object
100
     */
101
    public function setBountyUser(ShallowUserInterface $bountyUser)
102
    {
103
        $this->bountyUser = $bountyUser;
104
105
        return $this;
106
    }
107
108
    /**
109
     * Gets bounty user.
110
     *
111
     * @return \BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface|null
112
     */
113
    public function getBountyUser()
114
    {
115
        return $this->bountyUser;
116
    }
117
118
    /**
119
     * Loads the variables if the data exist into resource. It works like a constructor.
120
     *
121
     * @param null|mixed[] $resource The resource
122
     */
123
    protected function loadBounty($resource)
124
    {
125
        $this->bodyAmount = Util::setIfIntegerExists($resource, 'body_amount');
126
        $this->bountyClosesDate = Util::setIfDateTimeExists($resource, 'bounty_closes_date');
127
        $this->bountyUser = new ShallowUser(Util::setIfArrayExists($resource, 'bounty_user'));
128
    }
129
}
130