public function getDocument()
{
if ($this->errors !== null) {
return [self::KEYWORD_ERRORS => $this->errors];
}
$document = array_filter([self::KEYWORD_JSON_API => $this->version, self::KEYWORD_META => $this->meta, self::KEYWORD_LINKS => $this->links, self::KEYWORD_DATA => true, self::KEYWORD_INCLUDED => empty($this->included) === true ? null : array_values($this->included)], function ($value) {
return $value !== null;
});
if ($this->showData === true) {
$isDataNotArray = $this->isDataArrayed === false && empty($this->data) === false;
$document[self::KEYWORD_DATA] = $isDataNotArray ? $this->data[0] : $this->data;
} else {
unset($document[self::KEYWORD_DATA]);
}
return $document;
}