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.

Issues (187)

src/AirTable.php (64 issues)

1
<?php
2
0 ignored issues
show
Missing file doc comment
Loading history...
3
namespace BristolSU\AirTable;
4
5
use GuzzleHttp\Psr7\Response;
6
use Psr\Http\Message\ResponseInterface;
7
8
class AirTable
0 ignored issues
show
Missing doc comment for class AirTable
Loading history...
9
{
10
11
    /**
12
     * The ID of the Progress base to use
13
     * 
14
     * @var string 
15
     */
16
    private string $baseId;
0 ignored issues
show
Private member variable "baseId" must be prefixed with an underscore
Loading history...
17
18
    /**
19
     * The name of the table to use
20
     *
21
     * @var string
22
     */
23
    private string $tableName;
0 ignored issues
show
Private member variable "tableName" must be prefixed with an underscore
Loading history...
24
25
    /**
26
     * API key to use for authentication
27
     * 
28
     * @var string 
29
     */
30
    private string $apiKey;
0 ignored issues
show
Private member variable "apiKey" must be prefixed with an underscore
Loading history...
31
32
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
33
     * @var \GuzzleHttp\Client 
34
     */
35
    private \GuzzleHttp\Client $client;
0 ignored issues
show
Private member variable "client" must be prefixed with an underscore
Loading history...
36
37
    public static $rateLimitCooldown = 30;
38
    
39 10
    public function __construct(\GuzzleHttp\Client $client)
0 ignored issues
show
Missing doc comment for function __construct()
Loading history...
40
    {
41 10
        $this->client = $client;
42 10
    }
43
44
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
45
     * @return string
46
     */
47 1
    public function getBaseId(): string
48
    {
49 1
        return $this->baseId;
50
    }
51
52
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
53
     * @param string $baseId
0 ignored issues
show
Missing parameter comment
Loading history...
54
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
55 8
    public function setBaseId(string $baseId): void
56
    {
57 8
        $this->baseId = $baseId;
58 8
    }
59
60
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
61
     * @return string
62
     */
63 1
    public function getTableName(): string
64
    {
65 1
        return $this->tableName;
66
    }
67
68
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
69
     * @param string $tableName
0 ignored issues
show
Missing parameter comment
Loading history...
70
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
71 8
    public function setTableName(string $tableName): void
72
    {
73 8
        $this->tableName = $tableName;
74 8
    }
75
76
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
77
     * @return string
78
     */
79 1
    public function getApiKey(): string
80
    {
81 1
        return $this->apiKey;
82
    }
83
84
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
85
     * @param string $apiKey
0 ignored issues
show
Missing parameter comment
Loading history...
86
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
87 8
    public function setApiKey(string $apiKey): void
88
    {
89 8
        $this->apiKey = $apiKey;
90 8
    }
91
92
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
93
     * @param string $method
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 5 spaces after parameter type; 1 found
Loading history...
94
     * @param array|null $data
0 ignored issues
show
Missing parameter comment
Loading history...
95
     * 
96
     * @return ResponseInterface
97
     * 
98
     * @throws \GuzzleHttp\Exception\GuzzleException
99
     */
100 7
    protected function request(string $method = 'get', array $data = null): ResponseInterface
101
    {
102
        $options = [
103
            'headers' => [
104 7
                'Authorization' => 'Bearer ' . $this->apiKey
105
            ]
106
        ];
107 7
        if($data !== null) {
0 ignored issues
show
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
108 7
            if($method === 'get' || $method === 'delete') {
0 ignored issues
show
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
109 4
                $options['query'] = $data;
110
            } else {
111 3
                $options['json'] = $data;
112
            }
113
        }
114 7
        return $this->client->request($method,
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
115 7
            sprintf('https://api.airtable.com/v0/%s/%s', $this->baseId, $this->tableName),
116
            $options
117
        );
118
    }
119
    
120 7
    protected function execute($dataChunk, \Closure $execution)
0 ignored issues
show
Missing doc comment for function execute()
Loading history...
121
    {
122
        try {
123 7
            return $execution->call($this, $dataChunk);
124 1
        } catch (\GuzzleHttp\Exception\ClientException $exception) {
125 1
            if($exception->getCode() === 429) {
0 ignored issues
show
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
126 1
                sleep(static::$rateLimitCooldown);
127 1
                return $this->execute($dataChunk, $execution);
128
            } else {
129
                throw $exception;
130
            }
131
        }
132
    }
133
134 5
    protected function chunkAndThrottle(array $data, \Closure $execution, int $delay = 1, int $chunkSize = 10)
0 ignored issues
show
Missing doc comment for function chunkAndThrottle()
Loading history...
135
    {
136 5
        $chunkedData = array_chunk($data, $chunkSize, false);
137 5
        foreach($chunkedData as $key => $dataChunk) {
0 ignored issues
show
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
138 5
            $this->execute($dataChunk, $execution);
139 5
            if($key !== array_key_last($chunkedData)) {
0 ignored issues
show
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
140 3
                sleep($delay);
141
            }
142
        }
143 5
    }
144
145
    /**
146
     * Create Rows
147
     *
148
     * @param array $rows An array of arrays with the key as the field name and the value as the field value. E.g.
0 ignored issues
show
Expected 5 spaces after parameter name; 1 found
Loading history...
149
     * [
0 ignored issues
show
Parameter comment not aligned correctly; expected 20 spaces but found 1
Loading history...
150
     *      ['Field1' => 'Val1', 'Field2' => 'Val2'],
0 ignored issues
show
Parameter comment not aligned correctly; expected 20 spaces but found 6
Loading history...
151
     *      ['Field1' => 'Val3', 'Field2' => 'Val3']
0 ignored issues
show
Parameter comment not aligned correctly; expected 20 spaces but found 6
Loading history...
152
     * ]
0 ignored issues
show
Parameter comment not aligned correctly; expected 20 spaces but found 1
Loading history...
153
     * @param bool $typecast
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 2 spaces after parameter type; 1 found
Loading history...
154
     * 
155
     * @throws \GuzzleHttp\Exception\GuzzleException
156
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
157 3
    public function createRows(array $rows, bool $typecast = true)
158
    {
159 3
        $data = [];
160 3
        foreach($rows as $row) {
0 ignored issues
show
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
161 3
            $data[] = ['fields' => $row];
162
        }
163
        
164
        $this->chunkAndThrottle($data, function($rowsToCreate) use ($typecast) {
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
165 3
            $this->request('post', [
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
166 3
                'records' => $rowsToCreate, 'typecast' => $typecast
167
            ]);
0 ignored issues
show
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
168 3
        });
0 ignored issues
show
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
169 3
    }
170
171
    /**
172
     * Delete Rows
173
     *
174
     * @param array $rowIds An array of row IDs to delete. E.g. ['rec123', 'rec456']
175
     *
176
     * @throws \GuzzleHttp\Exception\GuzzleException
177
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
178 2
    public function deleteRows(array $rowIds)
179
    {
180
        $this->chunkAndThrottle($rowIds, function($rowIds) {
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
181 2
            $this->request('delete', [
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
182 2
                'records' => $rowIds
183
            ]);
0 ignored issues
show
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
184 2
        });
0 ignored issues
show
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
185 2
    }
186
187 3
    public function retrieveRecords()
0 ignored issues
show
Missing doc comment for function retrieveRecords()
Loading history...
188
    {
189 3
        $records = [];
190 3
        $offset = null;
191
        do {
0 ignored issues
show
Expected "do \n... while (...);\n"; found "do \n... while(...);\n"
Loading history...
192
            $response = $this->execute([], function($data) use ($offset) {
0 ignored issues
show
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

192
            $response = $this->execute([], function(/** @scrutinizer ignore-unused */ $data) use ($offset) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
