Skip to content

Commit

Permalink
Merge branch 'release/v0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Feb 17, 2025
2 parents 358c19d + b19d810 commit f16ad9f
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 35 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
php-version: "8.4"
extensions: "${{ env.PHP_EXTENSIONS }}"
ini-values: "post_max_size=256M"

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

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ composer.lock
Thumbs.db
/phpunit.xml
/.idea

effigy.json
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v0.7.0 (2024-02-17)
* Added @phpstan-require-implements constraints
* Upgraded PHPStan to v2
* Updated dependencies
* Made Macros const part of MacroHandler interface
* Tidied boolean logic
* Fixed Exceptional syntax
* Added PHP8.4 to CI workflow
* Made PHP8.4 minimum version

## v0.6.0 (2024-08-21)
* Converted consts to protected PascalCase
* Updated dependency versions
Expand Down
38 changes: 30 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"email": "tom@inflatablecookie.com"
} ],
"require": {
"php": "^8.1",
"symfony/polyfill-mbstring": "^1.7",
"php": "^8.4",
"symfony/polyfill-mbstring": "^1.31",

"decodelabs/archetype": "^0.3",
"decodelabs/coercion": "^0.2",
"decodelabs/exceptional": "^0.4",
"decodelabs/tagged": "^0.15"
"decodelabs/archetype": "^0.3.8",
"decodelabs/coercion": "^0.2.15",
"decodelabs/exceptional": "^0.5.3",
"decodelabs/tagged": "^0.16"
},
"require-dev": {
"decodelabs/phpstan-decodelabs": "^0.6",
"decodelabs/phpstan-decodelabs": "^0.7",

"soundasleep/html2text": "^1.1|^2",
"erusev/parsedown": "^1.7",
Expand All @@ -34,9 +34,31 @@
"DecodeLabs\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"DecodeLabs\\Metamorph\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-develop": "0.6.x-dev"
"dev-develop": "0.7.x-dev"
},
"effigy": {
"exports": [
"phpstan-extension.neon"
]
},
"phpstan": {
"includes": [
"phpstan-extension.neon"
]
}
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"repositories": {
}
}
5 changes: 5 additions & 0 deletions phpstan-extension.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
-
class: DecodeLabs\PHPStan\MetamorphReflectionExtension
tags:
- phpstan.broker.methodsClassReflectionExtension
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
includes:
- ./phpstan-extension.neon

