Passed
Push — master ( dcb10e...d87ef3 )
by Adrien
12:23
created

SheetView::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Worksheet;
4
5
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
6
7
class SheetView
8
{
9
    // Sheet View types
10
    const SHEETVIEW_NORMAL = 'normal';
11
    const SHEETVIEW_PAGE_LAYOUT = 'pageLayout';
12
    const SHEETVIEW_PAGE_BREAK_PREVIEW = 'pageBreakPreview';
13
14
    private const SHEET_VIEW_TYPES = [
15
        self::SHEETVIEW_NORMAL,
16
        self::SHEETVIEW_PAGE_LAYOUT,
17
        self::SHEETVIEW_PAGE_BREAK_PREVIEW,
18
    ];
19
20
    /**
21
     * ZoomScale.
22
     *
23
     * Valid values range from 10 to 400.
24
     *
25
     * @var ?int
26
     */
27
    private $zoomScale = 100;
28
29
    /**
30
     * ZoomScaleNormal.
31
     *
32
     * Valid values range from 10 to 400.
33
     *
34
     * @var ?int
35
     */
36
    private $zoomScaleNormal = 100;
37
38
    /**
39
     * ShowZeros.
40
     *
41
     * If true, "null" values from a calculation will be shown as "0". This is the default Excel behaviour and can be changed
42
     * with the advanced worksheet option "Show a zero in cells that have zero value"
43
     *
44
     * @var bool
45
     */
46
    private $showZeros = true;
47
48
    /**
49
     * View.
50
     *
51
     * Valid values range from 10 to 400.
52
     *
53
     * @var string
54
     */
55
    private $sheetviewType = self::SHEETVIEW_NORMAL;
56
57
    /**
58
     * Create a new SheetView.
59
     */
60 9862
    public function __construct()
61
    {
62 9862
    }
63
64
    /**
65
     * Get ZoomScale.
66
     *
67
     * @return ?int
68
     */
69 315
    public function getZoomScale()
70
    {
71 315
        return $this->zoomScale;
72
    }
73
74
    /**
75
     * Set ZoomScale.
76
     * Valid values range from 10 to 400.
77
     *
78
     * @param ?int $zoomScale
79
     *
80
     * @return $this
81
     */
82 88
    public function setZoomScale($zoomScale)
83
    {
84
        // Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
85
        // but it is apparently still able to handle any scale >= 1
86 88
        if ($zoomScale === null || $zoomScale >= 1) {
87 88
            $this->zoomScale = $zoomScale;
88
        } else {
89
            throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.');
90
        }
91
92 88
        return $this;
93
    }
94
95
    /**
96
     * Get ZoomScaleNormal.
97
     *
98
     * @return ?int
99
     */
100 315
    public function getZoomScaleNormal()
101
    {
102 315
        return $this->zoomScaleNormal;
103
    }
104
105
    /**
106
     * Set ZoomScale.
107
     * Valid values range from 10 to 400.
108
     *
109
     * @param ?int $zoomScaleNormal
110
     *
111
     * @return $this
112
     */
113 90
    public function setZoomScaleNormal($zoomScaleNormal)
114
    {
115 90
        if ($zoomScaleNormal === null || $zoomScaleNormal >= 1) {
116 90
            $this->zoomScaleNormal = $zoomScaleNormal;
117
        } else {
118
            throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.');
119
        }
120
121 90
        return $this;
122
    }
123
124
    /**
125
     * Set ShowZeroes setting.
126
     *
127
     * @param bool $showZeros
128
     */
129 7
    public function setShowZeros($showZeros): void
130
    {
131 7
        $this->showZeros = $showZeros;
132
    }
133
134
    /**
135
     * @return bool
136
     */
137 288
    public function getShowZeros()
138
    {
139 288
        return $this->showZeros;
140
    }
141
142
    /**
143
     * Get View.
144
     *
145
     * @return string
146
     */
147 354
    public function getView()
148
    {
149 354
        return $this->sheetviewType;
150
    }
151
152
    /**
153
     * Set View.
154
     *
155
     * Valid values are
156
     *        'normal'            self::SHEETVIEW_NORMAL
157
     *        'pageLayout'        self::SHEETVIEW_PAGE_LAYOUT
158
     *        'pageBreakPreview'  self::SHEETVIEW_PAGE_BREAK_PREVIEW
159
     *
160
     * @param ?string $sheetViewType
161
     *
162
     * @return $this
163
     */
164 86
    public function setView($sheetViewType)
165
    {
166
        // MS Excel 2007 allows setting the view to 'normal', 'pageLayout' or 'pageBreakPreview' via the user interface
167 86
        if ($sheetViewType === null) {
168
            $sheetViewType = self::SHEETVIEW_NORMAL;
169
        }
170 86
        if (in_array($sheetViewType, self::SHEET_VIEW_TYPES)) {
171 86
            $this->sheetviewType = $sheetViewType;
172
        } else {
173
            throw new PhpSpreadsheetException('Invalid sheetview layout type.');
174
        }
175
176 86
        return $this;
177
    }
178
179
    /**
180
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
181
     */
182
    public function __clone()
183
    {
184
        $vars = get_object_vars($this);
185
        foreach ($vars as $key => $value) {
186
            if (is_object($value)) {
187
                $this->$key = clone $value;
188
            } else {
189
                $this->$key = $value;
190
            }
191
        }
192
    }
193
}
194