Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ RELEASE_NOTES_*.md export-ignore
UPGRADING.md export-ignore
index.php export-ignore
snap.php export-ignore
structarmed.php export-ignore
testbench.yaml export-ignore
workbench/ export-ignore
38 changes: 38 additions & 0 deletions .github/workflows/structarmed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: structarmed

on:
pull_request:
paths:
- '**.php'
- 'composer.json'
- '.github/workflows/structarmed.yml'

permissions:
contents: read

concurrency:
group: structarmed-${{ github.ref }}
cancel-in-progress: true

jobs:
structarmed:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout code
uses: actions/checkout@v7
with:
persist-credentials: false

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v4

- name: Run StructArmed
run: vendor/bin/structarmed analyze
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"symfony/var-dumper": "^7.3.3|^8.0"
},
"require-dev": {
"boundwize/structarmed": "^0.19",
"driftingly/rector-laravel": "^2.3",
"fakerphp/faker": "^1.24",
"fruitcake/laravel-debugbar": "^4.2",
Expand Down Expand Up @@ -91,12 +92,14 @@
"qa": [
"@rector",
"@format",
"@phpstan-simplified"
"@phpstan-simplified",
"@structarmed"
],
"fix-cs": "vendor/bin/pint",
"pint": "vendor/bin/pint",
"format": "vendor/bin/pint",
"rector": "vendor/bin/rector process",
"structarmed": "vendor/bin/structarmed analyze",
"sync-ai": "vendor/bin/boost sync",
"test": "vendor/bin/phpunit",
"post-update-cmd": [
Expand Down
5 changes: 2 additions & 3 deletions src/RunLog/RunLogServiceRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Foundation\Application;
use SanderMuller\Stopwatch\ServiceProvider;
use SanderMuller\Stopwatch\Stopwatch;

/**
* Container wiring for the run-log feature. Extracted from {@see ServiceProvider}
* to keep that class within its cognitive-complexity budget.
* Container wiring for the run-log feature. Extracted from the package service
* provider to keep that class within its cognitive-complexity budget.
*
* Helpers for config decoding live in {@see ConfigReader}; collector construction
* lives in dedicated {@see CollectorBuilder} static helpers.
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function packageRegistered(): void

public function packageBooted(): void
{
Blade::directive('stopwatch', function (): string {
Blade::directive('stopwatch', static function (): string {
return '<?php echo app(' . Stopwatch::class . '::class)->render(); ?>';
});

Expand Down
2 changes: 1 addition & 1 deletion src/StopwatchCheckpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static function formatBytes(int $bytes): string
$absBytes = abs($bytes);

return match (true) {
$absBytes >= 1048576 => round($bytes / 1048576, 1) . 'MB',
$absBytes >= 1_048_576 => round($bytes / 1_048_576, 1) . 'MB',
$absBytes >= 1024 => round($bytes / 1024, 1) . 'KB',
default => $bytes . 'B',
};
Expand Down
82 changes: 82 additions & 0 deletions structarmed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

use Boundwize\StructArmed\Architecture;
use Boundwize\StructArmed\Preset\Preset;
use Boundwize\StructArmed\Preset\Presets\Psr4Preset;

return Architecture::define()
->skip([
Psr4Preset::CLASSES_MUST_MATCH_COMPOSER => [
__DIR__ . '/tests/RunLog',
__DIR__ . '/tests/PHPStan/data',
],
])
->withPresets(Preset::PSR4(), Preset::CODEQUALITY())
->layer('Clock', ['src/Clock.php', 'src/SystemClock.php', 'src/FakeClock.php'])
->layer('Stopwatch', [
'src/Stopwatch.php',
'src/StopwatchCheckpoint.php',
'src/StopwatchCheckpointCollection.php',
'src/StopwatchOutput.php',
])
->layer('HtmlRenderer', [
'src/StopwatchCheckpointHtmlRenderer.php',
'src/StopwatchExpansionRenderer.php',
'src/StopwatchHtmlRenderer.php',
'src/StopwatchHttpRenderer.php',
'src/StopwatchIcons.php',
'src/StopwatchLocationRenderer.php',
'src/StopwatchQueryRenderer.php',
'src/StopwatchSlowStyling.php',
])
->layer('Inject', [
'src/InjectEnvironmentGate.php',
'src/InjectMiddlewareRegistrar.php',
'src/InjectSettings.php',
'src/ProfileViaStopwatch.php',
'src/StopwatchInjectAlias.php',
'src/StopwatchInjectMiddleware.php',
'src/StopwatchInjector.php',
'src/StopwatchMiddleware.php',
'src/StopwatchToolbarRenderer.php',
])
->layer('Notifications', 'src/Notifications')
// The run-log hooks the core talks to: two listener interfaces, the end-reason enum and the path helper.
->layer('RunLogContracts', [
'src/RunLog/CheckpointListener.php',
'src/RunLog/PathRelativiser.php',
'src/RunLog/RunEndReason.php',
'src/RunLog/RunRecorder.php',
])
->layer('RunLog', 'src/RunLog', [
'src/RunLog/CheckpointListener.php',
'src/RunLog/PathRelativiser.php',
'src/RunLog/RunEndReason.php',
'src/RunLog/RunRecorder.php',
])
->layer('Console', 'src/Console')
->layer('McpTools', 'src/Mcp/Tools')
->layer('Mcp', 'src/Mcp', 'src/Mcp/Tools')
->layer('Integrations', 'src/Integrations')
->layer('PHPStan', 'src/PHPStan')
->layer('ServiceProvider', 'src/ServiceProvider.php')
->ruleset([
'Clock' => [],
// The core renders through HtmlRenderer, notifies the channels and reports to the run-log
// hooks. Each of those reads the stopwatch back, so these three pairs are mutual by design.
'Stopwatch' => ['Clock', 'HtmlRenderer', 'Notifications', 'RunLogContracts'],
'HtmlRenderer' => ['Stopwatch'],
'Notifications' => ['Stopwatch'],
'RunLogContracts' => ['Stopwatch'],
'RunLog' => ['+RunLogContracts'],
'Inject' => ['+HtmlRenderer'],
'Integrations' => ['Stopwatch'],
'PHPStan' => ['Stopwatch'],
'Console' => ['+RunLog'],
// The list tool reuses the console's run-list filter parsing.
'McpTools' => ['+Console'],
'Mcp' => ['+McpTools'],
'ServiceProvider' => ['+Console', '+Mcp', '+Inject', '+Integrations', '+Notifications'],
]);
2 changes: 1 addition & 1 deletion tests/Inject/AttributeModeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function test_alias_does_not_trigger_ordering_warning_or_double_inject():

$logged = [];
Log::shouldReceive('debug')
->andReturnUsing(function (string $message) use (&$logged): void {
->andReturnUsing(static function (string $message) use (&$logged): void {
$logged[] = $message;
});

Expand Down
22 changes: 11 additions & 11 deletions tests/RunLog/StopwatchRunLogIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function test_recorder_fires_on_finish_with_resolved_context(): void
{
$captured = null;
$stopwatch = $this->makeStopwatch();
$stopwatch->recordRunsTo($this->makeRecorder(function (Stopwatch $sw, array $ctx) use (&$captured): void {
$stopwatch->recordRunsTo($this->makeRecorder(static function (Stopwatch $sw, array $ctx) use (&$captured): void {
$captured = $ctx;
}));

Expand All @@ -32,7 +32,7 @@ public function test_recorder_fires_only_once_when_finish_called_repeatedly(): v
{
$count = 0;
$stopwatch = $this->makeStopwatch();
$stopwatch->recordRunsTo($this->makeRecorder(function () use (&$count): void {
$stopwatch->recordRunsTo($this->makeRecorder(static function () use (&$count): void {
$count++;
}))->start();
$stopwatch->checkpoint('Step');
Expand All @@ -49,7 +49,7 @@ public function test_throwing_recorder_does_not_propagate(): void
{
Log::spy();
$stopwatch = $this->makeStopwatch();
$stopwatch->recordRunsTo($this->makeRecorder(function (): void {
$stopwatch->recordRunsTo($this->makeRecorder(static function (): void {
throw new RuntimeException('boom');
}))->start();
$stopwatch->checkpoint('Step');
Expand All @@ -63,7 +63,7 @@ public function test_throwing_notification_does_not_block_recorders(): void
{
$recorderCalled = false;
$stopwatch = $this->makeStopwatch();
$stopwatch->recordRunsTo($this->makeRecorder(function () use (&$recorderCalled): void {
$stopwatch->recordRunsTo($this->makeRecorder(static function () use (&$recorderCalled): void {
$recorderCalled = true;
}));

Expand Down Expand Up @@ -91,10 +91,10 @@ public function test_record_runs_to_replaces_not_appends(): void
$second = 0;

$stopwatch = $this->makeStopwatch();
$stopwatch->recordRunsTo($this->makeRecorder(function () use (&$first): void {
$stopwatch->recordRunsTo($this->makeRecorder(static function () use (&$first): void {
$first++;
}));
$stopwatch->recordRunsTo($this->makeRecorder(function () use (&$second): void {
$stopwatch->recordRunsTo($this->makeRecorder(static function () use (&$second): void {
$second++;
}));

Expand All @@ -112,7 +112,7 @@ public function test_context_providers_survive_reset_and_evaluate_at_finish(): v
$stopwatch = $this->makeStopwatch();

$stopwatch->pushRunContextProvider(static fn (): array => ['command' => 'app:reindex']);
$stopwatch->recordRunsTo($this->makeRecorder(function (Stopwatch $sw, array $ctx) use (&$captured): void {
$stopwatch->recordRunsTo($this->makeRecorder(static function (Stopwatch $sw, array $ctx) use (&$captured): void {
$captured = $ctx;
}));

Expand All @@ -137,7 +137,7 @@ public function test_with_run_context_overrides_provider_on_collision(): void
$captured = null;
$stopwatch = $this->makeStopwatch();
$stopwatch->pushRunContextProvider(static fn (): array => ['url' => '/from-provider', 'method' => 'GET']);
$stopwatch->recordRunsTo($this->makeRecorder(function (Stopwatch $sw, array $ctx) use (&$captured): void {
$stopwatch->recordRunsTo($this->makeRecorder(static function (Stopwatch $sw, array $ctx) use (&$captured): void {
$captured = $ctx;
}));

Expand All @@ -160,7 +160,7 @@ public function test_throwing_context_provider_does_not_block_recorders(): void
throw new RuntimeException('provider boom');
});
$stopwatch->pushRunContextProvider(static fn (): array => ['command' => 'app:still-fires']);
$stopwatch->recordRunsTo($this->makeRecorder(function (Stopwatch $sw, array $ctx) use (&$captured): void {
$stopwatch->recordRunsTo($this->makeRecorder(static function (Stopwatch $sw, array $ctx) use (&$captured): void {
$captured = $ctx;
}));

Expand All @@ -175,7 +175,7 @@ public function test_with_run_context_cleared_between_runs(): void
{
$captured = null;
$stopwatch = $this->makeStopwatch();
$stopwatch->recordRunsTo($this->makeRecorder(function (Stopwatch $sw, array $ctx) use (&$captured): void {
$stopwatch->recordRunsTo($this->makeRecorder(static function (Stopwatch $sw, array $ctx) use (&$captured): void {
$captured = $ctx;
}));

Expand All @@ -199,7 +199,7 @@ public function test_with_run_context_cleared_on_restart_when_first_run_abandone
{
$captured = null;
$stopwatch = $this->makeStopwatch();
$stopwatch->recordRunsTo($this->makeRecorder(function (Stopwatch $sw, array $ctx) use (&$captured): void {
$stopwatch->recordRunsTo($this->makeRecorder(static function (Stopwatch $sw, array $ctx) use (&$captured): void {
$captured = $ctx;
}));

Expand Down
2 changes: 1 addition & 1 deletion tests/RunLog/StopwatchTransientContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function test_survives_between_checkpoint_and_finish_then_clears_after_fi
{
$captured = null;
$stopwatch = $this->makeStopwatch();
$stopwatch->recordRunsTo($this->captureRecorder(function (Stopwatch $sw) use (&$captured): void {
$stopwatch->recordRunsTo($this->captureRecorder(static function (Stopwatch $sw) use (&$captured): void {
$captured = $sw->transientContext(Stopwatch::TRANSIENT_EXCEPTION);
}));

Expand Down
16 changes: 8 additions & 8 deletions tests/StopwatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ public function test_when_runs_callback_for_truthy_value_and_skips_for_falsy():
$falsyCalls = 0;

$result = $stopwatch
->when(true, function (Stopwatch $sw) use (&$truthyCalls, $stopwatch): void {
->when(true, static function (Stopwatch $sw) use (&$truthyCalls, $stopwatch): void {
$truthyCalls++;
self::assertSame($stopwatch, $sw);
})
->when(false, function () use (&$falsyCalls): void {
->when(false, static function () use (&$falsyCalls): void {
$falsyCalls++;
});

Expand All @@ -326,10 +326,10 @@ public function test_when_invokes_default_callback_for_falsy_value(): void

$stopwatch->when(
value: false,
callback: function () use (&$primary): void {
callback: static function () use (&$primary): void {
$primary++;
},
default: function () use (&$default): void {
default: static function () use (&$default): void {
$default++;
},
);
Expand All @@ -344,8 +344,8 @@ public function test_when_resolves_closure_value(): void

$calls = 0;
$stopwatch->when(
fn (Stopwatch $sw): bool => $sw->enabled(),
function () use (&$calls): void {
static fn (Stopwatch $sw): bool => $sw->enabled(),
static function () use (&$calls): void {
$calls++;
},
);
Expand All @@ -359,10 +359,10 @@ public function test_unless_inverts_when(): void

$calls = 0;
$stopwatch
->unless(false, function () use (&$calls): void {
->unless(false, static function () use (&$calls): void {
$calls++;
})
->unless(true, function () use (&$calls): void {
->unless(true, static function () use (&$calls): void {
$calls++;
});

Expand Down
Loading