Completed
Pull Request — master (#715)
by
unknown
01:52
created

ManagesCellSize   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 60
c 0
b 0
f 0
ccs 21
cts 21
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setDefaultColumnWidth() 0 4 1
A setDefaultRowHeight() 0 4 1
A setColumnWidth() 0 17 4
A setColumnWidthForRange() 0 4 1
1
<?php
2
3
4
namespace Box\Spout\Writer\Common\Manager;
5
6
7
trait ManagesCellSize
8
{
9
    /** @var float|null The default column width to use */
10
    private $defaultColumnWidth;
11
12
    /** @var float|null The default row height to use */
13
    private $defaultRowHeight;
14
15
    /** @var array Array of min-max-width arrays */
16
    private $columnWidths = [];
17
18
    /**
19
     * @param float|null $width
20
     */
21 49
    public function setDefaultColumnWidth($width)
22
    {
23 49
        $this->defaultColumnWidth = $width;
24 49
    }
25
26
    /**
27
     * @param float|null $height
28
     */
29 49
    public function setDefaultRowHeight($height)
30
    {
31 49
        $this->defaultRowHeight = $height;
32 49
    }
33
34
    /**
35
     * @param float $width
36
     * @param array $columns One or more columns with this width
37
     */
38 6
    public function setColumnWidth(float $width, ...$columns)
39
    {
40
        // Gather sequences
41 6
        $sequence = [];
42 6
        foreach ($columns as $i) {
43 6
            $sequenceLength = count($sequence);
44 6
            if ($sequenceLength > 0) {
45 4
                $previousValue = $sequence[$sequenceLength - 1];
46 4
                if ($i !== $previousValue + 1) {
47 2
                    $this->setColumnWidthForRange($width, $sequence[0], $previousValue);
48 2
                    $sequence = [];
49
                }
50
            }
51 6
            $sequence[] = $i;
52
        }
53 6
        $this->setColumnWidthForRange($width, $sequence[0], $sequence[count($sequence) - 1]);
54 6
    }
55
56
    /**
57
     * @param float $width The width to set
58
     * @param int $start First column index of the range
59
     * @param int $end Last column index of the range
60
     */
61 8
    public function setColumnWidthForRange(float $width, int $start, int $end)
62
    {
63 8
        $this->columnWidths[] = [$start, $end, $width];
64 8
    }
65
66
}
67