setValue($value); $this->setStyle($style); } /** * @return string */ public function __toString() { return (string) $this->getValue(); } /** * @param null|mixed $value */ public function setValue($value) { $this->value = $value; $this->type = $this->detectType($value); } /** * @return null|mixed */ public function getValue() { return !$this->isError() ? $this->value : null; } /** * @return mixed */ public function getValueEvenIfError() { return $this->value; } /** * @param null|Style $style */ public function setStyle($style) { $this->style = $style ?: new Style(); } /** * @return Style */ public function getStyle() { return $this->style; } /** * @return null|int */ public function getType() { return $this->type; } /** * @param int $type */ public function setType($type) { $this->type = $type; } /** * @return bool */ public function isBoolean() { return self::TYPE_BOOLEAN === $this->type; } /** * @return bool */ public function isEmpty() { return self::TYPE_EMPTY === $this->type; } /** * @return bool */ public function isNumeric() { return self::TYPE_NUMERIC === $this->type; } /** * @return bool */ public function isString() { return self::TYPE_STRING === $this->type; } /** * @return bool */ public function isDate() { return self::TYPE_DATE === $this->type; } /** * @return bool */ public function isFormula() { return self::TYPE_FORMULA === $this->type; } /** * @return bool */ public function isError() { return self::TYPE_ERROR === $this->type; } /** * Get the current value type. * * @param null|mixed $value * * @return int */ protected function detectType($value) { if (CellTypeHelper::isBoolean($value)) { return self::TYPE_BOOLEAN; } if (CellTypeHelper::isEmpty($value)) { return self::TYPE_EMPTY; } if (CellTypeHelper::isNumeric($value)) { return self::TYPE_NUMERIC; } if (CellTypeHelper::isDateTimeOrDateInterval($value)) { return self::TYPE_DATE; } if (CellTypeHelper::isFormula($value)) { return self::TYPE_FORMULA; } if (CellTypeHelper::isNonEmptyString($value)) { return self::TYPE_STRING; } return self::TYPE_ERROR; } }