ImageFont   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 47
c 4
b 0
f 0
dl 0
loc 97
ccs 0
cts 51
cp 0
rs 10
wmc 12

10 Methods

Rating   Name   Duplication   Size   Complexity  
A color() 0 3 1
A __construct() 0 3 1
A text() 0 5 1
A font() 0 9 2
A size() 0 5 1
A valign() 0 2 1
A align() 0 2 1
A createColor() 0 7 1
A angle() 0 5 1
A apply() 0 24 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Suricate;
6
7
class ImageFont
8
{
9
    const FONTTYPE_INTERNAL = 1;
10
    const FONTTYPE_TTF = 2;
11
12
    private $color;
13
    private $text;
14
    private $angle = 0;
15
    private $size = 8;
16
    private $fontType;
17
    private $font;
18
    private $image;
0 ignored issues
show
introduced by
The private property $image is not used, and could be removed.
Loading history...
19
20
    public function __construct($text = '')
21
    {
22
        $this->text = $text;
23
    }
24
25
    public function font($fontFile)
26
    {
27
        if (is_int($fontFile)) {
28
            $this->fontType = self::FONTTYPE_INTERNAL;
29
        } else {
30
            $this->fontType = self::FONTTYPE_TTF;
31
        }
32
33
        $this->font = $fontFile;
34
    }
35
36
    public function size($size)
37
    {
38
        $this->size = $size;
39
40
        return $this;
41
    }
42
43
    public function angle($angle)
44
    {
45
        $this->angle = $angle;
46
47
        return $this;
48
    }
49
50
    public function color($color)
51
    {
52
        $this->color = $color;
53
    }
54
55
    private function createColor($image)
56
    {
57
        return imagecolorallocate(
58
            $image,
59
            $this->color[0],
60
            $this->color[1],
61
            $this->color[2]
62
        );
63
    }
64
65
    public function align($align)
0 ignored issues
show
Unused Code introduced by
The parameter $align is not used and could be removed. ( Ignorable by Annotation )

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

65
    public function align(/** @scrutinizer ignore-unused */ $align)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
    {
67
    }
68
69
    public function text($text)
70
    {
71
        $this->text = $text;
72
73
        return $this;
74
    }
75
76
    public function valign($align)
0 ignored issues
show
Unused Code introduced by
The parameter $align is not used and could be removed. ( Ignorable by Annotation )

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

76
    public function valign(/** @scrutinizer ignore-unused */ $align)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
    {
78
    }
79
80
    public function apply(&$image, $x = 0, $y = 0)
81
    {
82
        $colorResource = $this->createColor($image);
83
84
        if ($this->fontType == self::FONTTYPE_INTERNAL) {
85
            imagestring(
86
                $image,
87
                $this->font,
88
                $x,
89
                $y,
90
                $this->text,
91
                $colorResource
92
            );
93
            return;
94
        }
95
        imagettftext(
96
            $image,
97
            $this->size,
98
            $this->angle,
99
            $x,
100
            $y,
101
            $colorResource,
102
            $this->font,
103
            $this->text
104
        );
105
    }
106
}
107