Completed
Push — master ( 8af02a...bb147a )
by Stefan
03:10
created

Border   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 30.43%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 9
c 2
b 1
f 1
lcom 1
cbo 0
dl 0
loc 76
ccs 7
cts 23
cp 0.3043
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 12 4
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 4
    public function setId($id)
31
    {
32 4
        $this->id = $id;
33 4
    }
34
35
    /**
36
     * @return mixed
37
     */
38 4
    public function getId()
39
    {
40 4
        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 4
    public function asXml()
60
    {
61 4
        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
        $diagonal = isset($this->styles[BorderType::DIAGONAL]) ? ' diagonalUp="1"' : '';
69
        return sprintf('<border%s>%s</border>', $diagonal, $borderXml);
70
    }
71
72
    /**
73
     * @param $type
74
     * @return string
75
     */
76
    private function getTypeXml($type)
77
    {
78
        if (!isset($this->styles[$type])) {
79
            return "<{$type}/>";
80
        }
81
        return sprintf('<%s style="%s"><color rgb="%s"/></%s>',
82
            $type, $this->styles[$type], $this->colors[$type], $type
83
        );
84
    }
85
}
86