Completed
Push — next ( ba018c...5105e3 )
by Mathias
10:34
created

JobData   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 0
loc 113
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setJobId() 0 6 1
A getJobId() 0 4 1
A setExternalId() 0 6 1
A getExternalId() 0 4 1
A setExternalUrl() 0 6 1
A getExternalUrl() 0 4 1
A setIsOnline() 0 6 1
A isOnline() 0 4 1
A addResponse() 0 6 1
A getResponses() 0 8 2
A getLastResponse() 0 4 1
1
<?php
2
/**
3
 * YAWIK Stackoverflow API
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2016- 2017 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace StackoverflowApi\Entity;
12
13
use Core\Entity\Collection\ArrayCollection;
14
use Core\Entity\EntityTrait;
15
use Core\Entity\IdentifiableEntityTrait;
16
use Doctrine\Common\Collections\Collection;
17
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
18
19
/**
20
 * Stackoverflow specific data container to be attached to a job entity.
21
 *
22
 * @ODM\Document(collection="stackoverflowapi.jobdata", repositoryClass="\Core\Repository\DefaultRepository")
23
 *
24
 * @author Mathias Gelhausen <[email protected]>
25
 * @since 0.1.0
26
 */
27
class JobData implements JobDataInterface
28
{
29
    use EntityTrait, IdentifiableEntityTrait;
30
31
    /**
32
     * The id of the associated job
33
     *
34
     * @ODM\Field(type="string")
35
     * @var string
36
     */
37
    private $jobId;
38
39
    /**
40
     * The external id (Stackoverflow API)
41
     *
42
     * @ODM\Field(type="int")
43
     * @var int
44
     */
45
    private $externalId;
46
47
    /**
48
     * The external url.
49
     *
50
     * @ODM\Field(type="string")
51
     * @var string
52
     */
53
    private $externalUrl;
54
55
    /**
56
     * Flag wether the associated job is online.
57
     *
58
     * @ODM\Field(type="boolean")
59
     * @var bool
60
     */
61
    private $isOnline = false;
62
63
    /**
64
     * Api response stack.
65
     *
66
     * @ODM\EmbedMany(targetDocument="StackoverflowApi\Entity\ApiResponse")
67
     * @var Collection
68
     */
69
    private $responses;
70
71
    public function setJobId($id)
72
    {
73
        $this->jobId = (string) $id;
74
75
        return $this;
76
    }
77
78
    public function getJobId()
79
    {
80
        return $this->jobId;
81
    }
82
83
    public function setExternalId($externalId)
84
    {
85
        $this->externalId = $externalId;
86
87
        return $this;
88
    }
89
90
    public function getExternalId()
91
    {
92
        return $this->externalId;
93
    }
94
95
    public function setExternalUrl($externalUrl)
96
    {
97
        $this->externalUrl = $externalUrl;
98
99
        return $this;
100
    }
101
102
    public function getExternalUrl()
103
    {
104
        return $this->externalUrl;
105
    }
106
107
    public function setIsOnline($flag)
108
    {
109
        $this->isOnline = (bool) $flag;
110
111
        return $this;
112
    }
113
114
    public function isOnline()
115
    {
116
        return $this->isOnline;
117
    }
118
119
    public function addResponse(ApiResponseInterface $response)
120
    {
121
        $this->getResponses()->add($response);
122
123
        return $this;
124
    }
125
126
    public function getResponses()
127
    {
128
        if (!$this->responses) {
129
            $this->responses = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Core\Entity\Collection\ArrayCollection() of type object<Core\Entity\Collection\ArrayCollection> is incompatible with the declared type object<Doctrine\Common\Collections\Collection> of property $responses.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
130
        }
131
132
        return $this->responses;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->responses; of type Core\Entity\Collection\A...\Collections\Collection adds the type Core\Entity\Collection\ArrayCollection to the return on line 132 which is incompatible with the return type declared by the interface StackoverflowApi\Entity\...Interface::getResponses of type Doctrine\Common\Collections\Collection.
Loading history...
133
    }
134
135
    public function getLastResponse()
136
    {
137
        return $this->getResponses()->last();
138
    }
139
}