Skip to content

Commit cdb72e3

Browse files
committed
Merge branch 'feature/component' into develop
2 parents 5c3ff5d + 22d8abb commit cdb72e3

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ try {
304304
->setPriorityName("Critical")
305305
->setIssueType("Bug")
306306
->setDescription("Full description for issue")
307-
->addVersion("1.0.1")
308-
->addVersion("1.0.3");
307+
->addVersion(["1.0.1", "1.0.3"])
308+
->addComponents(['Component-1', 'Component-2']);
309309

310310
$issueService = new IssueService();
311311

src/Issue/Component.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php namespace JiraRestApi\Issue;
2+
3+
4+
class Component implements \JsonSerializable
5+
{
6+
public $id;
7+
public $name;
8+
9+
public function __construct($name)
10+
{
11+
$this->name = $name;
12+
}
13+
14+
public function jsonSerialize()
15+
{
16+
return array_filter(get_object_vars($this));
17+
}
18+
}

src/Issue/IssueField.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,13 @@ public function addVersion($name)
161161
$this->versions = array();
162162
}
163163

164-
$v = new Version();
165-
$v->name = $name;
166-
array_push($this->versions, $v);
164+
if (is_string($name)){
165+
array_push($this->versions, new Version($name));
166+
} else if (is_array($name)) {
167+
foreach($name as $v) {
168+
array_push($this->versions, new Version($v));
169+
}
170+
}
167171

168172
return $this;
169173
}
@@ -232,6 +236,30 @@ public function setParent(Issue $parent)
232236
$this->parent = $parent;
233237
}
234238

239+
/**
240+
* add issue component.
241+
*
242+
* @param string $component
243+
*
244+
* @return $this
245+
*/
246+
public function addComponents($component)
247+
{
248+
if (is_null($this->components)) {
249+
$this->components = array();
250+
}
251+
252+
if (is_string($component)){
253+
array_push($this->components, new Component($component));
254+
} else if (is_array($component)) {
255+
foreach($component as $c) {
256+
array_push($this->components, new Component($c));
257+
}
258+
}
259+
260+
return $this;
261+
}
262+
235263
/** @var string */
236264
public $summary;
237265

@@ -274,7 +302,7 @@ public function setParent(Issue $parent)
274302
/** @var string|null */
275303
public $environment;
276304

277-
/** @var array */
305+
/** @var \JiraRestApi\Issue\Component[] */
278306
public $components;
279307

280308
/** @var Comments */

src/Issue/Version.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class Version implements \JsonSerializable
2525
/* @var DateTime */
2626
public $releaseDate;
2727

28+
public function __construct($name)
29+
{
30+
$this->name = $name;
31+
}
32+
2833
public function jsonSerialize()
2934
{
3035
return array_filter(get_object_vars($this));

tests/IssueTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function testCreateIssue()
3636
->setPriorityName('Critical')
3737
->setIssueType('Bug')
3838
->setDescription('Full description for issue')
39-
->addVersion('1.0.1')
40-
->addVersion('1.0.3')
39+
->addVersion(['1.0.1', '1.0.3'])
40+
->addComponents(['Component-1', 'Component-2'])
4141
;
4242

4343
$issueService = new IssueService();

0 commit comments

Comments
 (0)