diff --git a/.phpmd/ruleset.xml b/.phpmd/ruleset.xml index 29570f9..603fb87 100644 --- a/.phpmd/ruleset.xml +++ b/.phpmd/ruleset.xml @@ -12,12 +12,20 @@ vendor/* + + + + + + + + diff --git a/src/Checks/DatabaseHealthCheck.php b/src/Checks/DatabaseHealthCheck.php index 09aa47b..d9a4049 100644 --- a/src/Checks/DatabaseHealthCheck.php +++ b/src/Checks/DatabaseHealthCheck.php @@ -11,11 +11,11 @@ class DatabaseHealthCheck extends HealthCheck { protected string $name = 'database'; - protected DatabaseManager $db; + protected DatabaseManager $database; - public function __construct(DatabaseManager $db) + public function __construct(DatabaseManager $database) { - $this->db = $db; + $this->database = $database; } public function status(): Status @@ -26,7 +26,7 @@ public function status(): Status $connection = ''; } - $pdo = $this->db->connection($connection)->getPdo(); + $this->database->connection($connection)->getPdo(); } catch (Exception $e) { return $this->problem('Could not connect to db', [ 'connection' => $connection, diff --git a/src/Checks/HttpHealthCheck.php b/src/Checks/HttpHealthCheck.php index b76ebe8..79f15db 100644 --- a/src/Checks/HttpHealthCheck.php +++ b/src/Checks/HttpHealthCheck.php @@ -46,14 +46,14 @@ public function status(): Status try { $response = $client->get($address); - } catch (ConnectException $e) { - $badConnections->put($address, $e->getMessage()); + } catch (ConnectException $exception) { + $badConnections->put($address, $exception->getMessage()); continue; - } catch (BadResponseException $e) { - $response = $e->getResponse(); - } catch (Exception $e) { - $generalFailures->put($address, $this->exceptionContext($e)); + } catch (BadResponseException $exception) { + $response = $exception->getResponse(); + } catch (Exception $exception) { + $generalFailures->put($address, $this->exceptionContext($exception)); continue; } diff --git a/tests/Checks/CacheHealthCheckTest.php b/tests/Checks/CacheHealthCheckTest.php index cc8bfe9..dcc14c8 100644 --- a/tests/Checks/CacheHealthCheckTest.php +++ b/tests/Checks/CacheHealthCheckTest.php @@ -12,6 +12,7 @@ class CacheHealthCheckTest extends TestCase { /** + * @inheritDoc * @param Application $app * @return array */ diff --git a/tests/Checks/DatabaseHealthCheckTest.php b/tests/Checks/DatabaseHealthCheckTest.php index 733cc88..37cdde2 100644 --- a/tests/Checks/DatabaseHealthCheckTest.php +++ b/tests/Checks/DatabaseHealthCheckTest.php @@ -13,6 +13,7 @@ class DatabaseHealthCheckTest extends TestCase { /** + * @inheritDoc * @param Application $app * @return array */ @@ -27,10 +28,10 @@ public function testShowsProblemWhenCantConnectToDb(): void 'healthcheck.database.connections' => ['default'], ]); - $db = new DatabaseManager(); - $db->addConnection('default', new BadConnection()); + $database = new DatabaseManager(); + $database->addConnection('default', new BadConnection()); - $status = (new DatabaseHealthCheck($db))->status(); + $status = (new DatabaseHealthCheck($database))->status(); $this->assertTrue($status->isProblem()); } @@ -41,10 +42,10 @@ public function testShowsOkayWhenCanConnectToDb(): void 'healthcheck.database.connections' => ['default'], ]); - $db = new DatabaseManager(); - $db->addConnection('default', new HealthyConnection()); + $database = new DatabaseManager(); + $database->addConnection('default', new HealthyConnection()); - $status = (new DatabaseHealthCheck($db))->status(); + $status = (new DatabaseHealthCheck($database))->status(); $this->assertTrue($status->isOkay()); } @@ -55,11 +56,11 @@ public function testShowsWhichConnectionFailed(): void 'healthcheck.database.connections' => ['healthy', 'bad'], ]); - $db = new DatabaseManager(); - $db->addConnection('healthy', new HealthyConnection()); - $db->addConnection('bad', new BadConnection()); + $database = new DatabaseManager(); + $database->addConnection('healthy', new HealthyConnection()); + $database->addConnection('bad', new BadConnection()); - $status = (new DatabaseHealthCheck($db))->status(); + $status = (new DatabaseHealthCheck($database))->status(); $this->assertTrue($status->isProblem()); $this->assertSame('bad', $status->context()['connection']); diff --git a/tests/Checks/EnvHealthCheckTest.php b/tests/Checks/EnvHealthCheckTest.php index a44e113..efe212a 100644 --- a/tests/Checks/EnvHealthCheckTest.php +++ b/tests/Checks/EnvHealthCheckTest.php @@ -10,6 +10,7 @@ class EnvHealthCheckTest extends TestCase { /** + * @inheritDoc * @param Application $app * @return array */ diff --git a/tests/Checks/HttpHealthCheckTest.php b/tests/Checks/HttpHealthCheckTest.php index 32b054a..70c5fdb 100644 --- a/tests/Checks/HttpHealthCheckTest.php +++ b/tests/Checks/HttpHealthCheckTest.php @@ -16,6 +16,7 @@ class HttpHealthCheckTest extends TestCase { /** + * @inheritDoc * @param Application $app * @return array */ @@ -34,7 +35,7 @@ public function testShowsProblemIfResponseCodeIsIncorrect(): void 'default-curl-timeout' => 1 ]); - $this->app->bind(Client::class, function ($app, $args) { + $this->app->bind(Client::class, function () { $responses = [ (new Response(500)), ]; @@ -58,7 +59,7 @@ public function testShowsProblemIfConnectionIsUnreachable(): void 'default-curl-timeout' => 1 ]); - $this->app->bind(Client::class, function ($app, $args) { + $this->app->bind(Client::class, function () { $responses = [ (new Response(500)), ]; @@ -82,7 +83,7 @@ public function testShowsProblemOnConnectException(): void 'default-curl-timeout' => 1 ]); - $this->app->bind(Client::class, function ($app, $args) { + $this->app->bind(Client::class, function () { $exceptions = [ (new ConnectException('Connection refused', new Request('GET', 'test'))), ]; @@ -106,7 +107,7 @@ public function testShowsProblemOnGeneralException(): void 'default-curl-timeout' => 1 ]); - $this->app->bind(Client::class, function ($app, $args) { + $this->app->bind(Client::class, function () { $exceptions = [ (new TooManyRedirectsException('Will not follow more than 5 redirects', new Request('GET', 'test'))), ]; @@ -130,7 +131,7 @@ public function testShowsOkayIfAllConnectionsAreReachable(): void 'default-curl-timeout' => 1, ]); - $this->app->bind(Client::class, function ($app, $args) { + $this->app->bind(Client::class, function () { $responses = [ (new Response(200)), ]; diff --git a/tests/Checks/LogHealthCheckTest.php b/tests/Checks/LogHealthCheckTest.php index 816f702..00f38c7 100644 --- a/tests/Checks/LogHealthCheckTest.php +++ b/tests/Checks/LogHealthCheckTest.php @@ -12,6 +12,7 @@ class LogHealthCheckTest extends TestCase { /** + * @inheritDoc * @param Application $app * @return array */ diff --git a/tests/Checks/MigrationUpToDateHealthCheckTest.php b/tests/Checks/MigrationUpToDateHealthCheckTest.php index 5c0c2ea..b3bc8f9 100644 --- a/tests/Checks/MigrationUpToDateHealthCheckTest.php +++ b/tests/Checks/MigrationUpToDateHealthCheckTest.php @@ -14,7 +14,7 @@ class MigrationUpToDateHealthCheckTest extends TestCase protected MockObject $migratorMock; - protected MockObject $migrationRepositoryMock; + protected MockObject $migrationRepository; public function prepare(): void @@ -27,13 +27,13 @@ public function prepare(): void ->disableOriginalConstructor() ->getMock(); - $this->migrationRepositoryMock = $this->getMockBuilder(MigrationRepositoryInterface::class) + $this->migrationRepository = $this->getMockBuilder(MigrationRepositoryInterface::class) ->disableOriginalConstructor() ->getMock(); $this->migratorMock->expects(($this->any())) ->method('getRepository') - ->willReturn($this->migrationRepositoryMock); + ->willReturn($this->migrationRepository); $this->migratorMock->expects($this->any()) ->method('repositoryExists') @@ -53,7 +53,7 @@ public function testCanReturnFalseWhenSchemaIsOutdated(): void 'missing_migration.php' => 2 ]); - $this->migrationRepositoryMock->expects($this->once()) + $this->migrationRepository->expects($this->once()) ->method('getRan') ->willReturn([]); @@ -75,7 +75,7 @@ public function testCanReturnFalseWhenRanMigrationCouldNotBeRetrieved(): void ->method('repositoryExists') ->willReturn(false); - $this->migrationRepositoryMock->expects($this->any()) + $this->migrationRepository->expects($this->any()) ->method('getRan') ->willReturn([]); @@ -91,7 +91,7 @@ public function testCanReturnTrueWhenMigrationsAreUpToDate(): void 'executed_migration.php' => 2 ]); - $this->migrationRepositoryMock->expects($this->any()) + $this->migrationRepository->expects($this->any()) ->method('getRan') ->willReturn([ 'executed_migration.php' diff --git a/tests/Checks/PackageSecurityHealthCheckTest.php b/tests/Checks/PackageSecurityHealthCheckTest.php index 4f8e2ed..af8ecac 100644 --- a/tests/Checks/PackageSecurityHealthCheckTest.php +++ b/tests/Checks/PackageSecurityHealthCheckTest.php @@ -5,6 +5,8 @@ use Closure; use Exception; use Illuminate\Foundation\Application; +use Illuminate\Support\Arr; +use Illuminate\Support\Collection; use Mockery; use Mockery\MockInterface; use Tests\Stubs\Checks\PackageSecurityHealthCheck as StubPackageSecurityHealthCheck; @@ -15,6 +17,7 @@ class PackageSecurityHealthCheckTest extends TestCase { /** + * @inheritDoc * @param Application $app * @return array */ @@ -30,9 +33,18 @@ public function getPackageProviders($app): array * @param \Closure|null $mock * @return MockInterface */ - protected function partialMock($abstract, Closure $mock = null): MockInterface + protected function partialMock($abstract, ?Closure $mock = null): MockInterface { - return $this->instance($abstract, Mockery::mock(...array_filter(func_get_args()))->makePartial()); + /** + * @var Collection $arguments + */ + $arguments = collect([ + $abstract, + $mock, + ]) + ->filter(); + + return $this->instance($abstract, Mockery::mock(...$arguments)->makePartial()); } public function testShowsProblemIfRequiredPackageNotLoaded() diff --git a/tests/Checks/RedisHealthCheckTest.php b/tests/Checks/RedisHealthCheckTest.php index a367e3b..04bfacb 100644 --- a/tests/Checks/RedisHealthCheckTest.php +++ b/tests/Checks/RedisHealthCheckTest.php @@ -16,6 +16,7 @@ class RedisHealthCheckTest extends TestCase { /** + * @inheritDoc * @param Application $app * @return array */ diff --git a/tests/Checks/SchedulerHealthCheckTest.php b/tests/Checks/SchedulerHealthCheckTest.php index ff7c08e..db12f6c 100644 --- a/tests/Checks/SchedulerHealthCheckTest.php +++ b/tests/Checks/SchedulerHealthCheckTest.php @@ -12,6 +12,7 @@ class SchedulerHealthCheckTest extends TestCase { /** + * @inheritDoc * @param Application $app * @return array */ diff --git a/tests/Checks/StorageHealthCheckTest.php b/tests/Checks/StorageHealthCheckTest.php index 7562cd7..0625625 100644 --- a/tests/Checks/StorageHealthCheckTest.php +++ b/tests/Checks/StorageHealthCheckTest.php @@ -12,6 +12,7 @@ class StorageHealthCheckTest extends TestCase { /** + * @inheritDoc * @param Application $app * @return array */ diff --git a/tests/Commands/HealthCheckMakeCommandTest.php b/tests/Commands/HealthCheckMakeCommandTest.php index 1166810..c85c905 100644 --- a/tests/Commands/HealthCheckMakeCommandTest.php +++ b/tests/Commands/HealthCheckMakeCommandTest.php @@ -11,6 +11,7 @@ class HealthCheckMakeCommandTest extends TestCase { /** + * @inheritDoc * @param Application $app * @return array */ diff --git a/tests/Controllers/HealthCheckControllerTest.php b/tests/Controllers/HealthCheckControllerTest.php index bb1b9bb..0edf50e 100644 --- a/tests/Controllers/HealthCheckControllerTest.php +++ b/tests/Controllers/HealthCheckControllerTest.php @@ -15,6 +15,7 @@ class HealthCheckControllerTest extends TestCase { /** + * @inheritDoc * @param Application $app * @return array */ diff --git a/tests/Controllers/PingControllerTest.php b/tests/Controllers/PingControllerTest.php index cf319ae..8f610f0 100644 --- a/tests/Controllers/PingControllerTest.php +++ b/tests/Controllers/PingControllerTest.php @@ -10,6 +10,7 @@ class PingControllerTest extends TestCase { /** + * @inheritDoc * @param Application $app * @return array */ diff --git a/tests/Stubs/Log/BadLogger.php b/tests/Stubs/Log/BadLogger.php index f8bbc59..58d7993 100644 --- a/tests/Stubs/Log/BadLogger.php +++ b/tests/Stubs/Log/BadLogger.php @@ -9,6 +9,7 @@ class BadLogger implements LoggerInterface { /** + * @inheritDoc * @throws Exception */ public function emergency(Stringable | string $message, array $context = []): void @@ -17,6 +18,7 @@ public function emergency(Stringable | string $message, array $context = []): vo } /** + * @inheritDoc * @throws Exception */ public function alert(Stringable | string $message, array $context = []): void @@ -25,6 +27,7 @@ public function alert(Stringable | string $message, array $context = []): void } /** + * @inheritDoc * @throws Exception */ public function critical(Stringable | string $message, array $context = []): void @@ -33,6 +36,7 @@ public function critical(Stringable | string $message, array $context = []): voi } /** + * @inheritDoc * @throws Exception */ public function error(Stringable | string $message, array $context = []): void @@ -41,6 +45,7 @@ public function error(Stringable | string $message, array $context = []): void } /** + * @inheritDoc * @throws Exception */ public function warning(Stringable | string $message, array $context = []): void @@ -49,6 +54,7 @@ public function warning(Stringable | string $message, array $context = []): void } /** + * @inheritDoc * @throws Exception */ public function notice(Stringable | string $message, array $context = []): void @@ -57,6 +63,7 @@ public function notice(Stringable | string $message, array $context = []): void } /** + * @inheritDoc * @throws Exception */ public function info(Stringable | string $message, array $context = []): void @@ -65,6 +72,7 @@ public function info(Stringable | string $message, array $context = []): void } /** + * @inheritDoc * @throws Exception */ public function debug(Stringable | string $message, array $context = []): void @@ -73,6 +81,7 @@ public function debug(Stringable | string $message, array $context = []): void } /** + * @inheritDoc * @throws Exception */ public function log($level, Stringable | string $message, array $context = []): void diff --git a/tests/Stubs/Log/NullLogger.php b/tests/Stubs/Log/NullLogger.php index a64df95..7d1c97e 100644 --- a/tests/Stubs/Log/NullLogger.php +++ b/tests/Stubs/Log/NullLogger.php @@ -7,39 +7,65 @@ class NullLogger implements LoggerInterface { + /** + * @inheritDoc + */ public function emergency(Stringable | string $message, array $context = []): void { } + /** + * @inheritDoc + */ public function alert(Stringable | string $message, array $context = []): void { } + /** + * @inheritDoc + */ public function critical(Stringable | string $message, array $context = []): void { } + /** + * @inheritDoc + */ public function error(Stringable | string $message, array $context = []): void { } + /** + * @inheritDoc + */ public function warning(Stringable | string $message, array $context = []): void { } + /** + * @inheritDoc + */ public function notice(Stringable | string $message, array $context = []): void { - // TODO: Implement notice() method. } + /** + * @inheritDoc + */ public function info(Stringable | string $message, array $context = []): void { } + /** + * @inheritDoc + */ public function debug(Stringable | string $message, array $context = []): void { } + /** + * @inheritDoc + */ public function log($level, Stringable | string $message, array $context = []): void { } diff --git a/tests/Stubs/Redis/Connections/PhpRedisClusterConnection.php b/tests/Stubs/Redis/Connections/PhpRedisClusterConnection.php index 1f01de0..cc69161 100644 --- a/tests/Stubs/Redis/Connections/PhpRedisClusterConnection.php +++ b/tests/Stubs/Redis/Connections/PhpRedisClusterConnection.php @@ -16,8 +16,10 @@ public function ping(string|array $message = null): string|bool } /** - * This cannot be changed for PSR 12 compliance as it is stubbing a dependency + * This cannot be changed for PSR 12 or PHPMD compliance as it is stubbing a dependency * @return array + * @SuppressWarnings(PHPMD.UnusedLocalVariable) + * @SuppressWarnings(PHPMD.CamelCaseMethodName) */ // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore public function _masters(): array