diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 0b3245e..d872a3a 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.0', '8.1'] + php-version: ['8.1', '8.2', '8.3'] steps: - uses: shivammathur/setup-php@v2 with: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 768dab5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -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 diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..8e18fa6 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright © 2024 Ambroise Maupate + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/composer.json b/composer.json index 61a33e5..a62eddd 100644 --- a/composer.json +++ b/composer.json @@ -3,11 +3,11 @@ "description": "Markdown services and Twig extension for Roadiz", "type": "library", "require": { - "php": ">=8.0", + "php": ">=8.1", "league/commonmark": "^2.2.0", "twig/twig": "^3.1", "doctrine/collections": ">=1.6", - "symfony/stopwatch": "5.4.*" + "symfony/stopwatch": "6.4.*" }, "require-dev": { "squizlabs/php_codesniffer": "^3.5", @@ -29,8 +29,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.1.x-dev", - "dev-develop": "2.2.x-dev" + "dev-master": "2.3.x-dev", + "dev-develop": "2.4.x-dev" } } } diff --git a/phpstan.neon b/phpstan.neon index 6f839dd..8fead83 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: max + level: 7 paths: - src excludePaths: @@ -7,6 +7,8 @@ parameters: - */bower_components/* - */static/* ignoreErrors: + - identifier: missingType.iterableValue + - identifier: missingType.generics - '#Instantiated class Memcached not found#' - '#Instantiated class Redis not found#' reportUnmatchedIgnoredErrors: false diff --git a/src/CommonMark.php b/src/CommonMark.php index 1abfed9..486b505 100644 --- a/src/CommonMark.php +++ b/src/CommonMark.php @@ -9,27 +9,12 @@ 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( - MarkdownConverter $textConverter, - MarkdownConverter $textExtraConverter, - MarkdownConverter $lineConverter, - ?Stopwatch $stopwatch = null + private readonly MarkdownConverter $textConverter, + private readonly MarkdownConverter $textExtraConverter, + private readonly MarkdownConverter $lineConverter, + private readonly ?Stopwatch $stopwatch = null ) { - $this->textConverter = $textConverter; - $this->textExtraConverter = $textExtraConverter; - $this->lineConverter = $lineConverter; - $this->stopwatch = $stopwatch; } public function text(string $markdown = null): string @@ -37,13 +22,9 @@ public function text(string $markdown = null): string if (null === $markdown) { return ''; } - if (null !== $this->stopwatch) { - $this->stopwatch->start(CommonMark::class . '::text'); - } + $this->stopwatch?->start(CommonMark::class . '::text'); $html = $this->textConverter->convert($markdown)->getContent(); - if (null !== $this->stopwatch) { - $this->stopwatch->stop(CommonMark::class . '::text'); - } + $this->stopwatch?->stop(CommonMark::class . '::text'); return $html; } @@ -52,13 +33,9 @@ public function textExtra(string $markdown = null): string if (null === $markdown) { return ''; } - if (null !== $this->stopwatch) { - $this->stopwatch->start(CommonMark::class . '::textExtra'); - } + $this->stopwatch?->start(CommonMark::class . '::textExtra'); $html = $this->textExtraConverter->convert($markdown)->getContent(); - if (null !== $this->stopwatch) { - $this->stopwatch->stop(CommonMark::class . '::textExtra'); - } + $this->stopwatch?->stop(CommonMark::class . '::textExtra'); return $html; } @@ -67,13 +44,9 @@ public function line(string $markdown = null): string if (null === $markdown) { return ''; } - if (null !== $this->stopwatch) { - $this->stopwatch->start(CommonMark::class . '::line'); - } + $this->stopwatch?->start(CommonMark::class . '::line'); $html = $this->lineConverter->convert($markdown)->getContent(); - if (null !== $this->stopwatch) { - $this->stopwatch->stop(CommonMark::class . '::line'); - } + $this->stopwatch?->stop(CommonMark::class . '::line'); return $html; } } diff --git a/src/Twig/MarkdownExtension.php b/src/Twig/MarkdownExtension.php index 919bfbd..01f432b 100644 --- a/src/Twig/MarkdownExtension.php +++ b/src/Twig/MarkdownExtension.php @@ -10,11 +10,8 @@ final class MarkdownExtension extends AbstractExtension { - private MarkdownInterface $markdown; - - public function __construct(MarkdownInterface $markdown) + public function __construct(private readonly MarkdownInterface $markdown) { - $this->markdown = $markdown; } public function getFilters(): array