Issues (48)

src/Structure/Workflow.php (4 issues)

1
<?php
2
3
4
namespace Pheanstalk\Structure;
5
6
use Doctrine\Common\Collections\ArrayCollection;
7
8
class Workflow
9
{
10
    /** @var null|string */
11
    private $id;
12
13
    /** @var $name string */
0 ignored issues
show
Documentation Bug introduced by
The doc comment $name at position 0 could not be parsed: Unknown type name '$name' at position 0 in $name.
Loading history...
14
    private $name;
15
16
    /** @var string $group */
17
    private $group;
18
19
    /** @var ArrayCollection[Job] */
0 ignored issues
show
Documentation Bug introduced by
The doc comment ArrayCollection[Job] at position 1 could not be parsed: Expected ']' at position 1, but found '['.
Loading history...
20
    private $jobs;
21
22
    /** @var null|string $comment */
23
    private $comment;
24
25
    /** @var null|int $boundToSchedule */
26
    private $boundToSchedule;
27
28
    /** @var null|int $lastcommit */
29
    private $lastcommit;
30
31
    /** @var null|int $modified */
32
    private $modified;
33
34
    /**
35
     * Job constructor.
36
     *
37
     * @param string                $name       The name of the workflow
38
     * @param string                $group      The group of the workflow
39
     * @param ArrayCollection[Job]  $jobs       The collection of jobs
0 ignored issues
show
Documentation Bug introduced by
The doc comment ArrayCollection[Job] at position 1 could not be parsed: Expected ']' at position 1, but found '['.
Loading history...
40
     * @param null|string           $comment    The comment of the workflow
41
     */
42 22
    public function __construct(string $name, string $group, ArrayCollection $jobs, ?string $comment = null)
43
    {
44 22
        $this->name = $name;
45 22
        $this->group = $group;
46 22
        $this->setJobs($jobs);
47 22
        $this->comment = $comment;
48
    }
49
50
    /**
51
     * @return string|null
52
     */
53 13
    public function getId(): ?string
54
    {
55 13
        return $this->id;
56
    }
57
58
    /**
59
     * @param string|null $id
60
     *
61
     * @return Workflow
62
     */
63 14
    public function setId(?string $id): Workflow
64
    {
65 14
        $this->id = $id;
66 14
        return $this;
67
    }
68
69
    /**
70
     * @return string
71
     */
72 14
    public function getName(): string
73
    {
74 14
        return $this->name;
75
    }
76
77
    /**
78
     * @param string $name
79
     *
80
     * @return Workflow
81
     */
82 1
    public function setName(string $name): Workflow
83
    {
84 1
        $this->name = $name;
85 1
        return $this;
86
    }
87
88
    /**
89
     * @return string
90
     */
91 8
    public function getGroup(): string
92
    {
93 8
        return $this->group;
94
    }
95
96
    /**
97
     * @param string $group
98
     *
99
     * @return Workflow
100
     */
101 1
    public function setGroup(string $group): Workflow
102
    {
103 1
        $this->group = $group;
104 1
        return $this;
105
    }
106
107
    /**
108
     * @return string|null
109
     */
110 8
    public function getComment(): ?string
111
    {
112 8
        return $this->comment;
113
    }
114
115
    /**
116
     * @param string|null $comment
117
     *
118
     * @return Workflow
119
     */
120 2
    public function setComment(?string $comment): Workflow
121
    {
122 2
        $this->comment = $comment;
123 2
        return $this;
124
    }
125
126
    /**
127
     * @return ArrayCollection
128
     */
129 9
    public function getJobs(): ArrayCollection
130
    {
131 9
        return $this->jobs;
132
    }
133
134
    /**
135
     * @param ArrayCollection $jobs
136
     *
137
     * @return Workflow
138
     */
139 22
    public function setJobs(ArrayCollection $jobs): Workflow
140
    {
141
        $this->jobs = $jobs->filter(function (Job $job) {
0 ignored issues
show
The parameter $job is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

141
        $this->jobs = $jobs->filter(function (/** @scrutinizer ignore-unused */ Job $job) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
142 14
            return true;
143 22
        });
144 22
        return $this;
145
    }
146
147
    /**
148
     * @param Job $job
149
     *
150
     * @return Workflow
151
     */
152 2
    public function addJob(Job $job): Workflow
153
    {
154 2
        $this->jobs[] = $job;
155 2
        return $this;
156
    }
157
158
    /**
159
     * @param Job $job
160
     *
161
     * @return Workflow
162
     */
163 1
    public function removeJob(Job $job): Workflow
164
    {
165 1
        $this->jobs->removeElement($job);
166 1
        return $this;
167
    }
168
169
    /**
170
     * @return int|null
171
     */
172 1
    public function getBoundToSchedule(): ?int
173
    {
174 1
        return $this->boundToSchedule;
175
    }
176
177
    /**
178
     * @param int|null $boundToSchedule
179
     *
180
     * @return Workflow
181
     */
182 11
    public function setBoundToSchedule(?int $boundToSchedule): Workflow
183
    {
184 11
        $this->boundToSchedule = $boundToSchedule;
185 11
        return $this;
186
    }
187
188
    /**
189
     * @return int|null
190
     */
191 1
    public function getLastcommit(): ?int
192
    {
193 1
        return $this->lastcommit;
194
    }
195
196
    /**
197
     * @param int|null $lastcommit
198
     *
199
     * @return Workflow
200
     */
201 11
    public function setLastcommit(?int $lastcommit): Workflow
202
    {
203 11
        $this->lastcommit = $lastcommit;
204 11
        return $this;
205
    }
206
207
    /**
208
     * @return int|null
209
     */
210 1
    public function getModified(): ?int
211
    {
212 1
        return $this->modified;
213
    }
214
215
    /**
216
     * @param int|null $modified
217
     *
218
     * @return Workflow
219
     */
220 11
    public function setModified(?int $modified): Workflow
221
    {
222 11
        $this->modified = $modified;
223 11
        return $this;
224
    }
225
226
    /**
227
     * @return \DOMDocument
228
     * @throws \ReflectionException
229
     */
230 8
    public function getXml()
231
    {
232 8
        $dom = new \DOMDocument("1.0", "utf-8");
233 8
        $root = $dom->createElement("workflow");
234 8
        $subjobs = $dom->createElement("subjobs");
235
        /** @var Job $job*/
236 8
        foreach ($this->getJobs() as $job) {
237 8
            $jobNode = $job->getXml()->getElementsByTagName('job')->item(0);
238 8
            $subjobs->appendChild($dom->importNode($jobNode, true));
239
        }
240 8
        $root->appendChild($subjobs);
241 8
        $dom->appendChild($root);
242 8
        return $dom;
243
    }
244
}
245