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.
Test Failed
Push — master ( 6a62c8...4de011 )
by Thomas
02:54
created

Files::uploadFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
ccs 0
cts 0
cp 0
rs 9.4285
cc 2
eloc 9
nc 2
nop 5
crap 6
1
<?php
2
3
namespace B2\Files;
4
5
use B2\B2Client;
6
7
/**
8
 * Class Files
9
 * @package Mlh\B2\Files
10
 */
11
class Files
12
{
13
14
    /**
15
     * @var B2Client
16
     */
17
    protected $B2Client;
18
19
    /**
20
     * Files constructor.
21
     * @param B2Client $B2Client
22
     */
23 2
    public function __construct(B2Client $B2Client)
24
    {
25 2
        $this->B2Client = $B2Client;
26 2
    }
27
28
    /**
29
     * @param $bucketId
30
     * @param $startFileName
31
     * @return mixed
32
     * @throws \Exception
33
     */
34
    public function listFileNames($bucketId, $startFileName = null, $maxFileCount = 100)
35
    {
36
        return $this->B2Client->call('b2_list_file_names', 'POST', [
37
            'startFileName' => $startFileName,
38
            'bucketId'      => $bucketId,
39
            'maxFileCount'  => $maxFileCount
40
        ]);
41
    }
42
43
    /**
44
     * Lists all files in a bucket and starting filename. For very large buckets this may fail, use listFileNames() directly
45
     *
46
     * @param $bucketId
47
     * @param $startFileName
48
     * @return array
49
     */
50
    public function listAllFileNames($bucketId, $startFileName)
51
    {
52
53
        $allresults = [];
54
        $result     = $this->listFileNames($bucketId, $startFileName);
55
        $allresults = array_merge($allresults, $result['responseBody']['files']);
56
57
        if ($result['responseBody']['nextFileName'] !== null) {
58
            $allresults = array_merge($allresults,
59
                $this->listAllFileNames($bucketId, $result['responseBody']['nextFileName']));
60
        }
61
62
        return $allresults;
63
    }
64
65
    /**
66
     * @param $fileID
67
     * @return mixed
68
     * @throws \Exception
69
     */
70
    public function getFileInfo($fileId)
71
    {
72
        return $this->B2Client->call('b2_get_file_info', 'POST', ['fileId' => $fileId]);
73
    }
74
75
    /**
76
     * @param $bucketId
77
     * @return mixed
78
     * @throws \Exception
79
     */
80
    public function getUploadUrl($bucketId)
81
    {
82
        return $this->B2Client->call('b2_get_upload_url', 'POST', ['bucketId' => $bucketId]);
83
    }
84
85
    /**
86
     * @param $bucketId
87
     * @param string $filePath The path to the local file
88
     * @param string $fileName The name/path on B2
89
     * @param string $contentType
90
     * @param null $uploadUrl
0 ignored issues
show
Documentation introduced by
There is no parameter named $uploadUrl. Did you maybe mean $uploadUrlResponse?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
91
     * @return array
92
     */
93
    public function uploadFile($bucketId, $filePath, $fileName, $contentType, $uploadUrlResponse = [])
94
    {
95
96
        if (!$uploadUrlResponse) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $uploadUrlResponse of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
97
            $uploadUrlResponse = $this->getUploadUrl($bucketId);
98
        }
99
100
        $handle       = fopen($filePath, 'r');
101
        $fileData     = fread($handle, filesize($filePath));
102
        $fileDataSha1 = sha1_file($filePath);
103
104
        return $this->B2Client->uploadData($fileData, $fileDataSha1, $fileName, $contentType,
105
            $uploadUrlResponse['uploadUrl'],
106
            $uploadUrlResponse['authorizationToken']);
107
108
    }
109
110
    /**
111
     * @param $bucketId
112
     * @param $fileName
113
     * @return mixed
114
     * @throws \Exception
115
     */
116
    public function downloadFileByName($bucketName, $fileName)
117
    {
118
        return $this->B2Client->downloadFileByName($bucketName . '/' . $fileName);
119
    }
120
121
}
122