Test Failed
Pull Request — master (#29)
by
unknown
02:05
created

ImageUrlUpload::getPostBodyData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 4
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Client\Image;
6
7
final class ImageUrlUpload implements ImageUploadRequestInterface
8
{
9
    const ALLOWED_FILE_TYPES = [
10
        'gif'  => 'GIF',
11
        'jpeg' => 'JPEG',
12
        'jpg'  => 'JPEG',
13
        'png'  => 'PNG',
14
        'bmp'  => 'BMP',
15
    ];
16
17
    private $imageUrl;
18
    private $imageFormat;
19
20 1
    public function __construct(string $imageUrl)
21
    {
22 1
        $this->imageUrl     = $imageUrl;
23 1
        $this->imageFormat  = self::ALLOWED_FILE_TYPES[
24 1
            strtolower(array_values(array_slice(explode('.', $imageUrl), -1))[0])
25
        ];
26 1
    }
27
28
    public function getPostBodyData(): string
29
    {
30
        $data = [
31
            'imageFormat'   => $this->imageFormat,
32
            'imageUrl'      => $this->imageUrl
33
        ];
34
35
        return json_encode($data);
36
    }
37
}
38