diff --git a/composer.json b/composer.json index 59e7cac..0ac08ac 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,17 @@ }, "require-dev": { "fakerphp/faker": "^1.23", + "larastan/larastan": "^3.9", "laravel/pint": "^1.18", "mockery/mockery": "^1.6", "nunomaduro/collision": "^8.6", "orchestra/testbench": "^9.0|^10.0", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-deprecation-rules": "^2.0", "phpunit/phpunit": "^11.5", - "spatie/laravel-activitylog": "^4.8" + "spatie/laravel-activitylog": "^4.8", + "vimeo/psalm": "^6.14" }, "suggest": { "spatie/laravel-activitylog": "Required for activity logging features (^4.0)" @@ -66,7 +71,8 @@ "preferred-install": "dist", "sort-packages": true, "allow-plugins": { - "php-http/discovery": true + "php-http/discovery": true, + "phpstan/extension-installer": true } }, "minimum-stability": "stable", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..f628907 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,23 @@ +parameters: + paths: + - src + level: 0 + ignoreErrors: + - '#Unsafe usage of new static#' + - '#env\(\).*outside of the config directory#' + - identifier: larastan.noEnvCallsOutsideOfConfig + - identifier: trait.unused + - identifier: class.notFound + - identifier: function.deprecated + - identifier: method.notFound + excludePaths: + - src/Core/Activity + - src/Core/Config/Tests + - src/Core/Input/Tests + - src/Core/Tests + - src/Core/Bouncer/Tests + - src/Core/Bouncer/Gate/Tests + - src/Core/Service/Tests + - src/Core/Front/Tests + - src/Mod/Trees + reportUnmatchedIgnoredErrors: false diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..7d23bb2 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Core/Storage/StorageMetrics.php b/src/Core/Storage/StorageMetrics.php index 255902d..c73a89b 100644 --- a/src/Core/Storage/StorageMetrics.php +++ b/src/Core/Storage/StorageMetrics.php @@ -92,7 +92,7 @@ class StorageMetrics return; } - $this->increment($driver, 'hits'); + $this->doIncrement($driver, 'hits'); $this->recordLatency($driver, $durationSeconds * 1000); } @@ -105,7 +105,7 @@ class StorageMetrics return; } - $this->increment($driver, 'misses'); + $this->doIncrement($driver, 'misses'); $this->recordLatency($driver, $durationSeconds * 1000); } @@ -118,7 +118,7 @@ class StorageMetrics return; } - $this->increment($driver, 'writes'); + $this->doIncrement($driver, 'writes'); $this->recordLatency($driver, $durationSeconds * 1000); } @@ -131,7 +131,7 @@ class StorageMetrics return; } - $this->increment($driver, 'deletes'); + $this->doIncrement($driver, 'deletes'); $this->recordLatency($driver, $durationSeconds * 1000); } @@ -144,7 +144,7 @@ class StorageMetrics return; } - $this->increment($driver, 'fallback_activations'); + $this->doIncrement($driver, 'fallback_activations'); $this->log('warning', 'Storage fallback activated', [ 'driver' => $driver, @@ -162,9 +162,9 @@ class StorageMetrics } if ($newState === CircuitBreaker::STATE_OPEN) { - $this->increment($driver, 'circuit_opens'); + $this->doIncrement($driver, 'circuit_opens'); } elseif ($newState === CircuitBreaker::STATE_CLOSED && $oldState !== CircuitBreaker::STATE_CLOSED) { - $this->increment($driver, 'circuit_closes'); + $this->doIncrement($driver, 'circuit_closes'); } $this->log('info', 'Circuit breaker state change', [ @@ -174,6 +174,17 @@ class StorageMetrics ]); } + /** + * Increment a custom metric counter. + * + * Allows external code to record custom metrics beyond the standard + * hit/miss/write/delete metrics. + */ + public function increment(string $driver, string $metric, int $amount = 1): void + { + $this->doIncrement($driver, $metric, $amount); + } + /** * Record an error. */ @@ -183,7 +194,7 @@ class StorageMetrics return; } - $this->increment($driver, 'errors'); + $this->doIncrement($driver, 'errors'); $this->log('error', 'Storage operation error', [ 'driver' => $driver, @@ -431,9 +442,9 @@ class StorageMetrics } /** - * Increment a metric counter. + * Internal metric counter increment. */ - protected function increment(string $driver, string $metric, int $amount = 1): void + protected function doIncrement(string $driver, string $metric, int $amount = 1): void { if (! isset($this->metrics[$driver])) { $this->metrics[$driver] = $this->getDefaultMetrics();