Skip to content

Commit

Permalink
feat: add caption in file blocks (#37)
Browse files Browse the repository at this point in the history
* feat: add caption in file blocks

* chore: coding style
  • Loading branch information
brd6 committed Mar 9, 2024
1 parent add38da commit 740f3b1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
6 changes: 0 additions & 6 deletions src/RequestParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public function setMethod(string $method): self
return $this;
}

/**
* @return array
*/
public function getQuery(): array
{
return $this->query;
Expand All @@ -55,9 +52,6 @@ public function setQuery(array $query): self
return $this;
}

/**
* @return array
*/
public function getBody(): array
{
return $this->body;
Expand Down
3 changes: 0 additions & 3 deletions src/Resource/AbstractResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ abstract protected function initialize(): void;

abstract public static function getResourceType(): string;

/**
* @return array
*/
public function getRawData(): array
{
return $this->rawData;
Expand Down
2 changes: 0 additions & 2 deletions src/Resource/Block/AbstractBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ protected function getProperty(): ?AbstractProperty
}

/**
* @return array
*
* @psalm-suppress PossiblyNullReference
*/
public function propertyToArray(): array
Expand Down
29 changes: 29 additions & 0 deletions src/Resource/File/AbstractFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@
use Brd6\NotionSdkPhp\Exception\InvalidFileException;
use Brd6\NotionSdkPhp\Exception\UnsupportedFileTypeException;
use Brd6\NotionSdkPhp\Resource\AbstractJsonSerializable;
use Brd6\NotionSdkPhp\Resource\RichText\AbstractRichText;
use Brd6\NotionSdkPhp\Util\StringHelper;

use function array_map;
use function class_exists;

abstract class AbstractFile extends AbstractJsonSerializable
{
private array $rawData = [];
protected string $type = '';

/**
* @var array|AbstractRichText[]
*/
protected array $caption = [];

public function __construct()
{
$this->type = static::getFileType();
Expand Down Expand Up @@ -48,6 +55,10 @@ protected function setRawData(array $rawData): self
$this->rawData = $rawData;

$this->type = (string) ($this->rawData['type'] ?? '');
$this->caption = isset($this->rawData['caption']) ? array_map(
fn (array $richTextRawData) => AbstractRichText::fromRawData($richTextRawData),
(array) $this->rawData['caption'],
) : [];

return $this;
}
Expand Down Expand Up @@ -90,4 +101,22 @@ public function setType(string $type): self

return $this;
}

/**
* @return array|AbstractRichText[]
*/
public function getCaption(): array
{
return $this->caption;
}

/**
* @param array|AbstractRichText[] $caption
*/
public function setCaption(array $caption): self
{
$this->caption = $caption;

return $this;
}
}
3 changes: 0 additions & 3 deletions src/Resource/RichText/AbstractRichText.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ protected static function getMapClassFromType(string $type): string

abstract protected function initialize(): void;

/**
* @return array
*/
public function getRawData(): array
{
return $this->rawData;
Expand Down

0 comments on commit 740f3b1

Please sign in to comment.