193 3
                return $this->request('get', [
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
194 3
                    'offset' => $offset
195
                ]);
0 ignored issues
show
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
196 3
            });
0 ignored issues
show
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
197 3
            $responseData = json_decode($response->getBody()->getContents(), true);
198
            
199
            try {
200 3
                $newRecords = $responseData['records'];
201
            } catch (\Exception $e) {
202
                $newRecords = [];
203
            }
204
            
205 3
            $records = array_merge($records, $newRecords);
206 3
            if(array_key_exists('offset', $responseData)) {
0 ignored issues
show
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
207 3
                $offset = $responseData['offset'];
208
            } else {
209 3
                $offset = null;
210
            }
211 3
        } while($offset !== null);
212 3
        return $records;
213
    }
214
    
215 2
    public function getIdsFromTable(): array
0 ignored issues
show
Missing doc comment for function getIdsFromTable()
Loading history...
216
    {
217 2
         $ids = [];
218 2
        foreach($this->retrieveRecords() as $record) {
0 ignored issues
show
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
219 2
            $ids[] = $record['id'];
220
        }
221 2
        return $ids;
222
    }
223
224 1
    public function flushTable()
0 ignored issues
show
Missing doc comment for function flushTable()
Loading history...
225
    {
226 1
        $this->deleteRows(
227 1
            $this->getIdsFromTable()
228
        );
229 1
    }
230
    
231
}