Test Failed
Push — master ( a8f129...f0db14 )
by Jelle
16:19
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 6
cts 6
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
    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
    public static function fromArray(array $attributes): self
26
    {
27
        if (array_key_exists('orientation', $attributes)
28
            && !in_array($attributes['orientation'], ['portrait', 'landscape'])
29
        ) {
30
            throw new \InvalidArgumentException(
31
                sprintf(
32
                    'Mode should either be "portrait" or "landscape", got "%s"',
33
                    $attributes['orientation']
34 9
                )
35
            );
36 9
        }
37 9
38
        return new self(
39 1
            filename: $attributes['filename'],
40 1
            html: $attributes['html'],
41 1
            orientation: $attributes['orientation'] ?? 'portrait',
42
            options: $attributes['options'] ?? [],
43
            path: $attributes['path'] ?? '/',
44
        );
45 8
    }
46
}
47