Skip to content

Commit

Permalink
Replace Psalm with Phpstan (#19)
Browse files Browse the repository at this point in the history
* Replace Psalm with PhpStan

* Update Workflows

* Make Phpstan happy

* Bump to Level 9
  • Loading branch information
stefanzweifel committed Mar 19, 2024
1 parent 8c7458d commit 5ba4504
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 98 deletions.
26 changes: 7 additions & 19 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -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'
33 changes: 0 additions & 33 deletions .github/workflows/psalm.yml

This file was deleted.

6 changes: 1 addition & 5 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 1 addition & 20 deletions .github/workflows/update-changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 9
paths:
- src
- tests
18 changes: 0 additions & 18 deletions psalm.xml.dist

This file was deleted.

1 change: 1 addition & 0 deletions src/Renderer/Block/HtmlBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/Inline/HtmlInlineRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/Inline/ImageRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s
{
Image::assertInstanceOf($node);

/** @var array<string, string> $attrs */
$attrs = $node->data->get('attributes');

$forbidUnsafeLinks = ! $this->config->get('allow_unsafe_links');
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/Inline/LinkRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s
{
Link::assertInstanceOf($node);

/** @var array<string, string> $attrs */
$attrs = $node->data->get('attributes');

$forbidUnsafeLinks = ! $this->config->get('allow_unsafe_links');
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/Inline/NewlineRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s
return "\n";
}

/** @phpstan-var string */
return $this->config->get('renderer/soft_break');
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Renderer/MarkdownRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
2 changes: 1 addition & 1 deletion tests/MarkdownRendererExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function test_markdown_renderer_extension_works(string $markdown, array $
}

/**
* @return iterable<array<mixed>>
* @return \Iterator
*/
public static function getTestData(): \Iterator
{
Expand Down
6 changes: 6 additions & 0 deletions tests/Renderer/Block/FencedCodeRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ protected function setUp(): void
$this->renderer = new FencedCodeRenderer();
}

/**
* @param array<int> $fencedArgs
*/
#[Test]
#[DataProvider('provide_fenced_code')]
public function it_renders_fenced_code(array $fencedArgs, string $expected): void
Expand All @@ -41,6 +44,9 @@ public function it_renders_fenced_code(array $fencedArgs, string $expected): voi
$this->assertEquals($expected, $result);
}

/**
* @return array<string, array<string, array<int, int|string>|string>>
*/
public function provide_fenced_code(): array
{
return [
Expand Down
2 changes: 2 additions & 0 deletions tests/Renderer/MarkdownRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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');

Expand Down

0 comments on commit 5ba4504

Please sign in to comment.