Skip to content

Commit

Permalink
Unify constructor method names (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariosimao authored Nov 1, 2022
1 parent f5a22dc commit 5290088
Show file tree
Hide file tree
Showing 64 changed files with 330 additions and 292 deletions.
2 changes: 1 addition & 1 deletion src/Blocks/Bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private function __construct(
/**
* Create a bookmark from a URL
*/
public static function create(string $url): self
public static function fromUrl(string $url): self
{
$metadata = BlockMetadata::create(BlockType::Bookmark);

Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BulletedListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static function create(): self
public static function fromString(string $content): self
{
$metadata = BlockMetadata::create(BlockType::BulletedListItem);
$text = [ RichText::createText($content) ];
$text = [ RichText::fromString($content) ];

return new self($metadata, $text, []);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Blocks/Callout.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ private function __construct(
public static function create(): self
{
$metadata = BlockMetadata::create(BlockType::Callout);
$icon = Icon::fromEmoji(Emoji::create(""));
$icon = Icon::fromEmoji(Emoji::fromString(""));

return new self($metadata, [], $icon, []);
}

public static function fromString(string $emoji, string $content): self
{
$metadata = BlockMetadata::create(BlockType::Callout);
$text = [ RichText::createText($content) ];
$icon = Icon::fromEmoji(Emoji::create($emoji));
$text = [ RichText::fromString($content) ];
$icon = Icon::fromEmoji(Emoji::fromString($emoji));

return new self($metadata, $text, $icon, []);
}
Expand Down
13 changes: 9 additions & 4 deletions src/Blocks/Code.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,27 @@ private function __construct(
$metadata->checkType(BlockType::Code);
}

public static function create(): self
{
return self::fromText([]);
}

/** @param RichText[] $text */
public static function create(
array $text = [],
public static function fromText(
array $text,
CodeLanguage $language = CodeLanguage::PlainText,
): self {
$metadata = BlockMetadata::create(BlockType::Code);

return new self($metadata, $text, $language, []);
}

public static function createFromString(
public static function fromString(
string $code,
CodeLanguage $language = CodeLanguage::PlainText,
): self {
$metadata = BlockMetadata::create(BlockType::Code);
$text = [ RichText::createText($code) ];
$text = [ RichText::fromString($code) ];

return new self($metadata, $text, $language, []);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private function __construct(
$metadata->checkType(BlockType::Embed);
}

public static function create(string $url = ""): self
public static function fromUrl(string $url = ""): self
{
$metadata = BlockMetadata::create(BlockType::Embed);

Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/EquationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ private function __construct(
$metadata->checkType(BlockType::Equation);
}

public static function create(string $expression = ""): self
public static function fromString(string $expression = ""): self
{
$block = BlockMetadata::create(BlockType::Equation);
$equation = Equation::create($expression);
$equation = Equation::fromString($expression);

return new self($block, $equation);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/FileBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private function __construct(
$metadata->checkType(BlockType::File);
}

public static function create(File $file): self
public static function fromFile(File $file): self
{
$metadata = BlockMetadata::create(BlockType::File);

Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/Heading1.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private function __construct(
$metadata->checkType(BlockType::Heading1);
}

public static function create(RichText ...$text): self
public static function fromText(RichText ...$text): self
{
$block = BlockMetadata::create(BlockType::Heading1);

Expand All @@ -45,7 +45,7 @@ public static function create(RichText ...$text): self
public static function fromString(string $content): self
{
$block = BlockMetadata::create(BlockType::Heading1);
$text = [ RichText::createText($content) ];
$text = [ RichText::fromString($content) ];

return new self($block, $text, false, []);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/Heading2.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private function __construct(
$metadata->checkType(BlockType::Heading2);
}

public static function create(RichText ...$text): self
public static function fromText(RichText ...$text): self
{
$block = BlockMetadata::create(BlockType::Heading2);

Expand All @@ -45,7 +45,7 @@ public static function create(RichText ...$text): self
public static function fromString(string $content): self
{
$block = BlockMetadata::create(BlockType::Heading2);
$text = [ RichText::createText($content) ];
$text = [ RichText::fromString($content) ];

return new self($block, $text, false, []);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/Heading3.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private function __construct(
$metadata->checkType(BlockType::Heading3);
}

public static function create(RichText ...$text): self
public static function fromText(RichText ...$text): self
{
$block = BlockMetadata::create(BlockType::Heading3);

Expand All @@ -45,7 +45,7 @@ public static function create(RichText ...$text): self
public static function fromString(string $content): self
{
$block = BlockMetadata::create(BlockType::Heading3);
$text = [ RichText::createText($content) ];
$text = [ RichText::fromString($content) ];

return new self($block, $text, false, []);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private function __construct(
$metadata->checkType(BlockType::Image);
}

public static function create(File $file): self
public static function fromFile(File $file): self
{
$block = BlockMetadata::create(BlockType::Image);

Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/NumberedListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function create(): self
public static function fromString(string $content): self
{
$block = BlockMetadata::create(BlockType::NumberedListItem);
$text = [ RichText::createText($content) ];
$text = [ RichText::fromString($content) ];

return new self($block, $text, []);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/Paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function create(): self
public static function fromString(string $content): self
{
$block = BlockMetadata::create(BlockType::Paragraph);
$text = [ RichText::createText($content) ];
$text = [ RichText::fromString($content) ];

return new self($block, $text, []);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private function __construct(
$metadata->checkType(BlockType::Pdf);
}

public static function create(File $file): self
public static function fromFile(File $file): self
{
$block = BlockMetadata::create(BlockType::Pdf);

Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function create(): self
public static function fromString(string $content): self
{
$block = BlockMetadata::create(BlockType::Quote);
$text = [ RichText::createText($content) ];
$text = [ RichText::fromString($content) ];

return new self($block, $text, []);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/ToDo.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function create(): self
public static function fromString(string $content): self
{
$block = BlockMetadata::create(BlockType::ToDo);
$text = [ RichText::createText($content) ];
$text = [ RichText::fromString($content) ];

return new self($block, $text, false, []);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/Toggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private function __construct(
$metadata->checkType(BlockType::Toggle);
}

public static function create(): self
public static function createEmpty(): self
{
$block = BlockMetadata::create(BlockType::Toggle);

Expand All @@ -41,7 +41,7 @@ public static function create(): self
public static function fromString(string $content): self
{
$block = BlockMetadata::create(BlockType::Toggle);
$text = [ RichText::createText($content) ];
$text = [ RichText::fromString($content) ];

return new self($block, $text, []);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private function __construct(
$metadata->checkType(BlockType::Video);
}

public static function create(File $file): self
public static function fromFile(File $file): self
{
$block = BlockMetadata::create(BlockType::Video);

Expand Down
2 changes: 1 addition & 1 deletion src/Common/Emoji.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private function __construct(
) {
}

public static function create(string $emoji): self
public static function fromString(string $emoji): self
{
return new self($emoji);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Equation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private function __construct(
) {
}

public static function create(string $expression): self
public static function fromString(string $expression): self
{
return new self($expression);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Common/Mention.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ private function __construct(
) {
}

public static function createPage(string $pageId): self
public static function page(string $pageId): self
{
return new self(MentionType::Page, $pageId, null, null, null);
}

public static function createDatabase(string $databaseId): self
public static function database(string $databaseId): self
{
return new self(MentionType::Database, null, $databaseId, null, null);
}

public static function createUser(User $user): self
public static function user(User $user): self
{
return new self(MentionType::User, null, null, $user, null);
}

public static function createDate(Date $date): self
public static function date(Date $date): self
{
return new self(MentionType::Date, null, null, null, $date);
}
Expand Down
36 changes: 21 additions & 15 deletions src/Common/RichText.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ private function __construct(
}

/** @psalm-mutation-free */
public static function createText(string $content): self
public static function fromString(string $content): self
{
$text = Text::create($content);
$text = Text::fromString($content);

return self::createFromText($text);
return self::fromText($text);
}

public static function createLink(string $content, string $url): self
{
$text = Text::create($content)->changeUrl($url);
$text = Text::fromString($content)->changeUrl($url);

return self::createFromText($text);
return self::fromText($text);
}

/** @psalm-mutation-free */
public static function createFromText(Text $text): self
public static function fromText(Text $text): self
{
$annotations = Annotations::create();

Expand All @@ -64,33 +64,39 @@ public static function createFromText(Text $text): self
);
}

public static function createEquation(string $expression): self
public static function fromEquation(Equation $equation): self
{
$equation = Equation::create($expression);
$annotations = Annotations::create();

return self::createFromEquation($equation);
return new self(
$equation->expression,
null,
$annotations,
RichTextType::Equation,
null,
null,
$equation
);
}

public static function createFromEquation(Equation $equation): self
public static function fromMention(Mention $mention): self
{
$annotations = Annotations::create();

return new self(
$equation->expression,
"",
null,
$annotations,
RichTextType::Equation,
null,
$mention,
null,
$equation
);
}

public static function newLine(): self
{
$text = Text::create("\n");

return self::createFromText($text);
return self::fromString("\n");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private function __construct(
}

/** @psalm-mutation-free */
public static function create(string $content): self
public static function fromString(string $content): self
{
return new self($content, null);
}
Expand Down
Loading

0 comments on commit 5290088

Please sign in to comment.