Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| IssueTransitionRequest | |
0.00% |
0 / 21 |
|
0.00% |
0 / 7 |
182 | |
0.00% |
0 / 1 |
| make | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| idOrKey | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| transitionId | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| comment | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getIdOrKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| validate | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
30 | |||
| toArray | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Javidnikoo\LaravelAtlassian\Jira\Features\Issue\Requests; |
| 4 | |
| 5 | use InvalidArgumentException; |
| 6 | |
| 7 | class IssueTransitionRequest |
| 8 | { |
| 9 | protected ?string $idOrKey = null; |
| 10 | |
| 11 | protected ?string $transitionId = null; |
| 12 | |
| 13 | protected ?string $comment = null; |
| 14 | |
| 15 | public static function make(): static |
| 16 | { |
| 17 | return new static; |
| 18 | } |
| 19 | |
| 20 | public function idOrKey(string $idOrKey): static |
| 21 | { |
| 22 | $this->idOrKey = $idOrKey; |
| 23 | |
| 24 | return $this; |
| 25 | } |
| 26 | |
| 27 | public function transitionId(string $id): static |
| 28 | { |
| 29 | $this->transitionId = $id; |
| 30 | |
| 31 | return $this; |
| 32 | } |
| 33 | |
| 34 | public function comment(string $comment): static |
| 35 | { |
| 36 | $this->comment = $comment; |
| 37 | |
| 38 | return $this; |
| 39 | } |
| 40 | |
| 41 | public function getIdOrKey(): string |
| 42 | { |
| 43 | return $this->idOrKey ?? throw new InvalidArgumentException('ID or key not set.'); |
| 44 | } |
| 45 | |
| 46 | protected function validate(): void |
| 47 | { |
| 48 | if ($this->idOrKey === null || trim($this->idOrKey) === '') { |
| 49 | throw new InvalidArgumentException('Issue ID or key is required for transition.'); |
| 50 | } |
| 51 | |
| 52 | if ($this->transitionId === null || trim($this->transitionId) === '') { |
| 53 | throw new InvalidArgumentException('Transition ID is required.'); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | public function toArray(): array |
| 58 | { |
| 59 | $this->validate(); |
| 60 | |
| 61 | $payload = [ |
| 62 | 'transition' => ['id' => $this->transitionId], |
| 63 | ]; |
| 64 | |
| 65 | if ($this->comment !== null && trim($this->comment) !== '') { |
| 66 | $payload['update'] = [ |
| 67 | 'comment' => [['add' => ['body' => $this->comment]]], |
| 68 | ]; |
| 69 | } |
| 70 | |
| 71 | return $payload; |
| 72 | } |
| 73 | } |