Skip to content

Commit

Permalink
Add PhpStan (#7)
Browse files Browse the repository at this point in the history
* Add phpstan

* Bump to Level 9

* Update Code to satisfy Phpstan

* Update Workflows

* Update run-tests.yml
  • Loading branch information
stefanzweifel committed Mar 19, 2024
1 parent ff107b4 commit 2f8b686
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 49 deletions.
23 changes: 4 additions & 19 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
name: Check & fix styling
name: php-cs-fixer

on: [push]
on:
push:

jobs:
php-cs-fixer:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
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'
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
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
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@v3
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5 | ^10"
},
"autoload": {
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
1 change: 1 addition & 0 deletions src/MarkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class MarkExtension implements ConfigurableExtensionInterface
{
public function register(EnvironmentBuilderInterface $environment): void
{
/** @var string $char */
$char = $environment->getConfiguration()->get('mark/character');

$environment
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/MarkRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MarkRenderer implements NodeRendererInterface
*/
public function render(Node $node, ChildNodeRendererInterface $childRenderer): HtmlElement
{
/** @var array<string, string> $attrs */
$attrs = $node->data->get('attributes');

return new HtmlElement('mark', $attrs, $childRenderer->renderNodes($node->children()));
Expand Down
5 changes: 4 additions & 1 deletion tests/MarkExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class MarkExtensionTest extends TestCase
{
public function getParser($character = '='): CommonMarkConverter
public function getParser(string $character = '='): CommonMarkConverter
{
$converter = new CommonMarkConverter([
'mark' => [
Expand Down Expand Up @@ -41,6 +41,9 @@ public function test(string $source, string $expected, string $character): void
);
}

/**
* @return array<string, array<string>>
*/
public static function getSourceAndExpectedOutputs(): array
{
return [
Expand Down
7 changes: 4 additions & 3 deletions tests/Renderer/MarkRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function setUp(): void
}

/** @test */
public function it_renders_mark()
public function it_renders_mark(): void
{
$inline = new Mark();
$inline->data->set('attributes/id', 'foo');
Expand All @@ -29,9 +29,10 @@ public function it_renders_mark()

$result = $this->renderer->render($inline, $fakeRenderer);

$this->assertTrue($result instanceof HtmlElement);
$this->assertInstanceOf(HtmlElement::class, $result);
$this->assertEquals('mark', $result->getTagName());
$this->assertStringContainsString('::children::', $result->getContents(true));
$this->assertEquals(['id' => 'foo'], $result->getAllAttributes());
/** @phpstan-ignore-next-line */
$this->assertStringContainsString('::children::', $result->getContents(false));
}
}

0 comments on commit 2f8b686

Please sign in to comment.