Completed
Push — master ( 26d7ed...da315f )
by Stefan
04:47 queued 02:12
created

Border   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 75
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setId() 0 4 1
A getId() 0 4 1
A set() 0 6 1
A asXml() 0 11 3
A getTypeXml() 0 9 2
1
<?php
2
3
namespace OneSheet\Style;
4
5
/**
6
 * Class Border for reusable border definitions.
7
 *
8
 * @package OneSheet
9
 */
10
class Border implements Component
11
{
12
    /**
13
     * @var int
14
     */
15
    private $id;
16
17
    /**
18
     * @var array
19
     */
20
    private $styles = array();
21
22
    /**
23
     * @var array
24
     */
25
    private $colors = array();
26
27
    /**
28
     * @param mixed $id
29
     */
30
    public function setId($id)
31
    {
32
        $this->id = $id;
33
    }
34
35
    /**
36
     * @return mixed
37
     */
38
    public function getId()
39
    {
40
        return $this->id;
41
    }
42
43
    /**
44
     * @param string $type
45
     * @param string $style
46
     * @param string $color
47
     * @return Border
48
     */
49
    public function set($type, $style, $color)
50
    {
51
        $this->styles[$type] = $style;
52
        $this->colors[$type] = strtoupper($color);
53
        return $this;
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function asXml()
60
    {
61
        if (!count($this->styles)) return '<border/>';
62
63
        $borderXml = '';
64
        foreach (array('left', 'right', 'top', 'bottom', 'diagonal') as $type) {
65
            $borderXml .= $this->getTypeXml($type);
66
        }
67
68
        return sprintf('<border>%s</border>', $borderXml);
69
    }
70
71
    /**
72
     * @param $type
73
     * @return string
74
     */
75
    private function getTypeXml($type)
76
    {
77
        if (!isset($this->styles[$type])) {
78
            return "<{$type}/>";
79
        }
80
        return sprintf('<%s style="%s"><color rgb="%s"/></%s>',
81
            $type, $this->styles[$type], $this->colors[$type], $type
82
        );
83
    }
84
}
85