1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\Common\Entity; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Writer\Common\Entity\Style\Style; |
6
|
|
|
use Box\Spout\Writer\Common\Helper\CellHelper; |
7
|
|
|
use Box\Spout\Writer\Common\Manager\Style\StyleMerger; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Cell |
11
|
|
|
*/ |
12
|
|
|
class Cell |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Numeric cell type (whole numbers, fractional numbers, dates) |
16
|
|
|
*/ |
17
|
|
|
const TYPE_NUMERIC = 0; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* String (text) cell type |
21
|
|
|
*/ |
22
|
|
|
const TYPE_STRING = 1; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Formula cell type |
26
|
|
|
* Not used at the moment |
27
|
|
|
*/ |
28
|
|
|
const TYPE_FORMULA = 2; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Empty cell type |
32
|
|
|
*/ |
33
|
|
|
const TYPE_EMPTY = 3; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Boolean cell type |
37
|
|
|
*/ |
38
|
|
|
const TYPE_BOOLEAN = 4; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Error cell type |
42
|
|
|
*/ |
43
|
|
|
const TYPE_ERROR = 5; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The value of this cell |
47
|
|
|
* @var mixed|null |
48
|
|
|
*/ |
49
|
|
|
protected $value; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* The cell type |
53
|
|
|
* @var int|null |
54
|
|
|
*/ |
55
|
|
|
protected $type; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* The cell style |
59
|
|
|
* @var Style|null |
60
|
|
|
*/ |
61
|
|
|
protected $style; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var StyleMerger |
65
|
|
|
*/ |
66
|
|
|
protected $styleMerger; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Cell constructor. |
70
|
|
|
* @param $value mixed |
71
|
|
|
* @param $style|null Style |
72
|
|
|
*/ |
73
|
97 |
|
public function __construct($value, Style $style = null) |
74
|
|
|
{ |
75
|
97 |
|
$this->setValue($value); |
76
|
97 |
|
$this->setStyle($style); |
77
|
97 |
|
$this->styleMerger = new StyleMerger(); |
78
|
97 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param $value mixed|null |
82
|
|
|
*/ |
83
|
97 |
|
public function setValue($value) |
84
|
|
|
{ |
85
|
97 |
|
$this->value = $value; |
86
|
97 |
|
$this->type = $this->detectType($value); |
87
|
97 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return mixed|null |
91
|
|
|
*/ |
92
|
94 |
|
public function getValue() |
93
|
|
|
{ |
94
|
94 |
|
return $this->value; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param Style $style|null |
|
|
|
|
99
|
|
|
*/ |
100
|
97 |
|
public function setStyle(Style $style = null) |
101
|
|
|
{ |
102
|
97 |
|
$this->style = $style; |
103
|
97 |
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return Style|null |
107
|
|
|
*/ |
108
|
63 |
|
public function getStyle() |
109
|
|
|
{ |
110
|
63 |
|
if (!isset($this->style)) { |
111
|
62 |
|
$this->setStyle(new Style()); |
112
|
|
|
} |
113
|
|
|
|
114
|
63 |
|
return $this->style; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return int|null |
119
|
|
|
*/ |
120
|
|
|
public function getType() |
121
|
|
|
{ |
122
|
|
|
return $this->type; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get the current value type |
127
|
|
|
* @param mixed|null $value |
128
|
|
|
* @return int |
129
|
|
|
*/ |
130
|
97 |
|
protected function detectType($value) |
131
|
|
|
{ |
132
|
97 |
|
if (CellHelper::isBoolean($value)) { |
133
|
6 |
|
return self::TYPE_BOOLEAN; |
134
|
|
|
} |
135
|
95 |
|
if (CellHelper::isEmpty($value)) { |
136
|
8 |
|
return self::TYPE_EMPTY; |
137
|
|
|
} |
138
|
92 |
|
if (CellHelper::isNumeric($this->getValue())) { |
139
|
7 |
|
return self::TYPE_NUMERIC; |
140
|
|
|
} |
141
|
90 |
|
if (CellHelper::isNonEmptyString($value)) { |
142
|
87 |
|
return self::TYPE_STRING; |
143
|
|
|
} |
144
|
|
|
|
145
|
4 |
|
return self::TYPE_ERROR; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return bool |
150
|
|
|
*/ |
151
|
11 |
|
public function isBoolean() |
152
|
|
|
{ |
153
|
11 |
|
return $this->type === self::TYPE_BOOLEAN; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return bool |
158
|
|
|
*/ |
159
|
30 |
|
public function isEmpty() |
160
|
|
|
{ |
161
|
30 |
|
return $this->type === self::TYPE_EMPTY; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Not used at the moment |
166
|
|
|
* @return bool |
167
|
|
|
*/ |
168
|
|
|
public function isFormula() |
169
|
|
|
{ |
170
|
|
|
return $this->type === self::TYPE_FORMULA; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @return bool |
175
|
|
|
*/ |
176
|
10 |
|
public function isNumeric() |
177
|
|
|
{ |
178
|
10 |
|
return $this->type === self::TYPE_NUMERIC; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return bool |
183
|
|
|
*/ |
184
|
64 |
|
public function isString() |
185
|
|
|
{ |
186
|
64 |
|
return $this->type === self::TYPE_STRING; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @return bool |
191
|
|
|
*/ |
192
|
1 |
|
public function isError() |
193
|
|
|
{ |
194
|
1 |
|
return $this->type === self::TYPE_ERROR; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return string |
199
|
|
|
*/ |
200
|
8 |
|
public function __toString() |
201
|
|
|
{ |
202
|
8 |
|
return (string) $this->value; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @param Style $style|null |
|
|
|
|
207
|
|
|
* @return Cell |
208
|
|
|
*/ |
209
|
61 |
|
public function applyStyle(Style $style = null) |
210
|
|
|
{ |
211
|
61 |
|
if ($style === null) { |
212
|
|
|
return $this; |
213
|
|
|
} |
214
|
61 |
|
$mergedStyle = $this->styleMerger->merge($this->getStyle(), $style); |
|
|
|
|
215
|
61 |
|
$this->setStyle($mergedStyle); |
216
|
|
|
|
217
|
61 |
|
return $this; |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.