Skip to content

Commit

Permalink
chore: Bumped
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Feb 17, 2025
1 parent 6b0d713 commit 5fe232e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 32 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.2', '8.3']
php-version: ['8.1', '8.2', '8.3']
steps:
- uses: shivammathur/setup-php@v2
with:
Expand All @@ -35,5 +35,7 @@ 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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test:
vendor/bin/phpcs --report=full --report-file=./report.txt -p ./src
vendor/bin/phpstan analyse -c phpstan.neon
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"description": "Markdown services and Twig extension for Roadiz",
"type": "library",
"require": {
"php": ">=8.2",
"doctrine/collections": ">=1.6",
"php": ">=8.1",
"league/commonmark": "^2.2.0",
"symfony/stopwatch": "6.4.*",
"twig/twig": "^3.16"
"twig/twig": "^3.1",
"doctrine/collections": ">=1.6",
"symfony/stopwatch": "6.4.*"
},
"require-dev": {
"phpstan/phpstan": "^1.5.3",
"phpstan/phpdoc-parser": "<2"
"squizlabs/php_codesniffer": "^3.5",
"phpstan/phpstan": "^1.5.3"
},
"license": "MIT",
"authors": [
Expand All @@ -29,8 +29,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.4.x-dev",
"dev-develop": "2.5.x-dev"
"dev-master": "2.3.x-dev",
"dev-develop": "2.4.x-dev"
}
}
}
14 changes: 14 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>

<rule ref="PSR12">
<exclude name="Generic.Files.LineLength"/>
</rule>
<file>./src</file>
</ruleset>
31 changes: 14 additions & 17 deletions src/CommonMark.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,46 @@
use League\CommonMark\MarkdownConverter;
use Symfony\Component\Stopwatch\Stopwatch;

final readonly class CommonMark implements MarkdownInterface
final class CommonMark implements MarkdownInterface
{
public function __construct(
private MarkdownConverter $textConverter,
private MarkdownConverter $textExtraConverter,
private MarkdownConverter $lineConverter,
private ?Stopwatch $stopwatch = null,
private readonly MarkdownConverter $textConverter,
private readonly MarkdownConverter $textExtraConverter,
private readonly MarkdownConverter $lineConverter,
private readonly ?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;
}
}
18 changes: 15 additions & 3 deletions src/MarkdownInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@ 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;
}
18 changes: 15 additions & 3 deletions src/Twig/MarkdownExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,42 @@ 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);
}
}

0 comments on commit 5fe232e

Please sign in to comment.