Completed
Push — master ( 1f4ad9...320f5c )
by John
03:15
created

FieldRendererBarcode   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 39
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 20 1
A factory() 0 3 1
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
use Graze\CiffRenderer\Renderer\Font\FontFace;
9
10
class FieldRendererBarcode implements FieldRendererInterface
11
{
12
    const FONT_SIZE_MULTIPLIER = 6.2;
13
14
    /**
15
     * @param ImageManager $imageManager
16
     * @param FieldParserInterface $parser
17
     * @param callable $fontResolver
18
     * @param callable $graphicResolver
19
     * @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...
20
     */
21 1
    public function render(
22
        ImageManager $imageManager,
23
        FieldParserInterface $parser,
24
        callable $fontResolver = null,
25
        callable $graphicResolver = null
26
    ) {
27 1
        $image = $imageManager->canvas($parser->getWidth(), $parser->getHeight(), '#000');
28 1
        $fontPath = $fontResolver(FontFace::FACE_BARCODE);
29
30 1
        $fontCallback = function ($font) use ($fontPath, $parser) {
31 1
            $font->file($fontPath);
32 1
            $font->size($parser->getFontSize() * self::FONT_SIZE_MULTIPLIER);
0 ignored issues
show
Bug introduced by
The method getFontSize() does not exist on Graze\CiffRenderer\Parse...er\FieldParserInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Graze\CiffRenderer\Parse...dParserGraphicPrimitive or Graze\CiffRenderer\Parse...ser\AbstractFieldParser or Graze\CiffRenderer\Parse...ieldParserStaticGraphic or Graze\CiffRenderer\Parse...dParserGraphicPrimitive or Graze\CiffRenderer\Parse...ieldParserStaticGraphic. Are you sure you never get one of those? ( Ignorable by Annotation )

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

32
            $font->size($parser->/** @scrutinizer ignore-call */ getFontSize() * self::FONT_SIZE_MULTIPLIER);
Loading history...
33 1
            $font->color('#fff');
34 1
            $font->align('center');
35 1
            $font->valign('middle');
36 1
        };
37
38 1
        $image->text($parser->getText(), $parser->getWidth() / 2, $parser->getHeight(), $fontCallback);
0 ignored issues
show
Bug introduced by
The method getText() does not exist on Graze\CiffRenderer\Parse...er\FieldParserInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Graze\CiffRenderer\Parse...dParserGraphicPrimitive or Graze\CiffRenderer\Parse...ser\AbstractFieldParser or Graze\CiffRenderer\Parse...ieldParserStaticGraphic or Graze\CiffRenderer\Parse...dParserGraphicPrimitive or Graze\CiffRenderer\Parse...ieldParserStaticGraphic. Are you sure you never get one of those? ( Ignorable by Annotation )

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

38
        $image->text($parser->/** @scrutinizer ignore-call */ getText(), $parser->getWidth() / 2, $parser->getHeight(), $fontCallback);
Loading history...
39
40 1
        return $image;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $image returns the type Intervention\Image\Image which is incompatible with the documented return type Graze\CiffRenderer\Rende...ntervention\Image\Image.
Loading history...
41
    }
42
43
    /**
44
     * @return FieldParserInterface
45
     */
46 1
    public static function factory()
47
    {
48 1
        return new static();
0 ignored issues
show
Bug Best Practice introduced by
The expression return new static() returns the type Graze\CiffRenderer\Rende...er\FieldRendererBarcode which is incompatible with the documented return type Graze\CiffRenderer\Parse...er\FieldParserInterface.
Loading history...
49
    }
50
}
51