Skip to content

Commit

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

* fix: phpstan fixes

* Apply fixes from StyleCI

* chore: bump js deps

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
imorland and StyleCIBot authored Nov 12, 2023
1 parent 8278d16 commit d9088f5
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 82 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 Sentry 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 Sentry 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 }}
20 changes: 20 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/18089"
},
"flarum-cli": {
"modules": {
"githubActions": true
}
}
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache"
},
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis"
},
"require-dev": {
"flarum/phpstan": "*"
}
}
129 changes: 65 additions & 64 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@sentry/tracing": "^7.56.0",
"flarum-tsconfig": "^1.0.2",
"flarum-webpack-config": "^2.0.0",
"webpack": "^5.76.0",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
"scripts": {
Expand All @@ -20,7 +20,7 @@
"format-check": "prettier --check src"
},
"devDependencies": {
"prettier": "^2.6.2",
"prettier": "^3.0.3",
"webpack-bundle-analyzer": "^4.9.0",
"webpack-merge": "^5.9.0"
}
Expand Down
13 changes: 13 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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']
4 changes: 2 additions & 2 deletions src/Performance/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public function measure($event)
));

static::$measure->setDescription($event->extension->name);
} elseif (static::$measure) {
} elseif (static::$measure !== null) {
static::$measure->finish();
}
}

public function __destruct()
{
if (static::$parent) {
if (static::$parent !== null) {
static::$parent->finish();
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/Performance/Middleware/MeasurePerformanceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
use Psr\Http\Server\RequestHandlerInterface;
use Sentry\Tracing\Span;
use Sentry\Tracing\SpanContext;
use Sentry\Tracing\Transaction;

class MeasurePerformanceMiddleware implements Middleware
{
/**
* @var Transaction
* @var Span
*/
protected $transaction;

/**
* @var string
*/
protected $frontend;

public function __construct(string $frontend, Span $transaction)
Expand Down
8 changes: 1 addition & 7 deletions src/Reporters/SentryReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,12 @@ public function report(Throwable $error)
/** @var HubInterface $hub */
$hub = $this->container->make('sentry');

if ($hub === null) {
$this->logger->warning('[fof/sentry] sentry dsn not set');

return;
}

if ($this->container->bound('sentry.request')) {
$hub->configureScope(function (Scope $scope) {
$request = $this->container->make('sentry.request');
$user = RequestUtil::getActor($request);

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

// Only send email if enabled in settings
Expand Down
Loading

0 comments on commit d9088f5

Please sign in to comment.