diff --git a/.gitignore b/.gitignore index 4b53aba..aedad56 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.lock .DS_Store .phpunit.result.cache +.idea diff --git a/composer.json b/composer.json index 4efe3b1..da0730e 100644 --- a/composer.json +++ b/composer.json @@ -16,16 +16,16 @@ } ], "require": { - "php": "^8.0.2", - "illuminate/support": "^9.0", - "illuminate/http": "^9.0", - "monolog/monolog": "^1.12|^2.0", + "php": "^8.0|^8.1", + "illuminate/support": "^9.0|^10.0", + "illuminate/http": "^9.0|^10.0", + "monolog/monolog": "^2.9|^3.3", "ext-json": "*" }, "require-dev": { - "laravel/framework": "^9.0", - "phpunit/phpunit": "^8.5|^9.0", - "orchestra/testbench": "~7.0" + "laravel/framework": "^9.0|^10.0", + "phpunit/phpunit": "^9.5|^10.0", + "orchestra/testbench": "~8.0" }, "autoload": { "classmap": [], diff --git a/phpunit.xml b/phpunit.xml index a78d330..38d6156 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,27 +1,19 @@ - - - - ./tests - - - - - ./app - - - - - - - - + + + + ./app + + + + + ./tests + + + + + + + + diff --git a/src/Formatters/LineWithHashFormatter.php b/src/Formatters/LineWithHashFormatter.php index 03df604..909e8e2 100644 --- a/src/Formatters/LineWithHashFormatter.php +++ b/src/Formatters/LineWithHashFormatter.php @@ -19,7 +19,7 @@ class LineWithHashFormatter extends LineFormatter public function format(array $record): string { $output = parent::format($record); - if (false !== strpos($output, '%' . self::KEY . '%')) { + if (str_contains($output, '%' . self::KEY . '%')) { $output = str_replace( '%' . self::KEY . '%', $this->stringify($this->getRequestHash()), diff --git a/src/Jobs/RequestLogJob.php b/src/Jobs/RequestLogJob.php index f9f4b58..e2c33a6 100644 --- a/src/Jobs/RequestLogJob.php +++ b/src/Jobs/RequestLogJob.php @@ -17,14 +17,16 @@ class RequestLogJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + /** * @var Request */ - protected $request; + + protected Request $request; /** * @var Response */ - protected $response; + protected Response $response; /** * RequestLogJob constructor. diff --git a/src/LogCustomizers/HashLogCustomizer.php b/src/LogCustomizers/HashLogCustomizer.php index 63e556d..305a960 100644 --- a/src/LogCustomizers/HashLogCustomizer.php +++ b/src/LogCustomizers/HashLogCustomizer.php @@ -3,6 +3,7 @@ namespace Brackets\AdvancedLogger\LogCustomizers; use Brackets\AdvancedLogger\Formatters\LineWithHashFormatter; +use \Illuminate\Log\Logger; /** * Class HashLogCustomizer @@ -12,10 +13,10 @@ class HashLogCustomizer /** * Customize the given logger instance. * - * @param \Illuminate\Log\Logger $logger + * @param Logger $logger * @return void */ - public function __invoke($logger) + public function __invoke(Logger $logger): void { foreach ($logger->getHandlers() as $handler) { $handler->setFormatter(app( diff --git a/src/Loggers/RequestLogger.php b/src/Loggers/RequestLogger.php index df29ec1..9263fa8 100644 --- a/src/Loggers/RequestLogger.php +++ b/src/Loggers/RequestLogger.php @@ -13,7 +13,7 @@ class RequestLogger implements LoggerInterface /** * @var \Monolog\Logger; */ - protected $monolog; + protected \Monolog\Logger $monolog; /** * BaseRequestLogger constructor. @@ -148,27 +148,4 @@ public function log($level, string|\Stringable $message, array $context = []): v { $this->monolog->log($level, $message, $context); } - - /** - * Register a file log handler. - * - * @param string $path - * @param string $level - * @return void - */ - public function useFiles($path, $level = 'debug') - { - } - - /** - * Register a daily file log handler. - * - * @param string $path - * @param int $days - * @param string $level - * @return void - */ - public function useDailyFiles($path, $days = 0, $level = 'debug') - { - } } diff --git a/src/Services/Benchmark.php b/src/Services/Benchmark.php index e41b454..a17a54b 100644 --- a/src/Services/Benchmark.php +++ b/src/Services/Benchmark.php @@ -12,13 +12,13 @@ class Benchmark /** * @var array */ - protected static $timers = []; + protected static array $timers = []; /** * @param string $name * @return mixed */ - public static function start(string $name) + public static function start(string $name): mixed { $start = microtime(true); static::$timers[$name] = [ @@ -71,7 +71,7 @@ public static function hash(string $name): string /** * @return bool|string */ - public static function generateRandomHash() + public static function generateRandomHash(): string { try { return substr(str_replace(['+', '/', '='], '', base64_encode(random_bytes(32))), 0, 10); diff --git a/src/Services/RequestLoggerService.php b/src/Services/RequestLoggerService.php index e53c9ba..63411f3 100644 --- a/src/Services/RequestLoggerService.php +++ b/src/Services/RequestLoggerService.php @@ -21,7 +21,7 @@ class RequestLoggerService /** * @var array */ - protected $formats = [ + protected array $formats = [ 'full' => '{request-hash} | HTTP/{http-version} {status} | {remote-addr} | {user} | {method} {url} {query} | {response-time} s | {user-agent} | {referer}', 'combined' => '{remote-addr} - {remote-user} [{date}] "{method} {url} HTTP/{http-version}" {status} {content-length} "{referer}" "{user-agent}"', 'common' => '{remote-addr} - {remote-user} [{date}] "{method} {url} HTTP/{http-version}" {status} {content-length}', @@ -32,15 +32,15 @@ class RequestLoggerService /** * @var RequestInterpolation */ - protected $requestInterpolation; + protected RequestInterpolation $requestInterpolation; /** * @var ResponseInterpolation */ - protected $responseInterpolation; + protected ResponseInterpolation $responseInterpolation; /** * @var RequestLogger */ - protected $logger; + protected RequestLogger $logger; /** * RequestLoggerService constructor. diff --git a/tests/TestCase.php b/tests/TestCase.php index 363ff4e..7f277fb 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -35,7 +35,7 @@ protected function tearDown(): void /** * @param \Illuminate\Foundation\Application $app */ - protected function getEnvironmentSetUp($app) + protected function getEnvironmentSetUp($app): void { if (file_exists($this->getRequestLogFileName())) { unlink($this->getRequestLogFileName());