From c359fd067f457f6f04bf93154e47ad7760a40357 Mon Sep 17 00:00:00 2001 From: IanM <16573496+imorland@users.noreply.github.com> Date: Tue, 14 Nov 2023 08:50:03 +0000 Subject: [PATCH] chore: enable phpstan, apply fixes (#16) --- .github/workflows/backend.yml | 1 + composer.json | 16 ++++++++++------ extend.php | 5 +++++ phpstan.neon | 13 +++++++++++++ 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 phpstan.neon diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 3993498..f5f9896 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -7,5 +7,6 @@ jobs: uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main with: enable_backend_testing: true + enable_phpstan: true backend_directory: . diff --git a/composer.json b/composer.json index 0c4078c..8de5143 100755 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "forum": "https://discuss.flarum.org/d/25772" }, "require": { - "flarum/core": "^1.2.0", + "flarum/core": "^1.8.0", "flarum/tags": "*" }, "autoload": { @@ -56,18 +56,22 @@ ], "test:unit": "phpunit -c tests/phpunit.unit.xml", "test:integration": "phpunit -c tests/phpunit.integration.xml", - "test:setup": "@php tests/integration/setup.php" + "test:setup": "@php tests/integration/setup.php", + "analyse:phpstan": "phpstan analyse", + "clear-cache:phpstan": "phpstan clear-result-cache" }, "scripts-descriptions": { "test": "Runs all tests.", "test:unit": "Runs all unit tests.", "test:integration": "Runs all integration tests.", - "test:setup": "Sets up a database for use with integration tests. Execute this only once." + "test:setup": "Sets up a database for use with integration tests. Execute this only once.", + "analyse:phpstan": "Run static analysis" }, "require-dev": { - "flarum/core": "*", - "flarum/testing": "^1.0.0", - "symfony/var-dumper": "*" + "flarum/core": "*", + "flarum/phpstan": "*", + "flarum/testing": "^1.0.0", + "symfony/var-dumper": "*" }, "config": { "sort-packages": true diff --git a/extend.php b/extend.php index 2072871..11df9c6 100755 --- a/extend.php +++ b/extend.php @@ -16,6 +16,7 @@ use Flarum\Extend; use Flarum\Tags\Api\Serializer\TagSerializer; use Flarum\Tags\Event\Saving as TagSaving; +use Flarum\Tags\Tag; return [ (new Extend\Frontend('forum')) @@ -27,6 +28,10 @@ new Extend\Locales(__DIR__.'/resources/locale'), + (new Extend\Model(Tag::class)) + ->cast('excerpt_length', 'int') + ->cast('rich_excerpts', 'bool'), + (new Extend\Settings()) ->default('ianm-synopsis.excerpt_length', 200) ->default('ianm-synopsis.rich-excerpts', false) diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..03cf261 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,13 @@ +includes: + - vendor/flarum/phpstan/extension.neon + +parameters: + # The level will be increased in Flarum 2.0 + level: 5 + paths: + - extend.php + - src + excludePaths: + - *.blade.php + checkMissingIterableValueType: false + databaseMigrationsPath: ['migrations']