Completed
Push — refactor-04-parser-tests ( dc4950...bd4663 )
by John
06:06
created

CiffRenderer::render()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 54
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 54
ccs 0
cts 37
cp 0
rs 8.7449
c 0
b 0
f 0
cc 5
eloc 30
nc 9
nop 1
crap 30

2 Methods

Rating   Name   Duplication   Size   Complexity  
A CiffRenderer::setGraphicResolver() 0 4 1
A CiffRenderer::factory() 0 8 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Graze\CiffRenderer;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Graze\CiffRenderer\Parser\ParserDocument;
7
use Graze\CiffRenderer\Renderer\RendererDocument;
8
9
class CiffRenderer
10
{
11
    /**
12
     * @var Filesystem
13
     */
14
    private $filesystem;
15
16
    /**
17
     * @var ParserDocument
18
     */
19
    private $parserDocument;
20
21
    /**
22
     * @var RendererDocument
23
     */
24
    private $rendererDocument;
25
26
    /**
27
     * @var callable
28
     */
29
    private $fontResolver;
30
31
    /**
32
     * @var callable
33
     */
34
    private $graphicResolver;
35
36
    /**
37
     * @param Filesystem $filesystem
38
     * @param ParserDocument $parserDocument
39
     * @param RendererDocument $rendererDocument
40
     */
41 2
    public function __construct(
42
        Filesystem $filesystem,
43
        ParserDocument $parserDocument,
44
        RendererDocument $rendererDocument
45
    ) {
46 2
        $this->filesystem = $filesystem;
47 2
        $this->parserDocument = $parserDocument;
48 2
        $this->rendererDocument = $rendererDocument;
49 2
    }
50
51
    /**
52
     * Render an image from a ciff file located on the filesystem.
53
     *
54
     * @param string $path
55
     * @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...
56
     */
57 1
    public function renderFile($path)
58
    {
59 1
        $string = $this->filesystem->get($path);
60 1
        return $this->renderString($string);
61
    }
62
63
    /**
64
     * Render an image from ciff data contained within a string.
65
     *
66
     * @param string $string
67
     * @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...
68
     */
69 2
    public function renderString($string)
70
    {
71 2
        $this->parserDocument->parse($string);
72
73 2
        return $this->rendererDocument->render(
74 2
            $this->parserDocument,
75 2
            $this->fontResolver,
76 2
            $this->graphicResolver
77
        );
78
    }
79
80
    /**
81
     * @param callable $fontResolver
82
     */
83 2
    public function setFontResolver(callable $fontResolver)
84
    {
85 2
        $this->fontResolver = $fontResolver;
86 2
    }
87
88
    /**
89
     * @param callable $graphicResolver
90
     */
91 2
    public function setGraphicResolver(callable $graphicResolver)
92
    {
93 2
        $this->graphicResolver = $graphicResolver;
94 2
    }
95
96
    /**
97
     * @return CiffRenderer
98
     */
99
    public static function factory()
100
    {
101
        return new static(
102
            new Filesystem(),
103
            ParserDocument::factory(),
104
            RendererDocument::factory()
105
        );
106
    }
107
}
108