CreateLabelBuilder   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
eloc 14
c 2
b 0
f 0
dl 0
loc 48
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 3 1
A getHeaders() 0 7 2
A __construct() 0 6 1
A getUrl() 0 8 2
A isExpectXml() 0 3 1
A getXml() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Bpost\BpostApiClient\Bpost\HttpRequestBuilder;
5
6
use Bpost\BpostApiClient\Common\ApiVersions;
7
use Bpost\BpostApiClient\Common\ValidatedValue\LabelFormat;
8
9
abstract class CreateLabelBuilder implements HttpRequestBuilderInterface
10
{
11
    public function __construct(
12
        protected readonly string $reference,
13
        protected readonly LabelFormat $labelFormat,
14
        protected readonly bool $asPdf,
15
        protected readonly bool $withReturnLabels,
16
    ) {}
17
18
    /**
19
     * @return string
20
     */
21
    abstract protected function getUrlPrefix(): string;
22
23
    public function getXml(): ?string
24
    {
25
        return null;
26
    }
27
28
    public function getHeaders(): array
29
    {
30
        $media = $this->asPdf ? 'pdf' : 'image';
31
32
        return [
33
            'Accept: application/vnd.bpost.shm-label-' . $media . '-' . ApiVersions::V3_4 . '+XML',
34
            'Content-Type: application/vnd.bpost.shm-labelRequest-' . ApiVersions::V3 . '+XML',
35
        ];
36
    }
37
38
    public function getUrl(): string
39
    {
40
        return sprintf(
41
            '/%s/%s/labels/%s%s',
42
            $this->getUrlPrefix(),
43
            $this->reference,
44
            $this->labelFormat->getValue(),
45
            $this->withReturnLabels ? '/withReturnLabels' : ''
46
        );
47
    }
48
49
    public function getMethod(): string
50
    {
51
        return self::METHOD_GET;
52
    }
53
54
    public function isExpectXml(): bool
55
    {
56
        return true;
57
    }
58
}