Passed
Push — master ( f0db14...f804b5 )
by Jelle
02:39
created

PdfToGenerateDTO   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 39
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 1
A fromArray() 0 19 3
1
<?php
2
3
namespace Traincase\HtmlToPdfTinker\DTO;
4
5
class PdfToGenerateDTO
6
{
7 8
    public function __construct(
8
        // The filename if you plan to store this PDF on the filesystem.
9
        public string $filename,
10
11
        // The HTML string to convert to PDF
12
        public string $html,
13
14
        // Display orientation of the PDF: 'portrait' or 'landscape'
15
        public string $orientation,
16
17
        // Any driver specific options you wish to pass.
18
        public array $options,
19
20
        // The path to where you plan to store this PDF on the filesystem.
21
        public string $path,
22
    ) {
23
    }
24
25 9
    public static function fromArray(array $attributes): self
26
    {
27 9
        if (array_key_exists('orientation', $attributes)
28 9
            && !in_array($attributes['orientation'], ['portrait', 'landscape'])
29
        ) {
30 1
            throw new \InvalidArgumentException(
31 1
                sprintf(
32
                    'Mode should either be "portrait" or "landscape", got "%s"',
33 1
                    $attributes['orientation']
34
                )
35
            );
36
        }
37
38 8
        return new self(
39 8
            filename: $attributes['filename'],
40 8
            html: $attributes['html'],
41 8
            orientation: $attributes['orientation'] ?? 'portrait',
42 8
            options: $attributes['options'] ?? [],
43 8
            path: $attributes['path'] ?? '/',
44
        );
45
    }
46
}
47