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

ImageUrlUpload   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 55.56%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 31
ccs 5
cts 9
cp 0.5556
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getPostBodyData() 0 9 1
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