BorderHelper   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 47
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A serializeBorderPart() 0 17 2
1
<?php
2
3
namespace Box\Spout\Writer\ODS\Helper;
4
5
use Box\Spout\Common\Entity\Style\Border;
6
use Box\Spout\Common\Entity\Style\BorderPart;
7
8
/**
9
 * Class BorderHelper
10
 *
11
 * The fo:border, fo:border-top, fo:border-bottom, fo:border-left and fo:border-right attributes
12
 * specify border properties
13
 * http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#__RefHeading__1419780_253892949
14
 *
15
 * Example table-cell-properties
16
 *
17
 * <style:table-cell-properties
18
 * fo:border-bottom="0.74pt solid #ffc000" style:diagonal-bl-tr="none"
19
 * style:diagonal-tl-br="none" fo:border-left="none" fo:border-right="none"
20
 * style:rotation-align="none" fo:border-top="none"/>
21
 */
22
class BorderHelper
23
{
24
    /**
25
     * Width mappings
26
     *
27
     * @var array
28
     */
29
    protected static $widthMap = [
30
        Border::WIDTH_THIN   => '0.75pt',
31
        Border::WIDTH_MEDIUM => '1.75pt',
32
        Border::WIDTH_THICK  => '2.5pt',
33
    ];
34
35
    /**
36
     * Style mapping
37
     *
38
     * @var array
39
     */
40
    protected static $styleMap = [
41
        Border::STYLE_SOLID  => 'solid',
42
        Border::STYLE_DASHED => 'dashed',
43
        Border::STYLE_DOTTED => 'dotted',
44
        Border::STYLE_DOUBLE => 'double',
45
    ];
46
47
    /**
48
     * @param BorderPart $borderPart
49
     * @return string
50
     */
51 1
    public static function serializeBorderPart(BorderPart $borderPart)
52
    {
53 1
        $definition = 'fo:border-%s="%s"';
54
55 1
        if ($borderPart->getStyle() === Border::STYLE_NONE) {
56
            $borderPartDefinition = \sprintf($definition, $borderPart->getName(), 'none');
57
        } else {
58
            $attributes = [
59 1
                self::$widthMap[$borderPart->getWidth()],
60 1
                self::$styleMap[$borderPart->getStyle()],
61 1
                '#' . $borderPart->getColor(),
62
            ];
63 1
            $borderPartDefinition = \sprintf($definition, $borderPart->getName(), \implode(' ', $attributes));
64
        }
65
66 1
        return $borderPartDefinition;
67
    }
68
}
69