Skip to content

Commit

Permalink
fixed #180 - worklog visibility error.
Browse files Browse the repository at this point in the history
  • Loading branch information
KwangSeob Jeong committed Jul 28, 2018
1 parent a34372a commit 4a8cdc6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 44 deletions.
27 changes: 2 additions & 25 deletions src/Issue/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class Comment implements \JsonSerializable
{
use VisibilityTrait;

/** @var string */
public $self;

Expand Down Expand Up @@ -35,31 +37,6 @@ public function setBody($body)
return $this;
}

/**
* @param Visibility $type
* @param null $value
*
* @return $this
*/
public function setVisibility($type, $value = null)
{
if (is_null($this->visibility)) {
$this->visibility = new Visibility();
}

if (is_array($type)) {
$this->visibility->setType($type['type']);
$this->visibility->setValue($type['value']);
} elseif ($type instanceof Visibility) {
$this->visibility = $type;
} else {
$this->visibility->setType($type);
$this->visibility->setValue($value);
}

return $this;
}

public function jsonSerialize()
{
return array_filter(get_object_vars($this));
Expand Down
32 changes: 32 additions & 0 deletions src/Issue/VisibilityTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace JiraRestApi\Issue;

trait VisibilityTrait {

/**
*
* @param Visibility $type
* @param null $value
*
* @return $this
*/
public function setVisibility($type, $value = null)
{
if (is_null($this->visibility)) {
$this->visibility = new Visibility();
}

if (is_array($type)) {
$this->visibility->setType($type['type']);
$this->visibility->setValue($type['value']);
} elseif ($type instanceof Visibility) {
$this->visibility = $type;
} else {
$this->visibility->setType($type);
$this->visibility->setValue($value);
}

return $this;
}
}
21 changes: 2 additions & 19 deletions src/Issue/Worklog.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class Worklog
{
use ClassSerialize;
use VisibilityTrait;

/**
* @var int id of worklog
Expand Down Expand Up @@ -58,7 +59,7 @@ class Worklog
public $timeSpentSeconds;

/**
* @var array
* @var \JiraRestApi\Issue\Visibility
*/
public $visibility;

Expand Down Expand Up @@ -153,22 +154,4 @@ public function setTimeSpentSeconds($timeSpentSeconds)

return $this;
}

/**
* Function to set visibility of worklog.
*
* @param string $type value can be group or role
* @param string $value
*
* @return Worklog
*/
public function setVisibility($type, $value)
{
$this->visibility = [
'type' => $type,
'value' => $value,
];

return $this;
}
}

0 comments on commit 4a8cdc6

Please sign in to comment.