parameters:
paths:
- src/
Expand Down
4 changes: 2 additions & 2 deletions src/Metamorph/Handler/HtmlToText.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class HtmlToText implements MacroHandler
{
use MacroHandlerTrait;

protected const Macros = [
public const array Macros = [
'wrap' => [
'wrap' => true
],
Expand All @@ -40,7 +40,7 @@ class HtmlToText implements MacroHandler
/**
* Set options
*
* @param array<string, mixed> $options
* @param array<string,mixed> $options
*/
public function __construct(
array $options
Expand Down
12 changes: 5 additions & 7 deletions src/Metamorph/Handler/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
use DecodeLabs\Metamorph\MacroHandler;
use DecodeLabs\Metamorph\MacroHandlerTrait;
use DecodeLabs\Tagged\Buffer;

use Michelf\Markdown as MarkdownLib;
use Parsedown;

use Stringable;

class Markdown implements MacroHandler
{
use MacroHandlerTrait;
use HtmlTrait;

protected const Macros = [
public const array Macros = [
'safe' => [
'safe' => true
],
Expand All @@ -44,7 +42,7 @@ class Markdown implements MacroHandler
/**
* Set options
*
* @param array<string, mixed> $options
* @param array<string,mixed> $options
*/
public function __construct(
array $options
Expand Down Expand Up @@ -75,7 +73,7 @@ class_exists(MarkdownLib::class)
}

throw Exceptional::ComponentUnavailable(
'No supported Markdown processors could be found for the requested format - try installing Parsedown'
message: 'No supported Markdown processors could be found for the requested format - try installing Parsedown'
);
}

Expand All @@ -94,9 +92,9 @@ protected function convertParsedown(
}

if ($this->inline) {
$output = $parser->line($content);
$output = Coercion::toString($parser->line($content));
} else {
$output = $parser->text($content);
$output = Coercion::toString($parser->text($content));
}

$output = $this->resolveHtmlUrls($output);
Expand Down
4 changes: 2 additions & 2 deletions src/Metamorph/Handler/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Text implements MacroHandler
{
use MacroHandlerTrait;

protected const Macros = [
public const array Macros = [
'raw' => [
'wrap' => false
],
Expand All @@ -42,7 +42,7 @@ class Text implements MacroHandler
/**
* Set options
*
* @param array<string, mixed> $options
* @param array<string,mixed> $options
*/
public function __construct(
array $options
Expand Down
7 changes: 6 additions & 1 deletion src/Metamorph/MacroHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@

interface MacroHandler extends Handler
{
/**
* @var array<string,array<string,mixed>>
*/
public const array Macros = [];

/**
* Load macro options
*
* @return array<string, mixed>|null
* @return array<string,mixed>|null
*/
public static function loadMacro(
string $name
Expand Down
14 changes: 4 additions & 10 deletions src/Metamorph/MacroHandlerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,19 @@

namespace DecodeLabs\Metamorph;

/**
* @phpstan-require-implements MacroHandler
*/
trait MacroHandlerTrait
{
//protected const Macros = [];

/**
* Load macro options
*
* @return array<string, mixed>|null
* @return ?array<string,mixed>
*/
public static function loadMacro(
string $name
): ?array {
if (
!isset(static::Macros[$name]) ||
!is_array(static::Macros[$name])
) {
return null;
}

return static::Macros[$name];
}
}
54 changes: 54 additions & 0 deletions src/PHPStan/MetamorphReflectionExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* @package PHPStanDecodeLabs
* @license http://opensource.org/licenses/MIT
*/

declare(strict_types=1);

namespace DecodeLabs\PHPStan;

use DecodeLabs\Metamorph;
use DecodeLabs\PHPStan\MethodReflection;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\FunctionVariant;
use PHPStan\Reflection\MethodReflection as MethodReflectionInterface;
use PHPStan\Reflection\MethodsClassReflectionExtension;
use PHPStan\Reflection\ReflectionProvider;

class MetamorphReflectionExtension implements MethodsClassReflectionExtension
{
protected ReflectionProvider $reflectionProvider;

public function __construct(
ReflectionProvider $reflectionProvider
) {
$this->reflectionProvider = $reflectionProvider;
}

public function hasMethod(
ClassReflection $classReflection,
string $methodName
): bool {
return $classReflection->getName() === Metamorph::class;
}

public function getMethod(
ClassReflection $classReflection,
string $methodName
): MethodReflectionInterface {
$method = $this->reflectionProvider->getClass(Metamorph::class)->getNativeMethod('convert');

/** @var FunctionVariant $variant */
$variant = $method->getVariants()[0];
$params = array_slice($variant->getParameters(), 1);

$newVariant = MethodReflection::alterVariant($variant, $params);

$output = new MethodReflection($classReflection, $methodName, [$newVariant]);
$output->setStatic(true);

return $output;
}
}
23 changes: 23 additions & 0 deletions tests/AnalyzeFactoryCall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* @package Metamorph
* @license http://opensource.org/licenses/MIT
*/

declare(strict_types=1);

namespace DecodeLabs\Metamorph\Tests;

use DecodeLabs\Metamorph;
use Stringable;

class AnalyzeFactoryCall {

public function render(): string|Stringable {
return Metamorph::{'markdown.safe'}('Hello World');
}
}

$obj = new AnalyzeFactoryCall();
$obj->render();

0 comments on commit f16ad9f

Please sign in to comment.