|
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 CELL_TYPE_NUMERIC = 0; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* String (text) cell type |
|
16
|
|
|
*/ |
|
17
|
|
|
const CELL_TYPE_STRING = 1; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Formula cell type |
|
21
|
|
|
*/ |
|
22
|
|
|
const CELL_TYPE_FORMULA = 2; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Blank cell type |
|
26
|
|
|
*/ |
|
27
|
|
|
const CELL_TYPE_BLANK = 3; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Boolean cell type |
|
31
|
|
|
*/ |
|
32
|
|
|
const CELL_TYPE_BOOLEAN = 4; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Error cell type |
|
36
|
|
|
*/ |
|
37
|
|
|
const CELL_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
|
|
|
public function __construct($value) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->setValue($value); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param $value mixed |
|
63
|
|
|
*/ |
|
64
|
|
|
public function setValue($value) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->value = $value; |
|
67
|
|
|
$this->type = $this->detectType($value); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return mixed|null |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getValue() |
|
74
|
|
|
{ |
|
75
|
|
|
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
|
|
|
protected function detectType($value) |
|
91
|
|
|
{ |
|
92
|
|
|
if (CellHelper::isBoolean($value)) { |
|
93
|
|
|
return self::CELL_TYPE_BOOLEAN; |
|
94
|
|
|
} elseif (CellHelper::isEmpty($value)) { |
|
95
|
|
|
return self::CELL_TYPE_BLANK; |
|
96
|
|
|
} elseif (CellHelper::isNumeric($this->getValue())) { |
|
97
|
|
|
return self::CELL_TYPE_NUMERIC; |
|
98
|
|
|
} elseif (CellHelper::isNonEmptyString($value)) { |
|
99
|
|
|
return self::CELL_TYPE_STRING; |
|
100
|
|
|
} else { |
|
101
|
|
|
return self::CELL_TYPE_ERROR; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return bool |
|
107
|
|
|
*/ |
|
108
|
|
|
public function isBoolean() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->type === self::CELL_TYPE_BOOLEAN; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return bool |
|
115
|
|
|
*/ |
|
116
|
|
|
public function isBlank() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->type === self::CELL_TYPE_BLANK; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return bool |
|
123
|
|
|
*/ |
|
124
|
|
|
public function isNumeric() |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->type === self::CELL_TYPE_NUMERIC; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return bool |
|
131
|
|
|
*/ |
|
132
|
|
|
public function isString() |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->type === self::CELL_TYPE_STRING; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return bool |
|
139
|
|
|
*/ |
|
140
|
|
|
public function isError() |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->type === self::CELL_TYPE_ERROR; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @return string |
|
147
|
|
|
*/ |
|
148
|
|
|
public function __toString() |
|
149
|
|
|
{ |
|
150
|
|
|
return (string)$this->value; |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|
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..