Passed
Push — refactor-01-decoupling ( 3120c6...479d2f )
by John
04:44
created

GraphicResolverFilePath::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\CiffRenderer\GraphicResolver;
4
5
use Graze\CiffRenderer\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
    public function __construct(Bmp $bmp)
23
    {
24
        $this->bmp = $bmp;
25
    }
26
27
    /**
28
     * @param string $filePath
29
     * @return Resource
30
     */
31
    public function __invoke($filePath)
32
    {
33
        try {
34
            return $this->bmp->create($filePath);
0 ignored issues
show
Bug introduced by
$filePath of type string is incompatible with the type Urbanplum\Bmp\Reader\ReaderInterface expected by parameter $reader of Urbanplum\Bmp\Bmp::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
            return $this->bmp->create(/** @scrutinizer ignore-type */ $filePath);
Loading history...
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