1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\Common; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Writer\Common\Helper\CellHelper; |
6
|
|
|
|
7
|
|
|
class Cell |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Numeric cell type (whole numbers, fractional numbers, dates) |
11
|
|
|
*/ |
12
|
|
|
const TYPE_NUMERIC = 0; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* String (text) cell type |
16
|
|
|
*/ |
17
|
|
|
const TYPE_STRING = 1; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Formula cell type |
21
|
|
|
*/ |
22
|
|
|
const TYPE_FORMULA = 2; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Blank cell type |
26
|
|
|
*/ |
27
|
|
|
const TYPE_BLANK = 3; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Boolean cell type |
31
|
|
|
*/ |
32
|
|
|
const TYPE_BOOLEAN = 4; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Error cell type |
36
|
|
|
*/ |
37
|
|
|
const TYPE_ERROR = 5; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The value of this cell |
41
|
|
|
* @var null | mixed |
42
|
|
|
*/ |
43
|
|
|
protected $value = null; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The cell type |
47
|
|
|
* @var null |
48
|
|
|
*/ |
49
|
|
|
protected $type = null; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Cell constructor. |
53
|
|
|
* @param $value mixed |
54
|
|
|
* @param $comment string |
55
|
|
|
*/ |
56
|
192 |
|
public function __construct($value) |
57
|
|
|
{ |
58
|
192 |
|
$this->setValue($value); |
59
|
192 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param $value mixed |
63
|
|
|
*/ |
64
|
192 |
|
public function setValue($value) |
65
|
|
|
{ |
66
|
192 |
|
$this->value = $value; |
67
|
192 |
|
$this->type = $this->detectType($value); |
|
|
|
|
68
|
192 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return mixed|null |
72
|
|
|
*/ |
73
|
189 |
|
public function getValue() |
74
|
|
|
{ |
75
|
189 |
|
return $this->value; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return mixed|null |
80
|
|
|
*/ |
81
|
|
|
public function getType() |
82
|
|
|
{ |
83
|
|
|
return $this->type; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get the current value type |
88
|
|
|
* @return int |
89
|
|
|
*/ |
90
|
192 |
|
protected function detectType($value) |
91
|
|
|
{ |
92
|
192 |
|
if (CellHelper::isBoolean($value)) { |
93
|
15 |
|
return self::TYPE_BOOLEAN; |
94
|
189 |
|
} elseif (CellHelper::isEmpty($value)) { |
95
|
12 |
|
return self::TYPE_BLANK; |
96
|
186 |
|
} elseif (CellHelper::isNumeric($this->getValue())) { |
97
|
18 |
|
return self::TYPE_NUMERIC; |
98
|
183 |
|
} elseif (CellHelper::isNonEmptyString($value)) { |
99
|
177 |
|
return self::TYPE_STRING; |
100
|
|
|
} else { |
101
|
12 |
|
return self::TYPE_ERROR; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
36 |
|
public function isBoolean() |
109
|
|
|
{ |
110
|
36 |
|
return $this->type === self::TYPE_BOOLEAN; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return bool |
115
|
|
|
*/ |
116
|
24 |
|
public function isBlank() |
117
|
|
|
{ |
118
|
24 |
|
return $this->type === self::TYPE_BLANK; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return bool |
123
|
|
|
*/ |
124
|
|
|
public function isFormula() |
125
|
|
|
{ |
126
|
|
|
return $this->type === self::TYPE_FORMULA; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return bool |
131
|
|
|
*/ |
132
|
33 |
|
public function isNumeric() |
133
|
|
|
{ |
134
|
33 |
|
return $this->type === self::TYPE_NUMERIC; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return bool |
139
|
|
|
*/ |
140
|
189 |
|
public function isString() |
141
|
|
|
{ |
142
|
189 |
|
return $this->type === self::TYPE_STRING; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return bool |
147
|
|
|
*/ |
148
|
|
|
public function isError() |
149
|
|
|
{ |
150
|
|
|
return $this->type === self::TYPE_ERROR; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return string |
155
|
|
|
*/ |
156
|
3 |
|
public function __toString() |
157
|
|
|
{ |
158
|
3 |
|
return (string)$this->value; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..