Passed
Pull Request — master (#32)
by Adam
02:00
created

TableRequest::updateRecords()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Beachcasts\Airtable\Request;
6
7
use Assert\Assert;
8
use GuzzleHttp\Psr7\Request;
9
10
class TableRequest extends Request
11
{
12 1
    public static function createRecords(string $tableName, array $records): Request
13
    {
14 1
        Assert::thatAll($records)
15 1
            ->keyExists('fields');
16
17 1
        return new self(
18 1
            'POST',
19
            $tableName,
20
            [
21 1
                'Content-Type' => 'application/json',
22
            ],
23 1
            json_encode(
24
                [
25 1
                    'records' => $records
26
                ]
27
            )
28
        );
29
    }
30
31 1
    public static function readRecords(string $tableName, string $id): Request
32
    {
33 1
        Assert::that($tableName)
34 1
            ->notEmpty();
35 1
        Assert::that($id)
36 1
            ->notEmpty();
37
38 1
        return new self(
39 1
            'GET',
40 1
            $tableName . '/' . $id
41
        );
42
    }
43
44 2
    public static function updateRecords(string $tableName, array $records, string $type): Request
45
    {
46 2
        Assert::thatAll($records)
47 2
            ->keyExists('fields');
48
49 2
        return new self(
50 2
            $type,
51
            $tableName,
52
            [
53 2
                'Content-Type' => 'application/json',
54
            ],
55 2
            json_encode(
56
                [
57 2
                    'records' => $records
58
                ]
59
            )
60
        );
61
    }
62
}
63