Test Failed
Push — develop ( 90366f...812a46 )
by Adrien
28:16
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 static $sheetViewTypes = [
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
     * View.
40
     *
41
     * Valid values range from 10 to 400.
42
     *
43
     * @var string
44
     */
45
    private $sheetviewType = self::SHEETVIEW_NORMAL;
46
47
    /**
48
     * Create a new SheetView.
49
     */
50 153
    public function __construct()
51
    {
52 153
    }
53
54
    /**
55
     * Get ZoomScale.
56
     *
57
     * @return int
58
     */
59 58
    public function getZoomScale()
60
    {
61 58
        return $this->zoomScale;
62
    }
63
64
    /**
65
     * Set ZoomScale.
66
     * Valid values range from 10 to 400.
67
     *
68
     * @param int $pValue
69
     *
70
     * @throws PhpSpreadsheetException
71
     *
72
     * @return SheetView
73
     */
74 18
    public function setZoomScale($pValue)
75
    {
76
        // Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
77
        // but it is apparently still able to handle any scale >= 1
78 18
        if (($pValue >= 1) || $pValue === null) {
79 18
            $this->zoomScale = $pValue;
80
        } else {
81
            throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.');
82
        }
83
84 18
        return $this;
85
    }
86
87
    /**
88
     * Get ZoomScaleNormal.
89
     *
90
     * @return int
91
     */
92 58
    public function getZoomScaleNormal()
93
    {
94 58
        return $this->zoomScaleNormal;
95
    }
96
97
    /**
98
     * Set ZoomScale.
99
     * Valid values range from 10 to 400.
100
     *
101
     * @param int $pValue
102
     *
103
     * @throws PhpSpreadsheetException
104
     *
105
     * @return SheetView
106
     */
107 18
    public function setZoomScaleNormal($pValue)
108
    {
109 18
        if (($pValue >= 1) || $pValue === null) {
110 18
            $this->zoomScaleNormal = $pValue;
111
        } else {
112
            throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.');
113
        }
114
115 18
        return $this;
116
    }
117
118
    /**
119
     * Get View.
120
     *
121
     * @return string
122
     */
123 72
    public function getView()
124
    {
125 72
        return $this->sheetviewType;
126
    }
127
128
    /**
129
     * Set View.
130
     *
131
     * Valid values are
132
     *        'normal'            self::SHEETVIEW_NORMAL
133
     *        'pageLayout'        self::SHEETVIEW_PAGE_LAYOUT
134
     *        'pageBreakPreview'  self::SHEETVIEW_PAGE_BREAK_PREVIEW
135
     *
136
     * @param string $pValue
137
     *
138
     * @throws PhpSpreadsheetException
139
     *
140
     * @return SheetView
141
     */
142 19
    public function setView($pValue)
143
    {
144
        // MS Excel 2007 allows setting the view to 'normal', 'pageLayout' or 'pageBreakPreview' via the user interface
145 19
        if ($pValue === null) {
146
            $pValue = self::SHEETVIEW_NORMAL;
147
        }
148 19
        if (in_array($pValue, self::$sheetViewTypes)) {
149 19
            $this->sheetviewType = $pValue;
150
        } else {
151
            throw new PhpSpreadsheetException('Invalid sheetview layout type.');
152
        }
153
154 19
        return $this;
155
    }
156
157
    /**
158
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
159
     */
160 View Code Duplication
    public function __clone()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
161
    {
162
        $vars = get_object_vars($this);
163
        foreach ($vars as $key => $value) {
164
            if (is_object($value)) {
165
                $this->$key = clone $value;
166
            } else {
167
                $this->$key = $value;
168
            }
169
        }
170
    }
171
}
172