Skip to content

Commit

Permalink
chore: enable phpstan (#81)
Browse files Browse the repository at this point in the history
* chore: enable phpstan

* fix: phpstan error

* chore: bump js deps
  • Loading branch information
imorland committed Nov 12, 2023
1 parent 3097258 commit 6582e1d
Show file tree
Hide file tree
Showing 8 changed files with 778 additions and 628 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 Masquerade 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 Masquerade 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 @@ -47,11 +47,26 @@
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/5791"
},
"flarum-cli": {
"modules": {
"githubActions": true
}
}
},
"autoload": {
"psr-4": {
"FoF\\Masquerade\\": "src/"
}
},
"require-dev": {
"flarum/phpstan": "*"
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache"
},
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis"
}
}
1,312 changes: 709 additions & 603 deletions js/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"dependencies": {
"flarum-webpack-config": "^2.0.0",
"html5sortable": "^0.9.18",
"webpack": "^5.76.0",
"webpack-cli": "^4.10.0"
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
"scripts": {
"dev": "webpack --mode development --watch",
Expand All @@ -16,6 +16,6 @@
"devDependencies": {
"@flarum/prettier-config": "^1.0.0",
"flarum-tsconfig": "^1.0.2",
"prettier": "^2.6.2"
"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']

7 changes: 6 additions & 1 deletion src/Api/Serializers/FieldSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
namespace FoF\Masquerade\Api\Serializers;

use Flarum\Api\Serializer\AbstractSerializer;
use FoF\Masquerade\Field;
use Tobscure\JsonApi\Relationship;
use Tobscure\JsonApi\Resource;

class FieldSerializer extends AbstractSerializer
{
/**
* @param Field $model
* @return array
*/
protected function getDefaultAttributes($model): array
{
return $model->toArray();
Expand All @@ -20,7 +25,7 @@ public function getType($model): string

public function answer($model): ?Relationship
{
if (!$this->getActor()) {
if ($this->getActor()->isGuest()) {
return null;
}

Expand Down
35 changes: 16 additions & 19 deletions src/Repositories/FieldRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,11 @@ public function delete($id)
{
$field = $this->field->findOrFail($id);

if ($field) {
$field->delete();
$field->delete();

$this->cache->forget(static::CACHE_KEY_ALL_FIELDS);

return $field;
}
$this->cache->forget(static::CACHE_KEY_ALL_FIELDS);

return false;
return $field;
}

/**
Expand All @@ -120,18 +116,18 @@ public function delete($id)
*/
public function completed($userId)
{
// return $this->cache->rememberForever(sprintf(
// static::CACHE_KEY_UNCOMPLETED,
// $userId
// ), function () use ($userId) {
// return $this->cache->rememberForever(sprintf(
// static::CACHE_KEY_UNCOMPLETED,
// $userId
// ), function () use ($userId) {
return $this->field
->where('required', true)
->whereDoesntHave('answers', function ($q) use ($userId) {
$q->where('user_id', $userId);
})
->count() == 0;
->where('required', true)
->whereDoesntHave('answers', function ($q) use ($userId) {
$q->where('user_id', $userId);
})
->count() == 0;

// });
// });
}

/**
Expand Down Expand Up @@ -167,9 +163,10 @@ protected function query()

protected function highestSort(): int
{
/** @var $max Field */
$max = Field::orderBy('sort', 'desc')->first();
/** @var Field $max */
$max = Field::query()->orderBy('sort', 'desc')->first();

/** @phpstan-ignore-next-line */
return $max ? $max->sort + 1 : 0;
}
}

0 comments on commit 6582e1d

Please sign in to comment.