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

GraphicResolverFilePath   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 6 2
A factory() 0 4 1
1
<?php
2
3
namespace Graze\CiffRenderer\GraphicResolver;
4
5
use Graze\CiffRenderer\GraphicResolver\GraphicResolverInterface;
0 ignored issues
show
Bug introduced by
The type Graze\CiffRenderer\Graph...raphicResolverInterface 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...
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->createFromFile($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