Passed
Push — master ( c2b576...f43d8f )
by Stephen
51s queued 10s
created

PdfExportService::fromViewData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Sfneal\ViewExport\Pdf;
4
5
use Illuminate\Contracts\View\View;
6
use Sfneal\ViewExport\Pdf\Utils\Renderer;
7
use Sfneal\ViewModels\AbstractViewModel;
8
9
class PdfExportService
10
{
11
    // todo: add ability to pass urls to export
12
13
    /**
14
     * Provide a view to build the PDF from.
15
     *
16
     * @param View $view
17
     * @param string|null $uploadPath
18
     * @return Renderer
19
     */
20
    public static function fromView(View $view, string $uploadPath = null): Renderer
21
    {
22
        return new Renderer($view->render(), $uploadPath);
0 ignored issues
show
Bug introduced by
It seems like $view->render() can also be of type array; however, parameter $content of Sfneal\ViewExport\Pdf\Ut...Renderer::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
        return new Renderer(/** @scrutinizer ignore-type */ $view->render(), $uploadPath);
Loading history...
23
    }
24
25
    /**
26
     * Provide a view to build the PDF from.
27
     *
28
     * @param AbstractViewModel $viewModel
29
     * @param string|null $uploadPath
30
     * @return Renderer
31
     */
32
    public static function fromViewModel(AbstractViewModel $viewModel, string $uploadPath = null): Renderer
33
    {
34
        return new Renderer($viewModel->renderNoCache(), $uploadPath);
35
    }
36
37
    /**
38
     * Provide an HTML string to build the PDF from.
39
     *
40
     * @param string $html
41
     * @param string|null $uploadPath
42
     * @return Renderer
43
     */
44
    public static function fromHtml(string $html, string $uploadPath = null): Renderer
45
    {
46
        return new Renderer($html, $uploadPath);
47
    }
48
49
    /**
50
     * Provide an HTML path to build the PDF from.
51
     *
52
     * @param string $path
53
     * @param string|null $uploadPath
54
     * @return Renderer
55
     */
56
    public static function fromHtmlFile(string $path, string $uploadPath = null): Renderer
57
    {
58
        return new Renderer(file_get_contents($path), $uploadPath);
59
    }
60
}
61