Completed
Pull Request — master (#18)
by John
05:06 queued 03:09
created

CiffRenderer::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Graze\CiffRenderer;
4
5
use Graze\CiffRenderer\Renderer\RendererDocument;
6
7
class CiffRenderer
8
{
9
    /**
10
     * @var RendererDocument
11
     */
12
    private $rendererDocument;
13
14
    /**
15
     * @var callable
16
     */
17
    private $fontResolver;
18
19
    /**
20
     * @var callable
21
     */
22
    private $graphicResolver;
23
24
    /**
25
     * @param RendererDocument $rendererDocument
26
     */
27
    public function __construct(RendererDocument $rendererDocument)
28
    {
29
        $this->rendererDocument = $rendererDocument;
30
    }
31
32
    /**
33
     * Render an image from a ciff file located on the filesystem.
34
     *
35
     * @param string $filePath
36
     * @return Intervention\Image\Image
0 ignored issues
show
Documentation introduced by
Should the return type not be \Intervention\Image\Image?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
37
     */
38
    public function renderFile($filePath)
39
    {
40
        $xml = simplexml_load_file($filePath);
41
        return $this->render($xml);
42
    }
43
44
    /**
45
     * Render an image from ciff data contained within a string.
46
     *
47
     * @param string $string
48
     * @return Intervention\Image\Image
0 ignored issues
show
Documentation introduced by
Should the return type not be \Intervention\Image\Image?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
49
     */
50
    public function renderString($string)
51
    {
52
        $xml = simplexml_load_string($string);
53
        return $this->render($xml);
54
    }
55
56
    /**
57
     * @param \SimpleXMLElement $xml
58
     * @return Intervention\Image\Image
0 ignored issues
show
Documentation introduced by
Should the return type not be \Intervention\Image\Image?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
59
     */
60
    private function render(\SimpleXMLElement $xml)
61
    {
62
        return $this->rendererDocument->render(
63
            $xml,
64
            $this->fontResolver,
65
            $this->graphicResolver
66
        );
67
    }
68
69
    /**
70
     * @param callable $fontResolver
71
     */
72
    public function setFontResolver(callable $fontResolver)
73
    {
74
        $this->fontResolver = $fontResolver;
75
    }
76
77
    /**
78
     * @param callable $graphicResolver
79
     */
80
    public function setGraphicResolver(callable $graphicResolver)
81
    {
82
        $this->graphicResolver = $graphicResolver;
83
    }
84
85
    /**
86
     * @return CiffRenderer
87
     */
88
    public static function factory()
89
    {
90
        return new static(
91
            RendererDocument::factory()
92
        );
93
    }
94
}
95