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

GraphicResolverFilePath::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.5

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 2
cts 4
cp 0.5
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.5
1
<?php
2
3
namespace Graze\CiffRenderer\Renderer\GraphicResolver;
4
5
use Graze\CiffRenderer\Renderer\GraphicResolver\GraphicResolverInterface;
6
use Urbanplum\Bmp\Bmp;
7
use Graze\CiffRenderer\Exception\RuntimeException;
8
9
/**
10
 * Resolves an image resource from it's file path
11
 */
12
class GraphicResolverFilePath implements GraphicResolverInterface
13
{
14
    /**
15
     * @var Bmp
16
     */
17
    private $bmp;
18
19
    /**
20
     * @param Bmp $bmp
21
     */
22 1
    public function __construct(Bmp $bmp)
23
    {
24 1
        $this->bmp = $bmp;
25 1
    }
26
27
    /**
28
     * @param string $filePath
29
     * @return Resource
30
     */
31 1
    public function __invoke($filePath)
32
    {
33
        try {
34 1
            return $this->bmp->create($filePath);
35
        } catch (\Exception $e) {
36
            throw new RuntimeException($e);
37
        }
38
    }
39
40
    /**
41
     * @return GraphicResolverInterface
42
     */
43
    public static function factory()
44
    {
45
        return new static(
46
            new Bmp()
47
        );
48
    }
49
}
50