Skip to content

Commit

Permalink
chore: enable phpstan, apply fixes (#53)
Browse files Browse the repository at this point in the history
* chore: enable phpstan, bump js deps

* fix: phpstan errors

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
imorland and StyleCIBot committed Nov 12, 2023
1 parent f7afe05 commit df824ea
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 139 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: FoF Pages PHP

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
with:
enable_backend_testing: false
enable_phpstan: true

backend_directory: .
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Javascript
name: FoF Pages JS

on: [workflow_dispatch, push, pull_request]

Expand All @@ -8,11 +8,12 @@ jobs:
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: false
enable_typescript: true

frontend_directory: ./js
backend_directory: .
js_package_manager: npm
main_git_branch: master

secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
15 changes: 15 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/18301"
},
"flarum-cli": {
"modules": {
"githubActions": true
}
}
},
"require-dev": {
"flarum/phpstan": "*"
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache"
},
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis"
}
}
250 changes: 126 additions & 124 deletions js/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@flarum/prettier-config": "^1.0.0",
"flarum-tsconfig": "^1.0.2",
"flarum-webpack-config": "^2.0.2",
"webpack": "^5.88.1",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
"scripts": {
Expand All @@ -17,6 +17,6 @@
"format-check": "prettier --check src"
},
"devDependencies": {
"prettier": "^2.8.8"
"prettier": "^3.0.3"
}
}
14 changes: 14 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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']

3 changes: 2 additions & 1 deletion src/Command/EditPageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FoF\Pages\Command;

use Carbon\Carbon;
use FoF\Pages\PageRepository;
use FoF\Pages\PageValidator;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -79,7 +80,7 @@ public function handle(EditPage $command)
$page->is_html = (bool) $attributes['isHtml'];
}

$page->edit_time = time();
$page->edit_time = Carbon::now();

$this->validator->assertValid($page->getDirty());

Expand Down
18 changes: 9 additions & 9 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
use Flarum\Post\Post;

/**
* @property string title
* @property string slug
* @property Carbon time
* @property Carbon edit_time
* @property string content
* @property bool is_hidden
* @property bool is_restricted
* @property bool is_html
* @property string $title
* @property string $slug
* @property Carbon $time
* @property Carbon $edit_time
* @property string $content
* @property bool $is_hidden
* @property bool $is_restricted
* @property bool $is_html
*/
class Page extends AbstractModel
{
Expand Down Expand Up @@ -69,7 +69,7 @@ public static function build($title, $slug, $content, $isHidden, $isRestricted,

$page->title = $title;
$page->slug = $slug;
$page->time = time();
$page->time = Carbon::now();
$page->content = $content;
$page->is_restricted = (bool) $isRestricted;
$page->is_hidden = (bool) $isHidden;
Expand Down
2 changes: 1 addition & 1 deletion src/PageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function query()
*/
public function findOrFail($id, User $user = null)
{
return $this->query()
return Page::query()
// We never pass a null $user from our own code, but third-party extensions
// like v17development/flarum-seo do it so we must allow null for backward compatibility
->whereVisibleTo($user ?? new Guest())
Expand Down
1 change: 1 addition & 0 deletions src/Search/NoOpGambit.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ public function filter(FilterState $filterState, string $filterValue, bool $nega
public function apply(SearchState $search, $bit)
{
// Does nothing
return false;
}
}

0 comments on commit df824ea

Please sign in to comment.