Completed
Pull Request — master (#19)
by John
05:39 queued 03:41
created

FieldRendererStaticGraphic::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 8
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\CiffRenderer\Renderer\FieldRenderer;
4
5
use Graze\CiffRenderer\Renderer\FieldRenderer\FieldRendererInterface;
6
use Intervention\Image\ImageManager;
7
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface;
8
9
class FieldRendererStaticGraphic implements FieldRendererInterface
10
{
11
    /**
12
     * @param ImageManager $imageManager
13
     * @param FieldParserInterface $parser
14
     * @param callable $fontResolver
15
     * @param callable $graphicResolver
16
     * @return Intervention\Image\Image
0 ignored issues
show
Bug introduced by
The type Graze\CiffRenderer\Rende...ntervention\Image\Image was not found. Did you mean Intervention\Image\Image? If so, make sure to prefix the type with \.
Loading history...
17
     */
18 1
    public function render(
19
        ImageManager $imageManager,
20
        FieldParserInterface $parser,
21
        callable $fontResolver = null,
22
        callable $graphicResolver = null
23
    ) {
24 1
        $gdResource = $graphicResolver($parser->getGraphic());
0 ignored issues
show
Bug introduced by
The method getGraphic() does not exist on Graze\CiffRenderer\Parse...er\FieldParserInterface. It seems like you code against a sub-type of Graze\CiffRenderer\Parse...er\FieldParserInterface such as Graze\CiffRenderer\Parse...ieldParserStaticGraphic or Graze\CiffRenderer\Parse...ieldParserStaticGraphic. ( Ignorable by Annotation )

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

24
        $gdResource = $graphicResolver($parser->/** @scrutinizer ignore-call */ getGraphic());
Loading history...
25 1
        return $imageManager->make($gdResource);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $imageManager->make($gdResource) returns the type Intervention\Image\Image which is incompatible with the documented return type Graze\CiffRenderer\Rende...ntervention\Image\Image.
Loading history...
26
    }
27
28
    /**
29
     * @return FieldRendererInterface
30
     */
31 1
    public static function factory()
32
    {
33 1
        return new static();
0 ignored issues
show
Bug Best Practice introduced by
The expression return new static() returns the type Graze\CiffRenderer\Rende...ldRendererStaticGraphic which is incompatible with the return type mandated by Graze\CiffRenderer\Rende...rerInterface::factory() of Graze\CiffRenderer\Parse...er\FieldParserInterface.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
34
    }
35
}
36