Completed
Push — master ( 151065...57d309 )
by Stefan
03:48
created

Style::size()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * @author neun
4
 * @since  2016-07-03
5
 */
6
7
namespace OneSheet;
8
9
/**
10
 * Class Style
11
 * @package OneSheet
12
 */
13
class Style
14
{
15
    /**
16
     * @var int
17
     */
18
    private $size = 11;
19
20
    /**
21
     * @var string
22
     */
23
    private $color = '000000';
24
25
    /**
26
     * @var string
27
     */
28
    private $name = 'Calibri';
29
30
    /**
31
     * @var string
32
     */
33
    private $bold;
34
35
    /**
36
     * @var string
37
     */
38
    private $italic;
39
40
    /**
41
     * @var string
42
     */
43
    private $underline;
44
45
    /**
46
     * @var string
47
     */
48
    private $fill;
49
50
    /**
51
     * @return string
52
     */
53
    public function getFontXml()
54
    {
55
        return sprintf('<font><sz val="%s"/><color rgb="%s"/><name val="%s"/>%s%s%s</font>',
56
            $this->size, $this->color, $this->name, $this->bold, $this->italic, $this->underline
57
        );
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getFillXml()
64
    {
65
        if (!$this->fill) {
66
            return '<fill><patternFill patternType="none"/></fill>';
67
        }
68
        return '<fill><patternFill patternType="solid"><fgColor rgb="' . $this->fill . '"/></patternFill></fill>';
69
    }
70
71
    /**
72
     * Set font size.
73
     *
74
     * @param int $size
75
     * @return Style
76
     */
77
    public function size($size)
78
    {
79
        $this->size = $size;
80
        return $this;
81
    }
82
83
    /**
84
     * Set font color.
85
     *
86
     * @param string $color
87
     * @return Style
88
     */
89
    public function color($color)
90
    {
91
        $this->color = strtoupper($color);
92
        return $this;
93
    }
94
95
    /**
96
     * Set font name.
97
     *
98
     * @param string $name
99
     * @return Style
100
     */
101
    public function name($name)
102
    {
103
        $this->name = $name;
104
        return $this;
105
    }
106
107
    /**
108
     * Make font bold.
109
     *
110
     * @return Style
111
     */
112
    public function bold()
113
    {
114
        $this->bold = '<b/>';
115
        return $this;
116
    }
117
118
    /**
119
     * Make font italic.
120
     *
121
     * @return Style
122
     */
123
    public function italic()
124
    {
125
        $this->italic = '<i/>';
126
        return $this;
127
    }
128
129
    /**
130
     * Underline the font text.
131
     *
132
     * @return Style
133
     */
134
    public function underline()
135
    {
136
        $this->underline = '<u/>';
137
        return $this;
138
    }
139
140
    /**
141
     * Set the cell fill/background color.
142
     *
143
     * @param string $fill
144
     * @return Style
145
     */
146
    public function fill($fill)
147
    {
148
        $this->fill = strtoupper($fill);
149
        return $this;
150
    }
151
}
152