Passed
Push — refactor-02-filesystem-inject ( 3f5f4e...cc1d23 )
by John
02:35
created

CiffRenderer::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Graze\CiffRenderer;
4
5
use Graze\CiffRenderer\Renderer\RendererDocument;
6
use Illuminate\Filesystem\Filesystem;
0 ignored issues
show
Bug introduced by
The type Illuminate\Filesystem\Filesystem was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class CiffRenderer
9
{
10
    /**
11
     * @var Filesystem
12
     */
13
    private $filesystem;
14
15
    /**
16
     * @var RendererDocument
17
     */
18
    private $rendererDocument;
19
20
    /**
21
     * @var callable
22
     */
23
    private $fontResolver;
24
25
    /**
26
     * @var callable
27
     */
28
    private $graphicResolver;
29
30
    /**
31
     * @param Filesystem $filesystem
32
     * @param RendererDocument $rendererDocument
33
     */
34
    public function __construct(
35
        Filesystem $filesystem,
36
        RendererDocument $rendererDocument
37
    ) {
38
        $this->filesystem = $filesystem;
39
        $this->rendererDocument = $rendererDocument;
40
    }
41
42
    /**
43
     * Render an image from a ciff file located on the filesystem.
44
     *
45
     * @param string $path
46
     * @return Intervention\Image\Image
0 ignored issues
show
Bug introduced by
The type Graze\CiffRenderer\Intervention\Image\Image was not found. Did you mean Intervention\Image\Image? If so, make sure to prefix the type with \.
Loading history...
47
     */
48
    public function renderFile($path)
49
    {
50
        $string = $this->filesystem->get($path);
51
        return $this->renderString($string);
52
    }
53
54
    /**
55
     * Render an image from ciff data contained within a string.
56
     *
57
     * @param string $string
58
     * @return Intervention\Image\Image
59
     */
60
    public function renderString($string)
61
    {
62
        $xml = simplexml_load_string($string);
63
64
        return $this->rendererDocument->render(
65
            $xml,
0 ignored issues
show
Bug introduced by
It seems like $xml can also be of type false; however, parameter $xml of Graze\CiffRenderer\Rende...dererDocument::render() does only seem to accept SimpleXMLElement, 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

65
            /** @scrutinizer ignore-type */ $xml,
Loading history...
66
            $this->fontResolver,
67
            $this->graphicResolver
68
        );
69
    }
70
71
    /**
72
     * @param callable $fontResolver
73
     */
74
    public function setFontResolver(callable $fontResolver)
75
    {
76
        $this->fontResolver = $fontResolver;
77
    }
78
79
    /**
80
     * @param callable $graphicResolver
81
     */
82
    public function setGraphicResolver(callable $graphicResolver)
83
    {
84
        $this->graphicResolver = $graphicResolver;
85
    }
86
87
    /**
88
     * @return CiffRenderer
89
     */
90
    public static function factory()
91
    {
92
        return new static(
93
            new Filesystem(),
94
            RendererDocument::factory()
95
        );
96
    }
97
}
98