Code Duplication    Length = 121-121 lines in 2 locations

src/Model/Abstracts/Base2Abstract.php 1 location

@@ 21-141 (lines=121) @@
18
 *
19
 * @author Beñat Espiña <[email protected]>
20
 */
21
abstract class Base2Abstract
22
{
23
    /**
24
     * Creation date.
25
     *
26
     * @var \DateTime
27
     */
28
    protected $creationDate;
29
30
    /**
31
     * Array that contains tags.
32
     *
33
     * @var string[]
34
     */
35
    protected $tags;
36
37
    /**
38
     * The title.
39
     *
40
     * @var string|null
41
     */
42
    protected $title;
43
44
    /**
45
     * Constructor.
46
     *
47
     * @param null|mixed[] $json The json string being decoded
48
     */
49
    public function __construct($json = null)
50
    {
51
        $this->creationDate = Util::setIfDateTimeExists($json, 'creation_date');
52
        $this->tags = Util::setIfArrayExists($json, 'tags');
53
        $this->title = Util::setIfStringExists($json, 'title');
54
    }
55
56
    /**
57
     * Sets creation date.
58
     *
59
     * @param \DateTime $creationDate The creation date
60
     *
61
     * @return $this self Object
62
     */
63
    public function setCreationDate(\DateTime $creationDate)
64
    {
65
        $this->creationDate = $creationDate;
66
67
        return $this;
68
    }
69
70
    /**
71
     * Gets creation date.
72
     *
73
     * @return \DateTime
74
     */
75
    public function getCreationDate()
76
    {
77
        return $this->creationDate;
78
    }
79
80
    /**
81
     * Adds tag.
82
     *
83
     * @param string|null $tag The tag
84
     *
85
     * @return $this self Object
86
     */
87
    public function addTag($tag)
88
    {
89
        $this->tags[] = $tag;
90
91
        return $this;
92
    }
93
94
    /**
95
     * Removes tag.
96
     *
97
     * @param string|null $tag The tag
98
     *
99
     * @return $this self Object
100
     */
101
    public function removeTag($tag)
102
    {
103
        $this->tags = Util::removeElement($tag, $this->tags);
104
105
        return $this;
106
    }
107
108
    /**
109
     * Gets array of tags.
110
     *
111
     * @return string[]
112
     */
113
    public function getTags()
114
    {
115
        return $this->tags;
116
    }
117
118
    /**
119
     * Sets title.
120
     *
121
     * @param string|null $title The title
122
     *
123
     * @return $this self Object
124
     */
125
    public function setTitle($title)
126
    {
127
        $this->title = $title;
128
129
        return $this;
130
    }
131
132
    /**
133
     * Gets title.
134
     *
135
     * @return string|null
136
     */
137
    public function getTitle()
138
    {
139
        return $this->title;
140
    }
141
}
142

src/Model/Traits/LastTrait.php 1 location

@@ 21-141 (lines=121) @@
18
 *
19
 * @author Beñat Espiña <[email protected]>
20
 */
21
trait LastTrait
22
{
23
    /**
24
     * The last body.
25
     *
26
     * @var string|null
27
     */
28
    protected $lastBody;
29
30
    /**
31
     * Array that contains the last tags.
32
     *
33
     * @var string[]
34
     */
35
    protected $lastTags = [];
36
37
    /**
38
     * The last title.
39
     *
40
     * @var string|null
41
     */
42
    protected $lastTitle;
43
44
    /**
45
     * Sets last body.
46
     *
47
     * @param string|null $lastBody The last body
48
     *
49
     * @return $this self Object
50
     */
51
    public function setLastBody($lastBody)
52
    {
53
        $this->lastBody = $lastBody;
54
55
        return $this;
56
    }
57
58
    /**
59
     * Gets last body.
60
     *
61
     * @return string|null
62
     */
63
    public function getLastBody()
64
    {
65
        return $this->lastBody;
66
    }
67
68
    /**
69
     * Adds last tag.
70
     *
71
     * @param string|null $lastTag The last tag
72
     *
73
     * @return $this self Object
74
     */
75
    public function addLastTag($lastTag)
76
    {
77
        $this->lastTags[] = $lastTag;
78
79
        return $this;
80
    }
81
82
    /**
83
     * Removes last tag.
84
     *
85
     * @param string|null $lastTag The last tag
86
     *
87
     * @return $this self Object
88
     */
89
    public function removeLastTag($lastTag)
90
    {
91
        $this->lastTags = Util::removeElement($lastTag, $this->lastTags);
92
93
        return $this;
94
    }
95
96
    /**
97
     * Gets array of last tags.
98
     *
99
     * @return string[]
100
     */
101
    public function getLastTags()
102
    {
103
        return $this->lastTags;
104
    }
105
106
    /**
107
     * Sets last title.
108
     *
109
     * @param string|null $lastTitle The last title
110
     *
111
     * @return $this self Object
112
     */
113
    public function setLastTitle($lastTitle)
114
    {
115
        $this->lastTitle = $lastTitle;
116
117
        return $this;
118
    }
119
120
    /**
121
     * Gets last title.
122
     *
123
     * @return string|null
124
     */
125
    public function getLastTitle()
126
    {
127
        return $this->lastTitle;
128
    }
129
130
    /**
131
     * Loads the variables if the data exist into resource. It works like a constructor.
132
     *
133
     * @param null|mixed[] $resource The resource
134
     */
135
    protected function loadLast($resource)
136
    {
137
        $this->lastBody = Util::setIfStringExists($resource, 'last_body');
138
        $this->lastTags = Util::setIfArrayExists($resource, 'last_tags');
139
        $this->lastTitle = Util::setIfStringExists($resource, 'last_title');
140
    }
141
}
142