OfficeRequest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 20
c 1
b 0
f 0
dl 0
loc 63
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormFiles() 0 8 2
A setPageRanges() 0 3 1
A setLandscape() 0 3 1
A __construct() 0 4 1
A getPostURL() 0 3 1
A getFormValues() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TheCodingMachine\Gotenberg;
6
7
final class OfficeRequest extends Request implements GotenbergRequestInterface
8
{
9
    private const LANDSCAPE = 'landscape';
10
    private const PAGE_RANGES = 'pageRanges';
11
12
    /** @var Document[] */
13
    private $files;
14
15
    /** @var bool */
16
    private $landscape;
17
18
    /** @var string|null */
19
    private $pageRanges;
20
21
    /**
22
     * @param Document[] $files
23
     */
24
    public function __construct(array $files)
25
    {
26
        parent::__construct();
27
        $this->files = $files;
28
    }
29
30
    public function getPostURL(): string
31
    {
32
        return '/convert/office';
33
    }
34
35
    /**
36
     * @return array<string,mixed>
37
     */
38
    public function getFormValues(): array
39
    {
40
        $values = parent::getFormValues();
41
        if ($this->pageRanges !== null) {
42
            $values[self::PAGE_RANGES] = $this->pageRanges;
43
        }
44
        $values[self::LANDSCAPE] = $this->landscape;
45
46
        return $values;
47
    }
48
49
    /**
50
     * @return array<string,Document>
51
     */
52
    public function getFormFiles(): array
53
    {
54
        $files = [];
55
        foreach ($this->files as $file) {
56
            $files[$file->getFileName()] = $file;
57
        }
58
59
        return $files;
60
    }
61
62
    public function setLandscape(bool $landscape): void
63
    {
64
        $this->landscape = $landscape;
65
    }
66
67
    public function setPageRanges(string $pageRanges): void
68
    {
69
        $this->pageRanges = $pageRanges;
70
    }
71
}
72