Skip to content

Commit

Permalink
Merge branch 'release/v0.16.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Feb 20, 2025
2 parents 0f8a43e + 6c4a116 commit 4e4ee24
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.16.3 (2025-02-19)
* Upgraded Coercion dependency

## v0.16.2 (2025-02-19)
* Accept Generators in list factories

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"ext-intl": "*",
"symfony/polyfill-mbstring": "^1.31",

"decodelabs/coercion": "^0.2.15",
"decodelabs/coercion": "^0.3",
"decodelabs/collections": "^0.10.4",
"decodelabs/cosmos": "^0.2.1",
"decodelabs/elementary": "^0.4.4",
Expand Down
2 changes: 1 addition & 1 deletion src/Tagged/Asset/InlineScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function setType(
*/
public function getType(): string
{
return Coercion::toString(
return Coercion::asString(
$this->getAttribute('type') ?? 'text/javascript'
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Tagged/Asset/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function setHref(
*/
public function getHref(): string
{
return Coercion::toString(
return Coercion::asString(
$this->getAttribute('href')
);
}
Expand All @@ -71,7 +71,7 @@ public function setRel(
*/
public function getRel(): string
{
return Coercion::toString(
return Coercion::asString(
$this->getAttribute('rel') ?? 'stylesheet'
);
}
Expand All @@ -90,7 +90,7 @@ public function setType(
*/
public function getType(): ?string
{
return Coercion::toStringOrNull(
return Coercion::tryString(
$this->getAttribute('type')
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Tagged/Asset/RemoteScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function setSrc(
*/
public function getSrc(): string
{
return Coercion::toString(
return Coercion::asString(
$this->getAttribute('src')
);
}
Expand Down Expand Up @@ -104,7 +104,7 @@ public function setType(
*/
public function getType(): string
{
return Coercion::toString(
return Coercion::asString(
$this->getAttribute('type') ?? 'text/javascript'
);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Tagged/Embed/Audioboom.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ protected function setUrl(
$booId === 'playlist'
) {
$this->type = 'playlist';
$this->audioboomId = Coercion::toString($query['data_for_content_type']);
$this->audioboomId = Coercion::asString($query['data_for_content_type']);
} else {
$this->type = 'embed';
$this->audioboomId = (string)$booId;

foreach ((array)$query as $key => $value) {
if (in_array(strtolower((string)$key), self::QueryVars)) {
$this->options[(string)$key] = Coercion::forceString($value);
$this->options[(string)$key] = Coercion::toString($value);
}
}
}
Expand Down Expand Up @@ -153,7 +153,7 @@ public function lookupThumbnail(
}

/** @var array<string, mixed> $json */
return Coercion::toStringOrNull($json['thumbnail_url'] ?? null);
return Coercion::tryString($json['thumbnail_url'] ?? null);
}

/**
Expand Down Expand Up @@ -211,7 +211,7 @@ protected function lookupEmbedMeta(
'uploadDate' =>
isset($json['upload_date']) ?
new DateTime()->setTimestamp(
Coercion::toInt($json['upload_date'])
Coercion::asInt($json['upload_date'])
) :
null,
'description' => $json['description'],
Expand Down Expand Up @@ -250,8 +250,8 @@ protected function lookupPlaylistMeta(
$uploadTs = $uploadDate = $user = $profileUrl = null;

foreach ($playlist->memberships as $item) {
$duration += Coercion::toInt($item->audio_clip['duration']);
$currentDate = new DateTime(Coercion::toString($item->audio_clip['uploaded_at']));
$duration += Coercion::asInt($item->audio_clip['duration']);
$currentDate = new DateTime(Coercion::asString($item->audio_clip['uploaded_at']));
$ts = $currentDate->getTimestamp();

if ($ts > $uploadTs) {
Expand Down
6 changes: 3 additions & 3 deletions src/Tagged/Embed/MediaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function parse(
$width = 720 / 100 * (int)$width;
}

$width = Coercion::toInt($width);
$width = Coercion::asInt($width);

if (preg_match('/height\=\"([^\"]+)\"/i', $embed, $matches)) {
$height = $matches[1];
Expand All @@ -90,9 +90,9 @@ public static function parse(
$height = 450 / 100 * (int)$height;
}

$height = Coercion::toInt($height);
$height = Coercion::asInt($height);
} else {
$height = Coercion::toInt(
$height = Coercion::asInt(
round($width / $output->width * $output->height)
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Tagged/Embed/Vimeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function render(): Element
public function lookupThumbnail(
?array $options = null
): ?string {
return Coercion::toStringOrNull(
return Coercion::tryString(
$this->lookupMeta($options)['thumbnailUrl'] ?? null
);
}
Expand All @@ -144,7 +144,7 @@ public function lookupMeta(

$url = 'https://vimeo.com/api/oembed.json?url=' . urlencode($this->url);

$referrer = Coercion::toString(
$referrer = Coercion::asString(
$options['referrer'] ?? $options['referer'] ?? $_SERVER['SERVER_NAME']
);

Expand Down Expand Up @@ -173,7 +173,7 @@ public function lookupMeta(
'duration' => $json['duration'] ?? $json['length_seconds'],
'uploadDate' => isset($json['upload_date']) ?
new DateTime()->setTimestamp(
Coercion::toInt($json['upload_date'])
Coercion::asInt($json['upload_date'])
) :
null,
'description' => $json['description'],
Expand Down
4 changes: 2 additions & 2 deletions src/Tagged/Embed/Youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function setUrl(
}
}

$this->youtubeId = Coercion::toString($id);
$this->youtubeId = Coercion::asString($id);


foreach ((array)$query as $key => $value) {
Expand Down Expand Up @@ -187,7 +187,7 @@ public function lookupMeta(
'duration' => $info['length_seconds'],
'uploadDate' => isset($info['timestamp']) ?
new DateTime()->setTimestamp(
Coercion::toInt($info['timestamp'])
Coercion::asInt($info['timestamp'])
) :
null,
'description' => $json['description'],
Expand Down
6 changes: 3 additions & 3 deletions src/Tagged/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function el(
public function raw(
mixed $html
): Buffer {
return new Buffer(Coercion::forceString($html));
return new Buffer(Coercion::toString($html));
}

/**
Expand Down Expand Up @@ -473,10 +473,10 @@ public function esc(
}

try {
return htmlspecialchars(Coercion::forceString($value), ENT_QUOTES, 'UTF-8');
return htmlspecialchars(Coercion::toString($value), ENT_QUOTES, 'UTF-8');
} catch (Throwable $e) {
Glitch::logException($e);
return Coercion::forceString($value);
return Coercion::toString($value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Tagged/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function setAttribute(
!is_bool($value) &&
!$value instanceof Buffer
) {
$value = Coercion::forceString($value);
$value = Coercion::toString($value);
}

$this->attributes[$key] = $value;
Expand Down Expand Up @@ -383,7 +383,7 @@ public function setTitle(
*/
public function getTitle(): ?string
{
return Coercion::toStringOrNull(
return Coercion::tryString(
$this->getAttribute('title')
);
}
Expand Down

0 comments on commit 4e4ee24

Please sign in to comment.