diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index d872a3a..2d69d18 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['8.1', '8.2', '8.3'] + php-version: ['8.2', '8.3'] steps: - uses: shivammathur/setup-php@v2 with: @@ -35,7 +35,5 @@ jobs: ${{ runner.os }}-php-${{ matrix.php-version }}- - name: Install Dependencies run: composer install --no-scripts --no-ansi --no-interaction --no-progress - - name: Run PHP Code Sniffer - run: vendor/bin/phpcs --extensions=php --warning-severity=0 --standard=PSR12 -p ./src - name: Run PHPStan run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon diff --git a/Makefile b/Makefile deleted file mode 100644 index 5f4d6d2..0000000 --- a/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -test: - vendor/bin/phpcs --report=full --report-file=./report.txt -p ./src - vendor/bin/phpstan analyse -c phpstan.neon diff --git a/composer.json b/composer.json index a62eddd..3ee2ef7 100644 --- a/composer.json +++ b/composer.json @@ -3,14 +3,13 @@ "description": "Markdown services and Twig extension for Roadiz", "type": "library", "require": { - "php": ">=8.1", - "league/commonmark": "^2.2.0", - "twig/twig": "^3.1", + "php": ">=8.2", "doctrine/collections": ">=1.6", - "symfony/stopwatch": "6.4.*" + "league/commonmark": "^2.2.0", + "symfony/stopwatch": "6.4.*", + "twig/twig": "^3.16" }, "require-dev": { - "squizlabs/php_codesniffer": "^3.5", "phpstan/phpstan": "^1.5.3" }, "license": "MIT", @@ -29,8 +28,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3.x-dev", - "dev-develop": "2.4.x-dev" + "dev-master": "2.4.x-dev", + "dev-develop": "2.5.x-dev" } } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist deleted file mode 100644 index da4bfdb..0000000 --- a/phpcs.xml.dist +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - ./src - diff --git a/src/CommonMark.php b/src/CommonMark.php index 486b505..9986641 100644 --- a/src/CommonMark.php +++ b/src/CommonMark.php @@ -7,46 +7,49 @@ use League\CommonMark\MarkdownConverter; use Symfony\Component\Stopwatch\Stopwatch; -final class CommonMark implements MarkdownInterface +final readonly class CommonMark implements MarkdownInterface { public function __construct( - private readonly MarkdownConverter $textConverter, - private readonly MarkdownConverter $textExtraConverter, - private readonly MarkdownConverter $lineConverter, - private readonly ?Stopwatch $stopwatch = null + private MarkdownConverter $textConverter, + private MarkdownConverter $textExtraConverter, + private MarkdownConverter $lineConverter, + private ?Stopwatch $stopwatch = null, ) { } - public function text(string $markdown = null): string + public function text(?string $markdown = null): string { if (null === $markdown) { return ''; } - $this->stopwatch?->start(CommonMark::class . '::text'); + $this->stopwatch?->start(CommonMark::class.'::text'); $html = $this->textConverter->convert($markdown)->getContent(); - $this->stopwatch?->stop(CommonMark::class . '::text'); + $this->stopwatch?->stop(CommonMark::class.'::text'); + return $html; } - public function textExtra(string $markdown = null): string + public function textExtra(?string $markdown = null): string { if (null === $markdown) { return ''; } - $this->stopwatch?->start(CommonMark::class . '::textExtra'); + $this->stopwatch?->start(CommonMark::class.'::textExtra'); $html = $this->textExtraConverter->convert($markdown)->getContent(); - $this->stopwatch?->stop(CommonMark::class . '::textExtra'); + $this->stopwatch?->stop(CommonMark::class.'::textExtra'); + return $html; } - public function line(string $markdown = null): string + public function line(?string $markdown = null): string { if (null === $markdown) { return ''; } - $this->stopwatch?->start(CommonMark::class . '::line'); + $this->stopwatch?->start(CommonMark::class.'::line'); $html = $this->lineConverter->convert($markdown)->getContent(); - $this->stopwatch?->stop(CommonMark::class . '::line'); + $this->stopwatch?->stop(CommonMark::class.'::line'); + return $html; } } diff --git a/src/MarkdownInterface.php b/src/MarkdownInterface.php index 4435a5f..c9e5f0d 100644 --- a/src/MarkdownInterface.php +++ b/src/MarkdownInterface.php @@ -8,28 +8,16 @@ interface MarkdownInterface { /** * Convert Markdown to HTML using standard Markdown syntax. - * - * @param string|null $markdown - * - * @return string */ - public function text(string $markdown = null): string; + public function text(?string $markdown = null): string; /** * Convert Markdown to HTML using standard Markdown Extra syntax. - * - * @param string|null $markdown - * - * @return string */ - public function textExtra(string $markdown = null): string; + public function textExtra(?string $markdown = null): string; /** * Convert Markdown to HTML using only inline HTML elements. - * - * @param string|null $markdown - * - * @return string */ - public function line(string $markdown = null): string; + public function line(?string $markdown = null): string; } diff --git a/src/Twig/MarkdownExtension.php b/src/Twig/MarkdownExtension.php index 01f432b..bee79ff 100644 --- a/src/Twig/MarkdownExtension.php +++ b/src/Twig/MarkdownExtension.php @@ -25,42 +25,30 @@ public function getFilters(): array ]; } - /** - * @param string|null $input - * - * @return string - */ public function markdown(?string $input): string { if (null === $input) { return ''; } + return $this->markdown->text($input); } - /** - * @param string|null $input - * - * @return string - */ public function inlineMarkdown(?string $input): string { if (null === $input) { return ''; } + return $this->markdown->line($input); } - /** - * @param string|null $input - * - * @return string - */ public function markdownExtra(?string $input): string { if (null === $input) { return ''; } + return $this->markdown->textExtra($input); } }