Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CreateEmpty method for Page Properties #346

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Pages/Properties/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public static function createUnchecked(): self
return new self($property, false);
}

public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create($id ?? "", PropertyType::Checkbox);

return new self($property, false);
}

public static function fromArray(array $array): self
{
/** @psalm-var CheckboxJson $array */
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Properties/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public static function createRange(DateTimeImmutable $start, DateTimeImmutable $
return new self($property, CommonDate::createRange($start, $end));
}

public static function createEmpty(): self
public static function createEmpty(string $id = null): self
{
$metadata = PropertyMetadata::create("", PropertyType::Date);
$metadata = PropertyMetadata::create($id ?? "", PropertyType::Date);

return new self($metadata, null);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Properties/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static function create(string $email): self
return new self($property, $email);
}

public static function createEmpty(): self
public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create("", PropertyType::Email);
$property = PropertyMetadata::create($id ?? "", PropertyType::Email);

return new self($property, null);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/Properties/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public static function create(File ...$files): self
return new self($property, $files);
}

public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create($id ?? "", PropertyType::Files);

return new self($property, []);
}

public static function fromArray(array $array): self
{
/** @psalm-var FilesJson $array */
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/Properties/MultiSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ private function __construct(
) {
}

public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create($id ?? "", PropertyType::MultiSelect);

return new self($property, []);
}

public static function fromIds(string ...$ids): self
{
$metadata = PropertyMetadata::create("", PropertyType::MultiSelect);
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Properties/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static function create(int|float $number): self
return new self($property, $number);
}

public static function createEmpty(): self
public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create("", PropertyType::Number);
$property = PropertyMetadata::create($id ?? "", PropertyType::Number);

return new self($property, null);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/Properties/People.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public static function create(User ...$users): self
return new self($property, $users);
}

public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create($id ?? "", PropertyType::People);

return new self($property, []);
}

public static function fromArray(array $array): self
{
/** @psalm-var PeopleJson $array */
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Properties/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static function create(string $phone): self
return new self($property, $phone);
}

public static function createEmpty(): self
public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create("", PropertyType::PhoneNumber);
$property = PropertyMetadata::create($id ?? "", PropertyType::PhoneNumber);

return new self($property, null);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/Properties/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public static function create(string ...$pageIds): self
return new self($property, $pageIds);
}

public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create($id ?? "", PropertyType::Relation);

return new self($property, []);
}

public static function fromArray(array $array): self
{
/** @psalm-var RelationJson $array */
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Properties/RichTextProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public static function fromString(string $text): self
return new self($metadata, $texts);
}

public static function createEmpty(): self
public static function createEmpty(string $id = null): self
{
$metadata = PropertyMetadata::create("", PropertyType::RichText);
$metadata = PropertyMetadata::create($id ?? "", PropertyType::RichText);

return new self($metadata, []);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Properties/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public static function fromOption(SelectOption $option): self
return new self($metadata, $option);
}

public static function createEmpty(): self
public static function createEmpty(string $id = null): self
{
$metadata = PropertyMetadata::create("", PropertyType::Select);
$metadata = PropertyMetadata::create($id ?? "", PropertyType::Select);

return new self($metadata, null);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/Properties/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ private function __construct(
) {
}

public static function createEmpty(string $id = null): self
{
$property = PropertyMetadata::create($id ?? "", PropertyType::Status);

return new self($property, null);
}

public static function fromId(string $id): self
{
$metadata = PropertyMetadata::create("", PropertyType::Status);
Expand Down
7 changes: 7 additions & 0 deletions src/Pages/Properties/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ private function __construct(
) {
}

public static function createEmpty(): self
{
$property = PropertyMetadata::create("title", PropertyType::Title);

return new self($property, []);
}

/** @psalm-mutation-free */
public static function fromText(RichText ...$title): self
{
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Properties/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static function create(string $url): self
return new self($metadata, $url);
}

public static function createEmpty(): self
public static function createEmpty(string $id = null): self
{
$metadata = PropertyMetadata::create("", PropertyType::Url);
$metadata = PropertyMetadata::create($id ?? "", PropertyType::Url);

return new self($metadata, null);
}
Expand Down