ContentPage   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A generatePage() 0 20 2
1
<?php namespace Todaymade\Daux\Format\HTMLFile;
2
3
use Todaymade\Daux\Format\Base\EmbedImages;
4
use Todaymade\Daux\Tree\Raw;
5
6
class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
7
{
8
    public $attachments = [];
9
10
    protected function generatePage()
11
    {
12
        $content = parent::generatePage();
13
14
        // Embed images
15
        // We do it after generation so we can catch the images that were in html already
16
        return (new EmbedImages($this->config->getTree()))
17
            ->embed(
18
                $content,
19
                $this->file,
20
                function ($src, array $attributes, Raw $file) {
21
                    // TODO :: ignore absolute paths
22
                    $content = base64_encode(file_get_contents($file->getPath()));
23
                    $attr = '';
24
                    foreach ($attributes as $name => $value) {
25
                        $attr .= ' ' . $name . '="' . htmlentities($value, ENT_QUOTES, 'UTF-8', false) . '"';
26
                    }
27
28
                    // TODO :: handle other formats than PNG as well
29
                    return "<img $attr src=\"data:image/png;base64,$content\"/>";
30
                }
31
            );
32
    }
33
}
34