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 10, 2025
1 parent 4d0f93f commit e9c0eef
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 45 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.0', '8.1']
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
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: php
sudo: required
php:
- 8.0
- 8.1
- nightly
install:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev --no-interaction
script:
- vendor/bin/phpcs --report=full --report-file=./report.txt -p ./src
- vendor/bin/phpstan analyse -c phpstan.neon
jobs:
allow_failures:
- php: nightly
9 changes: 0 additions & 9 deletions LICENSE.md

This file was deleted.

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.0",
"league/commonmark": "^2.2.0",
"symfony/stopwatch": "6.4.*",
"twig/twig": "^3.16"
"twig/twig": "^3.1",
"doctrine/collections": ">=1.6",
"symfony/stopwatch": "5.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.1.x-dev",
"dev-develop": "2.2.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>
4 changes: 1 addition & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
parameters:
level: 7
level: max
paths:
- src
excludePaths:
- */node_modules/*
- */bower_components/*
- */static/*
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics
- '#Instantiated class Memcached not found#'
- '#Instantiated class Redis not found#'
reportUnmatchedIgnoredErrors: false
58 changes: 41 additions & 17 deletions src/CommonMark.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,73 @@
use League\CommonMark\MarkdownConverter;
use Symfony\Component\Stopwatch\Stopwatch;

final readonly class CommonMark implements MarkdownInterface
final class CommonMark implements MarkdownInterface
{
private ?Stopwatch $stopwatch;
private MarkdownConverter $textConverter;
private MarkdownConverter $lineConverter;
private MarkdownConverter $textExtraConverter;

/**
* @param MarkdownConverter $textConverter
* @param MarkdownConverter $textExtraConverter
* @param MarkdownConverter $lineConverter
* @param Stopwatch|null $stopwatch
*/
public function __construct(
private MarkdownConverter $textConverter,
private MarkdownConverter $textExtraConverter,
private MarkdownConverter $lineConverter,
private ?Stopwatch $stopwatch = null,
MarkdownConverter $textConverter,
MarkdownConverter $textExtraConverter,
MarkdownConverter $lineConverter,
?Stopwatch $stopwatch = null
) {
$this->textConverter = $textConverter;
$this->textExtraConverter = $textExtraConverter;
$this->lineConverter = $lineConverter;
$this->stopwatch = $stopwatch;
}

public function text(?string $markdown = null): string
public function text(string $markdown = null): string
{
if (null === $markdown) {
return '';
}
$this->stopwatch?->start(CommonMark::class.'::text');
if (null !== $this->stopwatch) {
$this->stopwatch->start(CommonMark::class . '::text');
}
$html = $this->textConverter->convert($markdown)->getContent();
$this->stopwatch?->stop(CommonMark::class.'::text');

if (null !== $this->stopwatch) {
$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');
if (null !== $this->stopwatch) {
$this->stopwatch->start(CommonMark::class . '::textExtra');
}
$html = $this->textExtraConverter->convert($markdown)->getContent();
$this->stopwatch?->stop(CommonMark::class.'::textExtra');

if (null !== $this->stopwatch) {
$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');
if (null !== $this->stopwatch) {
$this->stopwatch->start(CommonMark::class . '::line');
}
$html = $this->lineConverter->convert($markdown)->getContent();
$this->stopwatch?->stop(CommonMark::class.'::line');

if (null !== $this->stopwatch) {
$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;
}
23 changes: 19 additions & 4 deletions src/Twig/MarkdownExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

final class MarkdownExtension extends AbstractExtension
{
public function __construct(private readonly MarkdownInterface $markdown)
private MarkdownInterface $markdown;

public function __construct(MarkdownInterface $markdown)
{
$this->markdown = $markdown;
}

public function getFilters(): array
Expand All @@ -25,30 +28,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 e9c0eef

Please sign in to comment.