Font::getFonts()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
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