GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 6d53bd...a5f194 )
by Pascal
01:05
created

BladeOnDemandRenderer::parseMarkdownMail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace ProtoneMedia\BladeOnDemand;
4
5
use Illuminate\Mail\Markdown;
6
use Illuminate\View\Factory as ViewFactory;
7
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
8
9
class BladeOnDemandRenderer
10
{
11
    /**
12
     * @var \Illuminate\View\Factory
13
     */
14
    private $viewFactory;
15
16
    /**
17
     * @var \Illuminate\Mail\Markdown
18
     */
19
    private $markdown;
20
21
    /**
22
     * @var \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles
23
     */
24
    private $cssInliner;
25
26
    public function __construct(ViewFactory $viewFactory, Markdown $markdown, CssToInlineStyles $cssInliner)
27
    {
28
        $this->viewFactory = $viewFactory;
29
        $this->markdown    = $markdown;
30
        $this->cssInliner  = $cssInliner;
31
    }
32
33
    /**
34
     * Renders the content with the given data.
35
     *
36
     * @param string $contents
37
     * @param array $data
38
     * @return string
39
     */
40
    public function render(string $contents, array $data = []): string
41
    {
42
        file_put_contents(
43
            $path = tempnam(sys_get_temp_dir(), 'blade-on-demand') . '.blade.php',
44
            $contents
45
        );
46
47
        $this->viewFactory->flushFinderCache();
48
49
        return tap($this->viewFactory->file($path, $data)->render(), function () use ($path) {
50
            unlink($path);
51
        });
52
    }
53
54
    /**
55
     * Renders the markdown content to a HTML mail.
56
     *
57
     * @param string $contents
58
     * @param array $data
59
     * @return string
60
     */
61
    public function renderMarkdownMailToHtml(string $contents, array $data = []): string
62
    {
63
        $this->viewFactory->replaceNamespace('mail', $this->markdown->htmlComponentPaths());
64
65
        $rendered = $this->render($contents, $data);
66
67
        return $this->cssInliner->convert(
68
            $rendered,
69
            $this->viewFactory->make('mail::themes.' . config('mail.markdown.theme', 'default'))->render()
70
        );
71
    }
72
73
    /**
74
     * Renders the markdown content to a Text mail.
75
     *
76
     * @param string $contents
77
     * @param array $data
78
     * @return string
79
     */
80
    public function renderMarkdownMailToText(string $contents, array $data = []): string
81
    {
82
        $this->viewFactory->replaceNamespace('mail', $this->markdown->textComponentPaths());
83
84
        $rendered = $this->render($contents, $data);
85
86
        return html_entity_decode(preg_replace("/[\r\n]{2,}/", "\n\n", $rendered), ENT_QUOTES, 'UTF-8');
87
    }
88
89
    /**
90
     * Parses the markdown content.
91
     *
92
     * @param string $contents
93
     * @param array $data
94
     * @return string
95
     */
96
    public function parseMarkdownMail(string $contents, array $data = []): string
97
    {
98
        return $this->markdown->parse($this->renderMarkdownMailToText($contents, $data));
99
    }
100
}
101