testmonitor /
devops-client
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace TestMonitor\DevOps\Actions; |
||||||
| 4 | |||||||
| 5 | use TestMonitor\DevOps\Resources\Attachment; |
||||||
| 6 | use TestMonitor\DevOps\Transforms\TransformsAttachments; |
||||||
| 7 | |||||||
| 8 | trait ManagesAttachments |
||||||
| 9 | { |
||||||
| 10 | use TransformsAttachments; |
||||||
| 11 | |||||||
| 12 | /** |
||||||
| 13 | * Add a new attachment. |
||||||
| 14 | * |
||||||
| 15 | * @param string $path |
||||||
| 16 | * @param string $workItemId |
||||||
| 17 | * @param string $projectId |
||||||
| 18 | * |
||||||
| 19 | * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException |
||||||
| 20 | * |
||||||
| 21 | * @return \TestMonitor\DevOps\Resources\Attachment |
||||||
| 22 | */ |
||||||
| 23 | 5 | public function addAttachment(string $path, string $workItemId, string $projectId): Attachment |
|||||
| 24 | { |
||||||
| 25 | // First, upload the file |
||||||
| 26 | 5 | $response = $this->post( |
|||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 27 | 5 | "{$projectId}/_apis/wit/attachments", |
|||||
| 28 | 5 | [ |
|||||
| 29 | 5 | 'headers' => ['Content-Type' => 'application/octet-stream'], |
|||||
| 30 | 5 | 'query' => ['fileName' => basename($path), 'api-version' => $this->apiVersion], |
|||||
| 31 | 5 | 'body' => fopen($path, 'r'), |
|||||
| 32 | 5 | ] |
|||||
| 33 | 5 | ); |
|||||
| 34 | |||||||
| 35 | // Second, attach it to the work item |
||||||
| 36 | 1 | $this->patch( |
|||||
|
0 ignored issues
–
show
It seems like
patch() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 37 | 1 | "{$projectId}/_apis/wit/workitems/{$workItemId}", |
|||||
| 38 | 1 | [ |
|||||
| 39 | 1 | 'headers' => ['Content-Type' => 'application/json-patch+json'], |
|||||
| 40 | 1 | 'json' => $this->toDevOpsAttachment($response['url']), |
|||||
| 41 | 1 | ] |
|||||
| 42 | 1 | ); |
|||||
| 43 | |||||||
| 44 | 1 | return $this->fromDevOpsAttachment($response); |
|||||
| 45 | } |
||||||
| 46 | } |
||||||
| 47 |