Skip to content

Commit d3aed49

Browse files
committed
add component
1 parent 5c3ff5d commit d3aed49

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

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: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,30 @@ public function setParent(Issue $parent)
232232
$this->parent = $parent;
233233
}
234234

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

@@ -274,7 +298,7 @@ public function setParent(Issue $parent)
274298
/** @var string|null */
275299
public $environment;
276300

277-
/** @var array */
301+
/** @var \JiraRestApi\Issue\Component[] */
278302
public $components;
279303

280304
/** @var Comments */

tests/IssueTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function testCreateIssue()
3838
->setDescription('Full description for issue')
3939
->addVersion('1.0.1')
4040
->addVersion('1.0.3')
41+
->addComponents(['Component-1', 'Component-2'])
4142
;
4243

4344
$issueService = new IssueService();

0 commit comments

Comments
 (0)