GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

FilesClient::store()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2.003

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 20
ccs 10
cts 11
cp 0.9091
crap 2.003
rs 9.9332
1
<?php
2
3
namespace NStack\Clients;
4
5
use DateTime;
6
use NStack\Exceptions\FailedToParseException;
7
use NStack\Models\File;
8
9
/**
10
 * Class FilesClient
11
 *
12
 * @package NStack\Clients
13
 * @author  Tiago Araujo <[email protected]>
14
 */
15
class FilesClient extends NStackClient
16
{
17
    /** @var string */
18
    protected $path = 'content/files';
19
20
    /**
21
     * store
22
     *
23
     * @param String   $name
24
     * @param array    $tagsArray
25
     * @param DateTime $goneAt
26
     * @param String   $privacy
27
     * @param String   $imagePath
28
     * @return File
29
     * @throws FailedToParseException
30
     */
31 1
    public function store(
32
        String $name,
33
        String $privacy,
34
        String $imagePath,
35
        array $tagsArray = null,
36
        DateTime $goneAt = null
37
    ) {
38 1
        $response = $this->client->post($this->buildPath($this->path), [
39
            'form_params' => [
40 1
                'name'    => $name,
41 1
                'tags'    => is_null($tagsArray) ? null : implode(",", $tagsArray),
42 1
                'gone_at' => $goneAt,
43 1
                'privacy' => $privacy,
44 1
                'file'    => fopen($imagePath, 'r'),
45
            ],
46
        ]);
47 1
        $contents = $response->getBody()->getContents();
48 1
        $data = json_decode($contents, true);
49
50 1
        return new File($data['data']);
51
    }
52
53
    /**
54
     * storeWithPath
55
     *
56
     * @param String        $name
57
     * @param String        $privacy
58
     * @param String        $path
59
     * @param String        $mime
60
     * @param int           $size
61
     * @param array|null    $tagsArray
62
     * @param DateTime|null $goneAt
63
     * @return File
64
     * @throws FailedToParseException
65
     */
66 1
    public function storeWithPath(
67
        String $name,
68
        String $privacy,
69
        String $path,
70
        String $mime,
71
        int $size,
72
        array $tagsArray = null,
73
        DateTime $goneAt = null
74
    ) {
75 1
        $response = $this->client->post($this->buildPath($this->path . '/path'), [
76
            'form_params' => [
77 1
                'name'    => $name,
78 1
                'tags'    => is_null($tagsArray) ? null : implode(",", $tagsArray),
79 1
                'gone_at' => $goneAt,
80 1
                'privacy' => $privacy,
81 1
                'path'    => $path,
82 1
                'mime'    => $mime,
83 1
                'size'    => $size,
84
            ],
85
        ]);
86 1
        $contents = $response->getBody()->getContents();
87 1
        $data = json_decode($contents, true);
88
89 1
        return new File($data['data']);
90
    }
91
}