Font   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 51
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A arial() 0 5 1
A getFonts() 0 6 1
A __toString() 0 3 1
A __construct() 0 6 2
1
<?php
2
3
namespace Jackal\ImageMerge\Model\Font;
4
5
use Jackal\ImageMerge\Exception\InvalidFontException;
6
7
/**
8
 * Class Font
9
 * @package Jackal\ImageMerge\Model\Font
10
 */
11
class Font
12
{
13
    const FONT_ARIAL = 'arial';
14
15
    /**
16
     * @var string
17
     */
18
    private $fontPathname;
19
20
    /**
21
     * @return array
22
     */
23
    private static function getFonts()
24
    {
25
        $directory = dirname(__FILE__) . '/../../Resources/Fonts/';
26
27
        return [
28
            self::FONT_ARIAL => $directory . 'arial.ttf',
29
        ];
30
    }
31
32
    /**
33
     * Font constructor.
34
     * @param $fontPathname
35
     * @throws InvalidFontException
36
     */
37
    public function __construct($fontPathname)
38
    {
39
        if (!is_file($fontPathname)) {
40
            throw new InvalidFontException('Font file not found at path ' . $fontPathname);
41
        }
42
        $this->fontPathname = $fontPathname;
43
    }
44
45
    /**
46
     * @return Font
47
     * @throws InvalidFontException
48
     */
49
    public static function arial()
50
    {
51
        $fonts = Font::getFonts();
52
53
        return new Font($fonts[Font::FONT_ARIAL]);
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function __toString()
60
    {
61
        return $this->fontPathname;
62
    }
63
}
64