| @@ 8-40 (lines=33) @@ | ||
| 5 | use TestMonitor\DevOps\Validator; |
|
| 6 | use TestMonitor\DevOps\Resources\Account; |
|
| 7 | ||
| 8 | trait TransformsAccounts |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * @param array $accounts |
|
| 12 | * |
|
| 13 | * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException |
|
| 14 | * @return \TestMonitor\DevOps\Resources\Account[] |
|
| 15 | */ |
|
| 16 | protected function fromDevOpsAccounts($accounts): array |
|
| 17 | { |
|
| 18 | Validator::isArray($accounts); |
|
| 19 | ||
| 20 | return array_map(function ($account) { |
|
| 21 | return $this->fromDevOpsAccount($account); |
|
| 22 | }, $accounts); |
|
| 23 | } |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @param array $account |
|
| 27 | * |
|
| 28 | * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException |
|
| 29 | * @return \TestMonitor\DevOps\Resources\Account |
|
| 30 | */ |
|
| 31 | protected function fromDevOpsAccount($account): Account |
|
| 32 | { |
|
| 33 | Validator::keysExists($account, ['AccountId', 'AccountName']); |
|
| 34 | ||
| 35 | return new Account([ |
|
| 36 | 'id' => $account['AccountId'], |
|
| 37 | 'name' => $account['AccountName'], |
|
| 38 | ]); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 8-40 (lines=33) @@ | ||
| 5 | use TestMonitor\DevOps\Validator; |
|
| 6 | use TestMonitor\DevOps\Resources\Project; |
|
| 7 | ||
| 8 | trait TransformsProjects |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * @param array $projects |
|
| 12 | * |
|
| 13 | * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException |
|
| 14 | * @return \TestMonitor\DevOps\Resources\Project[] |
|
| 15 | */ |
|
| 16 | protected function fromDevOpsProjects($projects): array |
|
| 17 | { |
|
| 18 | Validator::isArray($projects); |
|
| 19 | ||
| 20 | return array_map(function ($project) { |
|
| 21 | return $this->fromDevOpsProject($project); |
|
| 22 | }, $projects); |
|
| 23 | } |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @param array $project |
|
| 27 | * |
|
| 28 | * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException |
|
| 29 | * @return \TestMonitor\DevOps\Resources\Project |
|
| 30 | */ |
|
| 31 | protected function fromDevOpsProject($project): Project |
|
| 32 | { |
|
| 33 | Validator::keysExists($project, ['id', 'name']); |
|
| 34 | ||
| 35 | return new Project([ |
|
| 36 | 'id' => $project['id'], |
|
| 37 | 'name' => $project['name'], |
|
| 38 | ]); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 8-40 (lines=33) @@ | ||
| 5 | use TestMonitor\DevOps\Validator; |
|
| 6 | use TestMonitor\DevOps\Resources\WorkItemType; |
|
| 7 | ||
| 8 | trait TransformsWorkItemTypes |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * @param array $workItemType |
|
| 12 | * |
|
| 13 | * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException |
|
| 14 | * @return \TestMonitor\DevOps\Resources\WorkItemType |
|
| 15 | */ |
|
| 16 | protected function fromDevOpsWorkItemType(array $workItemType): WorkItemType |
|
| 17 | { |
|
| 18 | Validator::keysExists($workItemType, ['name', 'description']); |
|
| 19 | ||
| 20 | return new WorkItemType([ |
|
| 21 | 'name' => $workItemType['name'], |
|
| 22 | 'description' => $workItemType['description'], |
|
| 23 | ]); |
|
| 24 | } |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @param $workItemTypes |
|
| 28 | * |
|
| 29 | * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException |
|
| 30 | * @return array |
|
| 31 | */ |
|
| 32 | protected function fromDevOpsWorkItemTypes($workItemTypes): array |
|
| 33 | { |
|
| 34 | Validator::isArray($workItemTypes); |
|
| 35 | ||
| 36 | return array_map(function ($workItemType) { |
|
| 37 | return $this->fromDevOpsWorkItemType($workItemType); |
|
| 38 | }, $workItemTypes); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||