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.
Passed
Push — master ( d0c397...a8a751 )
by Thomas
03:35
created

Files::listAllFileNames()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 14
ccs 0
cts 9
cp 0
rs 9.4285
c 1
b 1
f 0
cc 2
eloc 8
nc 2
nop 2
crap 6
1
<?php
2
namespace B2\Files;
3
4
use B2\B2Client;
5
6
/**
7
 * Class Files
8
 * @package Mlh\B2\Files
9
 */
10
class Files
11
{
12
13
    /**
14
     * @var B2Client
15
     */
16
    public $B2Client;
17
18
    /**
19
     * Files constructor.
20
     * @param B2Client $B2Client
21
     */
22 6
    public function __construct(B2Client $B2Client)
23
    {
24 6
        $this->B2Client = $B2Client;
25 6
    }
26
27
    /**
28
     * @param $bucketId
29
     * @param $startFileName
30
     * @return mixed
31
     * @throws \Exception
32
     */
33
    public function listFileNames($bucketId, $startFileName = null, $maxFileCount = 100)
34
    {
35
        return $this->B2Client->call('b2_list_file_names', 'POST', [
36
            'startFileName' => $startFileName,
37
            'bucketId'      => $bucketId,
38
            'maxFileCount'  => $maxFileCount
39
        ]);
40
    }
41
42
    /**
43
     * Lists all files in a bucket and starting filename. For very large buckets this may fail, use listFileNames() directly
44
     *
45
     * @param $bucketId
46
     * @param $startFileName
47
     * @return array
48
     */
49
    public function listAllFileNames($bucketId, $startFileName)
50
    {
51
52
        $allresults = [];
53
        $result     = $this->listFileNames($bucketId, $startFileName);
54
        $allresults = array_merge($allresults, $result['files']);
55
56
        if ($result['nextFileName'] !== null) {
57
            $allresults = array_merge($allresults,
58
                $this->listAllFileNames($bucketId, $result['nextFileName']));
59
        }
60
61
        return $allresults;
62
    }
63
64
    /**
65
     * @param $fileID
66
     * @return mixed
67
     * @throws \Exception
68
     */
69
    public function getFileInfo($fileId)
70
    {
71
        return $this->B2Client->call('b2_get_file_info', 'POST', ['fileId' => $fileId]);
72
    }
73
74
    /**
75
     * @param $bucketId
76
     * @return mixed
77
     * @throws \Exception
78
     */
79
    public function getUploadUrl($bucketId)
80
    {
81
        return $this->B2Client->call('b2_get_upload_url', 'POST', ['bucketId' => $bucketId]);
82
    }
83
84
    /**
85
     * @param $bucketId
86
     * @param string $filePath The path to the local file
87
     * @param string $fileName The name/path on B2
88
     * @param string $contentType
89
     * @param array $uploadUrlResponse
90
     * @return array
91
     */
92
    public function uploadFile($bucketId, $filePath, $fileName, $contentType, $uploadUrlResponse = [])
93
    {
94
95
        if (empty($uploadUrlResponse)) {
96
            $uploadUrlResponse = $this->getUploadUrl($bucketId);
97
        }
98
99
        $handle       = fopen($filePath, 'r');
100
        $fileData     = fread($handle, filesize($filePath));
101
        $fileDataSha1 = sha1_file($filePath);
102
103
        return $this->B2Client->uploadData($fileData, $fileDataSha1, $fileName, $contentType,
104
            $uploadUrlResponse['uploadUrl'],
105
            $uploadUrlResponse['authorizationToken']);
106
107
    }
108
109
    /**
110
     * @param $bucketId
111
     * @param $fileName
112
     * @return mixed
113
     * @throws \Exception
114
     */
115
    public function downloadFileByName($bucketName, $fileName)
116
    {
117
        return $this->B2Client->downloadFileByName($bucketName . '/' . $fileName);
118
    }
119
120
    /**
121
     * @param $bucketId
122
     * @param $fileName
123
     */
124
    public function hideFile($bucketId, $fileName) 
125
    {
126
        return $this->B2Client->call('b2_hide_file', 'POST', ['bucketId' => $bucketId, 'fileName' => $fileName]);
127
    }
128
129
    /**
130
     * @param $fileName
131
     * @param $fileId
132
     */
133
    public function deleteFileVersion($fileName, $fileId) {
134
        return $this->B2Client->call('b2_delete_file_version', 'POST', ['fileName' => $fileName, 'fileId' => $fileId]);
135
    }
136
}
137