Completed
Pull Request — master (#762)
by
unknown
02:29
created

Sheet::setMergeRanges()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Box\Spout\Writer\Common\Entity;
4
5
use Box\Spout\Writer\Common\Manager\SheetManager;
6
7
/**
8
 * Class Sheet
9
 * External representation of a worksheet
10
 */
11
class Sheet
12
{
13
    const DEFAULT_SHEET_NAME_PREFIX = 'Sheet';
14
15
    /** @var int Index of the sheet, based on order in the workbook (zero-based) */
16
    private $index;
17
18
    /** @var string ID of the sheet's associated workbook. Used to restrict sheet name uniqueness enforcement to a single workbook */
19
    private $associatedWorkbookId;
20
21
    /** @var string Name of the sheet */
22
    private $name;
23
24
    /** @var bool Visibility of the sheet */
25
    private $isVisible;
26
27
    /** @var SheetManager Sheet manager */
28
    private $sheetManager;
29
30
    /** @var merge cell */
31
    private $mergeRanges;
32
33
    /**
34
     * @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based)
35
     * @param string $associatedWorkbookId ID of the sheet's associated workbook
36
     * @param SheetManager $sheetManager To manage sheets
37
     */
38 96
    public function __construct($sheetIndex, $associatedWorkbookId, SheetManager $sheetManager)
39
    {
40 96
        $this->index = $sheetIndex;
41 96
        $this->associatedWorkbookId = $associatedWorkbookId;
42
43 96
        $this->sheetManager = $sheetManager;
44 96
        $this->sheetManager->markWorkbookIdAsUsed($associatedWorkbookId);
45
46 96
        $this->setName(self::DEFAULT_SHEET_NAME_PREFIX . ($sheetIndex + 1));
47 96
        $this->setIsVisible(true);
48 96
    }
49
50
    /**
51
     * @return int Index of the sheet, based on order in the workbook (zero-based)
52
     */
53 96
    public function getIndex()
54
    {
55 96
        return $this->index;
56
    }
57
58
    /**
59
     * @return string
60
     */
61 96
    public function getAssociatedWorkbookId()
62
    {
63 96
        return $this->associatedWorkbookId;
64
    }
65
66
    /**
67
     * @return string Name of the sheet
68
     */
69 96
    public function getName()
70
    {
71 96
        return $this->name;
72
    }
73
74
    /**
75
     * Sets the name of the sheet. Note that Excel has some restrictions on the name:
76
     *  - it should not be blank
77
     *  - it should not exceed 31 characters
78
     *  - it should not contain these characters: \ / ? * : [ or ]
79
     *  - it should be unique
80
     *
81
     * @param string $name Name of the sheet
82
     * @throws \Box\Spout\Writer\Exception\InvalidSheetNameException If the sheet's name is invalid.
83
     * @return Sheet
84
     */
85 96
    public function setName($name)
86
    {
87 96
        $this->sheetManager->throwIfNameIsInvalid($name, $this);
88
89 96
        $this->name = $name;
90
91 96
        $this->sheetManager->markSheetNameAsUsed($this);
92
93 96
        return $this;
94
    }
95
96
    /**
97
     * @return bool isVisible Visibility of the sheet
98
     */
99 73
    public function isVisible()
100
    {
101 73
        return $this->isVisible;
102
    }
103
104
    /**
105
     * @param bool $isVisible Visibility of the sheet
106
     * @return Sheet
107
     */
108 96
    public function setIsVisible($isVisible)
109
    {
110 96
        $this->isVisible = $isVisible;
111
112 96
        return $this;
113
    }
114
115
    /**
116
     * @return merge
117
     */
118 38
    public function getMergeRanges()
119
    {
120 38
        return $this->mergeRanges;
121
    }
122
123
    /**
124
     * @param $mergeRanges
125
     * @return mixed
126
     */
127
    public function setMergeRanges($mergeRanges)
128
    {
129
        return $this->mergeRanges = $mergeRanges;
130
    }
131
}
132