Passed
Push — master ( e79061...af4049 )
by Bingo
03:12
created

ImageRenderer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace PhpDocxTemplate\Twig\Impl;
4
5
use PhpDocxTemplate\PhpDocxTemplate;
6
use PhpDocxTemplate\Twig\RendererInterface;
7
8
class ImageRenderer implements RendererInterface
9
{
10
    private $template;
11
12 7
    public function __construct(PhpDocxTemplate $template)
13
    {
14 7
        $this->template = $template;
15 7
    }
16
17 1
    public function render(string $path, int $width, int $height): string
18
    {
19 1
        $docx = $this->template->getDocx();
20 1
        $preparedImageAttrs = $docx->prepareImageAttrs(['path' => $path, 'width' => $width, 'height' => $height]);
21 1
        $imgPath = $preparedImageAttrs['src'];
22
23
        // get image index
24 1
        $imgIndex = $docx->getNextRelationsIndex($path);
25 1
        $rid = 'rId' . $imgIndex;
26
27
        // replace preparations
28 1
        $docx->addImageToRelations($path, $rid, $imgPath, $preparedImageAttrs['mime']);
29 1
        $xmlImage = str_replace(array('{RID}', '{WIDTH}', '{HEIGHT}'), array($rid, $preparedImageAttrs['width'], $preparedImageAttrs['height']), $docx->getImageTemplate());
30 1
        return $xmlImage;
31
    }
32
}
33