Skip to content

Commit d9088f5

Browse files
imorlandStyleCIBot
andauthored
chore: enable phpstan (#30)
* chore: enable phpstan * fix: phpstan fixes * Apply fixes from StyleCI * chore: bump js deps --------- Co-authored-by: StyleCI Bot <[email protected]>
1 parent 8278d16 commit d9088f5

File tree

10 files changed

+126
-82
lines changed

10 files changed

+126
-82
lines changed

.github/workflows/backend.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: FoF Sentry PHP
2+
3+
on: [workflow_dispatch, push, pull_request]
4+
5+
jobs:
6+
run:
7+
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
8+
with:
9+
enable_backend_testing: false
10+
enable_phpstan: true
11+
12+
backend_directory: .
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Javascript
1+
name: FoF Sentry JS
22

33
on: [workflow_dispatch, push, pull_request]
44

@@ -8,11 +8,12 @@ jobs:
88
with:
99
enable_bundlewatch: false
1010
enable_prettier: true
11-
enable_typescript: false
11+
enable_typescript: true
1212

1313
frontend_directory: ./js
1414
backend_directory: .
1515
js_package_manager: npm
1616
main_git_branch: master
17+
1718
secrets:
1819
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@
4545
},
4646
"flagrow": {
4747
"discuss": "https://discuss.flarum.org/d/18089"
48+
},
49+
"flarum-cli": {
50+
"modules": {
51+
"githubActions": true
52+
}
53+
}
54+
},
55+
"config": {
56+
"allow-plugins": {
57+
"php-http/discovery": true
4858
}
59+
},
60+
"scripts": {
61+
"analyse:phpstan": "phpstan analyse",
62+
"clear-cache:phpstan": "phpstan clear-result-cache"
63+
},
64+
"scripts-descriptions": {
65+
"analyse:phpstan": "Run static analysis"
66+
},
67+
"require-dev": {
68+
"flarum/phpstan": "*"
4969
}
5070
}

js/package-lock.json

Lines changed: 65 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@sentry/tracing": "^7.56.0",
1111
"flarum-tsconfig": "^1.0.2",
1212
"flarum-webpack-config": "^2.0.0",
13-
"webpack": "^5.76.0",
13+
"webpack": "^5.89.0",
1414
"webpack-cli": "^5.1.4"
1515
},
1616
"scripts": {
@@ -20,7 +20,7 @@
2020
"format-check": "prettier --check src"
2121
},
2222
"devDependencies": {
23-
"prettier": "^2.6.2",
23+
"prettier": "^3.0.3",
2424
"webpack-bundle-analyzer": "^4.9.0",
2525
"webpack-merge": "^5.9.0"
2626
}

phpstan.neon

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
includes:
2+
- vendor/flarum/phpstan/extension.neon
3+
4+
parameters:
5+
# The level will be increased in Flarum 2.0
6+
level: 5
7+
paths:
8+
- extend.php
9+
- src
10+
excludePaths:
11+
- *.blade.php
12+
checkMissingIterableValueType: false
13+
databaseMigrationsPath: ['migrations']

src/Performance/Extension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ public function measure($event)
4848
));
4949

5050
static::$measure->setDescription($event->extension->name);
51-
} elseif (static::$measure) {
51+
} elseif (static::$measure !== null) {
5252
static::$measure->finish();
5353
}
5454
}
5555

5656
public function __destruct()
5757
{
58-
if (static::$parent) {
58+
if (static::$parent !== null) {
5959
static::$parent->finish();
6060
}
6161
}

src/Performance/Middleware/MeasurePerformanceMiddleware.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717
use Psr\Http\Server\RequestHandlerInterface;
1818
use Sentry\Tracing\Span;
1919
use Sentry\Tracing\SpanContext;
20-
use Sentry\Tracing\Transaction;
2120

2221
class MeasurePerformanceMiddleware implements Middleware
2322
{
2423
/**
25-
* @var Transaction
24+
* @var Span
2625
*/
2726
protected $transaction;
27+
28+
/**
29+
* @var string
30+
*/
2831
protected $frontend;
2932

3033
public function __construct(string $frontend, Span $transaction)

src/Reporters/SentryReporter.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,12 @@ public function report(Throwable $error)
4141
/** @var HubInterface $hub */
4242
$hub = $this->container->make('sentry');
4343

44-
if ($hub === null) {
45-
$this->logger->warning('[fof/sentry] sentry dsn not set');
46-
47-
return;
48-
}
49-
5044
if ($this->container->bound('sentry.request')) {
5145
$hub->configureScope(function (Scope $scope) {
5246
$request = $this->container->make('sentry.request');
5347
$user = RequestUtil::getActor($request);
5448

55-
if ($user && $user->id !== 0) {
49+
if (!$user->isGuest() && $user->id !== 0) {
5650
$data = $user->only('id', 'username');
5751

5852
// Only send email if enabled in settings

0 commit comments

Comments
 (0)