Test Failed
Push — master ( a8f129...f0db14 )
by Jelle
16:19
created

PdfToGenerateDTO::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 16
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 5
crap 2
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