CreateLabelInBulkForOrders   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 48
rs 10
ccs 19
cts 19
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getXml() 0 17 2
A getHeaders() 0 7 2
A getUrl() 0 6 3
1
<?php
2
3
namespace Bpost\BpostApiClient\Bpost;
4
5
use Bpost\BpostApiClient\Common\ValidatedValue\LabelFormat;
6
7
/**
8
 * Class CreateLabelInBulkForOrders
9
 */
10
class CreateLabelInBulkForOrders
11
{
12
    /**
13
     * @param string[] $references
14
     * @return string
15
     */
16 1
    public function getXml(array $references)
17
    {
18 1
        $document = new \DOMDocument('1.0', 'UTF-8');
19 1
        $document->preserveWhiteSpace = false;
20 1
        $document->formatOutput = true;
21
22 1
        $batchLabels = $document->createElement('batchLabels');
23 1
        $batchLabels->setAttribute('xmlns', 'http://schema.post.be/shm/deepintegration/v3/');
24 1
        foreach ($references as $reference) {
25 1
            $batchLabels->appendChild(
26 1
                $document->createElement('order', $reference)
27 1
            );
28 1
        }
29 1
        $document->appendChild($batchLabels);
30
31 1
        return $document->saveXML();
32
    }
33
34
    /**
35
     * @param bool $asPdf
36
     * @return string[]
37
     */
38 1
    public function getHeaders($asPdf)
39
    {
40
        return array(
41 1
            'Accept: application/vnd.bpost.shm-label-' . ($asPdf ? 'pdf' : 'image') . '-v3+XML',
42 1
            'Content-Type: application/vnd.bpost.shm-labelRequest-v3+XML',
43 1
        );
44
    }
45
46
    /**
47
     * @param LabelFormat $format
48
     * @param bool        $withReturnLabels
49
     * @return string
50
     */
51 1
    public function getUrl(LabelFormat $format, $withReturnLabels, $forcePrinting = false)
52
    {
53 1
        return '/labels/' . $format->getValue()
54
               . ($withReturnLabels ? '/withReturnLabels' : '')
55
               . ($forcePrinting ? '?forcePrinting=true' : '');
56
    }
57
}
58