From 5ba45040483a86b94b44d5f6f07788a59cd08caf Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 19 Mar 2024 19:35:43 +0100 Subject: [PATCH] Replace Psalm with Phpstan (#19) * Replace Psalm with PhpStan * Update Workflows * Make Phpstan happy * Bump to Level 9 --- .github/workflows/php-cs-fixer.yml | 26 ++++----------- .github/workflows/phpstan.yml | 10 ++++++ .github/workflows/psalm.yml | 33 ------------------- .github/workflows/release-drafter.yml | 6 +--- .github/workflows/update-changelog.yaml | 21 +----------- composer.json | 4 +-- phpstan.neon | 5 +++ psalm.xml.dist | 18 ---------- src/Renderer/Block/HtmlBlockRenderer.php | 1 + src/Renderer/Inline/HtmlInlineRenderer.php | 1 + src/Renderer/Inline/ImageRenderer.php | 1 + src/Renderer/Inline/LinkRenderer.php | 1 + src/Renderer/Inline/NewlineRenderer.php | 1 + src/Renderer/MarkdownRenderer.php | 2 ++ tests/MarkdownRendererExtensionTest.php | 2 +- .../Renderer/Block/FencedCodeRendererTest.php | 6 ++++ tests/Renderer/MarkdownRendererTest.php | 2 ++ 17 files changed, 42 insertions(+), 98 deletions(-) create mode 100644 .github/workflows/phpstan.yml delete mode 100644 .github/workflows/psalm.yml create mode 100644 phpstan.neon delete mode 100644 psalm.xml.dist diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml index 5811f0c..a061a6c 100644 --- a/.github/workflows/php-cs-fixer.yml +++ b/.github/workflows/php-cs-fixer.yml @@ -1,23 +1,11 @@ -name: Check & fix styling +name: php-cs-fixer -on: [push] +on: + pull_request: + push: + branches: + - main jobs: php-cs-fixer: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - - - name: Run PHP CS Fixer - uses: docker://oskarstark/php-cs-fixer-ga - with: - args: --config=.php-cs-fixer.php --allow-risky=yes - - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Fix styling + uses: stefanzweifel/reusable-workflows/.github/workflows/php-cs-fixer.yml@main diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..21be933 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,10 @@ +name: PHPStan + +on: + push + +jobs: + update_release_draft: + uses: stefanzweifel/reusable-workflows/.github/workflows/phpstan.yml@main + with: + php_version: '8.3' diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml deleted file mode 100644 index a05ccc0..0000000 --- a/.github/workflows/psalm.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Psalm - -on: - push: - paths: - - '**.php' - - 'psalm.xml.dist' - -jobs: - psalm: - name: psalm - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.1' - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick - coverage: none - - - name: Cache composer dependencies - uses: actions/cache@v2 - with: - path: vendor - key: composer-${{ hashFiles('composer.lock') }} - - - name: Run composer install - run: composer install -n --prefer-dist - - - name: Run psalm - run: ./vendor/bin/psalm --output-format=github diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 896edaf..18dc2db 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -7,8 +7,4 @@ on: jobs: update_release_draft: - runs-on: ubuntu-latest - steps: - - uses: release-drafter/release-drafter@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: stefanzweifel/reusable-workflows/.github/workflows/release-drafter.yml@main diff --git a/.github/workflows/update-changelog.yaml b/.github/workflows/update-changelog.yaml index 375694a..54f78f1 100644 --- a/.github/workflows/update-changelog.yaml +++ b/.github/workflows/update-changelog.yaml @@ -6,23 +6,4 @@ on: jobs: update: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - ref: main - - - name: Update Changelog - uses: stefanzweifel/changelog-updater-action@v1 - with: - release-notes: ${{ github.event.release.body }} - latest-version: ${{ github.event.release.name }} - - - name: Commit updated CHANGELOG - uses: stefanzweifel/git-auto-commit-action@v4 - with: - branch: main - commit_message: Update CHANGELOG - file_pattern: CHANGELOG.md + uses: stefanzweifel/reusable-workflows/.github/workflows/update-changelog.yml@main diff --git a/composer.json b/composer.json index 8922b29..3b95826 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,9 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.0", + "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^10.0", - "rector/rector": "^0.15.17", - "vimeo/psalm": "^5.7" + "rector/rector": "^0.15.17" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..ec605ef --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 9 + paths: + - src + - tests diff --git a/psalm.xml.dist b/psalm.xml.dist deleted file mode 100644 index 1dfa80c..0000000 --- a/psalm.xml.dist +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - diff --git a/src/Renderer/Block/HtmlBlockRenderer.php b/src/Renderer/Block/HtmlBlockRenderer.php index e5d2b01..bf4e3b8 100644 --- a/src/Renderer/Block/HtmlBlockRenderer.php +++ b/src/Renderer/Block/HtmlBlockRenderer.php @@ -30,6 +30,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s // We ignore $node->getType() here, as we want to render all HTML blocks the same way. + /** @var string $htmlInput */ $htmlInput = $this->config->get('html_input'); return HtmlFilter::filter($node->getLiteral(), $htmlInput); diff --git a/src/Renderer/Inline/HtmlInlineRenderer.php b/src/Renderer/Inline/HtmlInlineRenderer.php index 669fd7d..b2e4f30 100644 --- a/src/Renderer/Inline/HtmlInlineRenderer.php +++ b/src/Renderer/Inline/HtmlInlineRenderer.php @@ -28,6 +28,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s { HtmlInline::assertInstanceOf($node); + /** @var string $htmlInput */ $htmlInput = $this->config->get('html_input'); return HtmlFilter::filter($node->getLiteral(), $htmlInput); diff --git a/src/Renderer/Inline/ImageRenderer.php b/src/Renderer/Inline/ImageRenderer.php index e6c187e..25eb3d3 100644 --- a/src/Renderer/Inline/ImageRenderer.php +++ b/src/Renderer/Inline/ImageRenderer.php @@ -28,6 +28,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s { Image::assertInstanceOf($node); + /** @var array $attrs */ $attrs = $node->data->get('attributes'); $forbidUnsafeLinks = ! $this->config->get('allow_unsafe_links'); diff --git a/src/Renderer/Inline/LinkRenderer.php b/src/Renderer/Inline/LinkRenderer.php index b6e44c7..4551ed4 100644 --- a/src/Renderer/Inline/LinkRenderer.php +++ b/src/Renderer/Inline/LinkRenderer.php @@ -28,6 +28,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s { Link::assertInstanceOf($node); + /** @var array $attrs */ $attrs = $node->data->get('attributes'); $forbidUnsafeLinks = ! $this->config->get('allow_unsafe_links'); diff --git a/src/Renderer/Inline/NewlineRenderer.php b/src/Renderer/Inline/NewlineRenderer.php index 256253a..c6b38da 100644 --- a/src/Renderer/Inline/NewlineRenderer.php +++ b/src/Renderer/Inline/NewlineRenderer.php @@ -35,6 +35,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s return "\n"; } + /** @phpstan-var string */ return $this->config->get('renderer/soft_break'); } } diff --git a/src/Renderer/MarkdownRenderer.php b/src/Renderer/MarkdownRenderer.php index 0fa3ec6..d0968fd 100644 --- a/src/Renderer/MarkdownRenderer.php +++ b/src/Renderer/MarkdownRenderer.php @@ -75,11 +75,13 @@ public function renderNodes(iterable $nodes): string public function getBlockSeparator(): string { + /** @phpstan-var string */ return $this->environment->getConfiguration()->get('renderer/block_separator'); } public function getInnerSeparator(): string { + /** @phpstan-var string */ return $this->environment->getConfiguration()->get('renderer/inner_separator'); } } diff --git a/tests/MarkdownRendererExtensionTest.php b/tests/MarkdownRendererExtensionTest.php index ad28fd9..869a86d 100644 --- a/tests/MarkdownRendererExtensionTest.php +++ b/tests/MarkdownRendererExtensionTest.php @@ -29,7 +29,7 @@ public function test_markdown_renderer_extension_works(string $markdown, array $ } /** - * @return iterable> + * @return \Iterator */ public static function getTestData(): \Iterator { diff --git a/tests/Renderer/Block/FencedCodeRendererTest.php b/tests/Renderer/Block/FencedCodeRendererTest.php index 2b1087a..9f26166 100644 --- a/tests/Renderer/Block/FencedCodeRendererTest.php +++ b/tests/Renderer/Block/FencedCodeRendererTest.php @@ -21,6 +21,9 @@ protected function setUp(): void $this->renderer = new FencedCodeRenderer(); } + /** + * @param array $fencedArgs + */ #[Test] #[DataProvider('provide_fenced_code')] public function it_renders_fenced_code(array $fencedArgs, string $expected): void @@ -41,6 +44,9 @@ public function it_renders_fenced_code(array $fencedArgs, string $expected): voi $this->assertEquals($expected, $result); } + /** + * @return array|string>> + */ public function provide_fenced_code(): array { return [ diff --git a/tests/Renderer/MarkdownRendererTest.php b/tests/Renderer/MarkdownRendererTest.php index d905698..ecae7f8 100644 --- a/tests/Renderer/MarkdownRendererTest.php +++ b/tests/Renderer/MarkdownRendererTest.php @@ -40,6 +40,7 @@ public function it_renders_ast_to_markdown(): void #[Test] public function it_parses_and_renders_kitchen_sink(): void { + /** @var string $contentKitchenSink */ $contentKitchenSink = file_get_contents(__DIR__ . '/../stubs/kitchen-sink.md'); $contentKitchenSinkExpected = file_get_contents(__DIR__ . '/../stubs/kitchen-sink-expected.md'); @@ -53,6 +54,7 @@ public function it_parses_and_renders_kitchen_sink(): void #[Test] public function it_parses_kitchen_sink_and_parsing_the_result_again_returns_the_same_result(): void { + /** @var string $contentKitchenSink */ $contentKitchenSink = file_get_contents(__DIR__ . '/../stubs/kitchen-sink.md'); $contentKitchenSinkExpected = file_get_contents(__DIR__ . '/../stubs/kitchen-sink-expected.md');