Skip to content

Commit

Permalink
Merge branch 'release/v0.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Apr 26, 2024
2 parents 0571ada + cf2d095 commit 50a925f
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 39 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
pull_request: null

env:
PHP_EXTENSIONS: "intl"
PHP_EXTENSIONS: "intl, :php-psr"

jobs:
file_consistency:
Expand All @@ -19,7 +19,7 @@ jobs:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.0"
php-version: "8.1"
extensions: "${{ env.PHP_EXTENSIONS }}"
ini-values: "post_max_size=256M"

Expand Down Expand Up @@ -60,9 +60,9 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
- "8.2"
- "8.3"
steps:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.0"
php-version: "8.1"
extensions: "${{ env.PHP_EXTENSIONS }}"
ini-values: "post_max_size=256M"

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.5.2 (2024-04-26)
* Made PHP8.1 minimum version
* Updated dependency list

## v0.5.1 (2023-09-26)
* Converted phpstan doc comments to generic
* Migrated to use effigy in CI workflow
Expand Down
18 changes: 8 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@
"name": "decodelabs/metamorph",
"description": "A flexible framework for content transformations",
"type": "library",
"keywords": ["render", "transform", "content"],
"keywords": [ "render", "transform", "content" ],
"license": "MIT",
"authors": [{
"name": "Tom Wright",
"email": "tom@inflatablecookie.com"
}],
"authors": [ {
"name": "Tom Wright",
"email": "tom@inflatablecookie.com"
} ],
"require": {
"php": "^8.0",
"php": "^8.1",
"symfony/polyfill-mbstring": "^1.7",

"decodelabs/archetype": "^0.2",
"decodelabs/coercion": "^0.2",
"decodelabs/glitch-support": "^0.4",
"decodelabs/exceptional": "^0.4",
"decodelabs/tagged": "^0.14"
},
"require-dev": {
"decodelabs/phpstan-decodelabs": "^0.6",

"soundasleep/html2text": "^1.1",
"soundasleep/html2text": "^1.1|^2",
"erusev/parsedown": "^1.7",
"michelf/php-markdown": "^1.9"
"michelf/php-markdown": "^1.9|^2"
},
"suggest": {
"erusev/parsedown": "Add support for Markdown parsing",
Expand Down
15 changes: 9 additions & 6 deletions src/Metamorph.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ class Metamorph
*
* @param callable(string):string|null $resolver
*/
public static function setUrlResolver(?callable $resolver): void
{
public static function setUrlResolver(
?callable $resolver
): void {
static::$urlResolver = $resolver;
}

/**
* Resolve URL
*/
public static function resolveUrl(string $url): string
{
public static function resolveUrl(
string $url
): string {
if (!$resolver = static::$urlResolver) {
return $url;
}
Expand Down Expand Up @@ -95,8 +97,9 @@ public static function convert(
*
* @param mixed $content
*/
protected static function prepareContent(mixed $content): ?string
{
protected static function prepareContent(
mixed $content
): ?string {
if (
is_string($content) ||
$content instanceof Stringable
Expand Down
15 changes: 9 additions & 6 deletions src/Metamorph/Handler/HtmlToText.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class HtmlToText implements MacroHandler
*
* @param array<string, mixed> $options
*/
public function __construct(array $options)
{
public function __construct(
array $options
) {
$this->maxLength = Coercion::toIntOrNull($options['maxLength'] ?? $this->maxLength);
$this->wrap = Coercion::toBool($options['wrap'] ?? $this->wrap);
$this->ellipsis = Coercion::toString($options['ellipsis'] ?? $this->ellipsis);
Expand Down Expand Up @@ -85,8 +86,9 @@ public function convert(
/**
* Strip significant characters from content
*/
protected function strip(string $content): ?string
{
protected function strip(
string $content
): ?string {
$content = new Buffer($content);
$content = (string)ContentCollection::normalize($content);

Expand All @@ -108,8 +110,9 @@ protected function strip(string $content): ?string
/**
* Shorten output string
*/
protected function shorten(string $content): string
{
protected function shorten(
string $content
): string {
return mb_substr($content, 0, $this->maxLength);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Metamorph/Handler/HtmlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ trait HtmlTrait
/**
* Resolve URLs in HTML
*/
protected function resolveHtmlUrls(string $html): string
{
protected function resolveHtmlUrls(
string $html
): string {
if (!$this->resolveUrls) {
return $html;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Metamorph/Handler/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ class Markdown implements MacroHandler
*
* @param array<string, mixed> $options
*/
public function __construct(array $options)
{
public function __construct(
array $options
) {
$this->inline = Coercion::toBool($options['inline'] ?? $this->inline);
$this->safe = Coercion::toBool($options['safe'] ?? $this->safe);
$this->resolveUrls = Coercion::toBool($options['resolveUrls'] ?? $this->resolveUrls);
Expand Down
15 changes: 9 additions & 6 deletions src/Metamorph/Handler/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ class Text implements MacroHandler
*
* @param array<string, mixed> $options
*/
public function __construct(array $options)
{
public function __construct(
array $options
) {
$this->maxLength = Coercion::toIntOrNull($options['maxLength'] ?? $this->maxLength);
$this->wrap = Coercion::toBool($options['wrap'] ?? $this->wrap);
$this->ellipsis = Coercion::toString($options['ellipsis'] ?? $this->ellipsis);
Expand Down Expand Up @@ -79,17 +80,19 @@ public function convert(
/**
* Strip significant characters from content
*/
protected function escape(string $content): string
{
protected function escape(
string $content
): string {
return htmlspecialchars($content, ENT_QUOTES, 'UTF-8');
}


/**
* Shorten output string
*/
protected function shorten(string $content): string
{
protected function shorten(
string $content
): string {
return mb_substr($content, 0, $this->maxLength);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Metamorph/MacroHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ interface MacroHandler extends Handler
*
* @return array<string, mixed>|null
*/
public static function loadMacro(string $name): ?array;
public static function loadMacro(
string $name
): ?array;
}
5 changes: 3 additions & 2 deletions src/Metamorph/MacroHandlerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ trait MacroHandlerTrait
*
* @return array<string, mixed>|null
*/
public static function loadMacro(string $name): ?array
{
public static function loadMacro(
string $name
): ?array {
if (
!isset(static::MACROS[$name]) ||
!is_array(static::MACROS[$name])
Expand Down

0 comments on commit 50a925f

Please sign in to comment.