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

TableRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 26
c 0
b 0
f 0
dl 0
loc 50
ccs 26
cts 26
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createRecords() 0 14 1
A readRecords() 0 10 1
A updateRecords() 0 16 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 3
    public static function updateRecords(string $tableName, array $records, string $type): Request
45
    {
46 3
        Assert::thatAll($records)
47 3
            ->keyExists('fields');
48 3
        Assert::that(strtoupper($type))
49 3
            ->inArray(['PUT', 'PATCH']);
50
51 2
        return new self(
52 2
            strtoupper($type),
53
            $tableName,
54
            [
55 2
                'Content-Type' => 'application/json',
56
            ],
57 2
            json_encode(
58
                [
59 2
                    'records' => $records
60
                ]
61
            )
62
        );
63
    }
64
}
65