From 29b2a145bd19b8e641f5dc01071ee59e8d9af72f Mon Sep 17 00:00:00 2001 From: aarongerig Date: Wed, 8 Feb 2023 14:39:33 +0100 Subject: [PATCH] style: optimize global namespace functions and classes --- composer.json | 10 ++-- .../Check/AppEnvironment.php | 9 +-- src/PimcoreMonitorBundle/Check/DiskUsage.php | 46 ++++++-------- .../Check/DoctrineMigrations.php | 39 ++++++------ .../Check/HostingSize.php | 60 ++++++++++--------- .../Check/HttpsConnection.php | 32 ++++++---- .../Check/MySqlVersion.php | 43 +++++++------ src/PimcoreMonitorBundle/Check/PhpVersion.php | 17 ++---- .../Check/PimcoreAreabricks.php | 11 +--- .../Check/PimcoreBundles.php | 11 +--- .../Check/PimcoreElementCount.php | 50 ++++++---------- .../Check/PimcoreMaintenance.php | 11 +--- .../Check/PimcoreUsers.php | 9 +-- .../Check/PimcoreVersion.php | 14 ++--- .../Command/HealthCheckCommand.php | 6 +- .../Command/HealthReportCommand.php | 41 +++++-------- .../Admin/HealthCheckController.php | 2 +- .../Compiler/CheckTagCompilerPass.php | 2 +- .../PimcoreMonitorExtension.php | 7 +-- .../Manager/RunnerManager.php | 7 +-- .../PimcoreMonitorBundle.php | 6 +- .../Reporter/ArrayReporter.php | 16 ++--- .../Resources/config/services.yaml | 2 +- .../Resources/config/services/checks.yaml | 4 +- .../Health => admin/health}/status.html.twig | 10 ++-- src/PimcoreMonitorBundle/Runner/Runner.php | 24 -------- 26 files changed, 195 insertions(+), 294 deletions(-) rename src/PimcoreMonitorBundle/Resources/views/{Admin/Health => admin/health}/status.html.twig (89%) delete mode 100644 src/PimcoreMonitorBundle/Runner/Runner.php diff --git a/composer.json b/composer.json index a9ca75f..081da7f 100644 --- a/composer.json +++ b/composer.json @@ -18,15 +18,15 @@ ], "require": { "php": ">=8.0", - "laminas/laminas-diagnostics": "^1.8", + "laminas/laminas-diagnostics": "^1.24", "pimcore/pimcore": "^10.0" }, "require-dev": { - "deployer/deployer": "^7.0", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-symfony": "^0.12", + "deployer/deployer": "^7.1", + "phpstan/phpstan": "^1.9", + "phpstan/phpstan-symfony": "^1.2", "roave/security-advisories": "dev-latest", - "symplify/easy-coding-standard": "^9.0" + "symplify/easy-coding-standard": "^11.2" }, "autoload": { "psr-4": { diff --git a/src/PimcoreMonitorBundle/Check/AppEnvironment.php b/src/PimcoreMonitorBundle/Check/AppEnvironment.php index ccef5ad..d0e36f1 100644 --- a/src/PimcoreMonitorBundle/Check/AppEnvironment.php +++ b/src/PimcoreMonitorBundle/Check/AppEnvironment.php @@ -26,14 +26,7 @@ class AppEnvironment extends AbstractCheck { protected const IDENTIFIER = 'system:app_environment'; - protected bool $skip; - protected string $environment; - - public function __construct(bool $skip, string $environment) - { - $this->skip = $skip; - $this->environment = $environment; - } + public function __construct(protected bool $skip, protected string $environment) {} /** * {@inheritDoc} diff --git a/src/PimcoreMonitorBundle/Check/DiskUsage.php b/src/PimcoreMonitorBundle/Check/DiskUsage.php index 148c20a..c06b406 100644 --- a/src/PimcoreMonitorBundle/Check/DiskUsage.php +++ b/src/PimcoreMonitorBundle/Check/DiskUsage.php @@ -27,18 +27,12 @@ class DiskUsage extends AbstractCheck { protected const IDENTIFIER = 'device:disk_usage'; - protected bool $skip; - protected int $warningThreshold; - protected int $criticalThreshold; - protected string $path; - - public function __construct(bool $skip, int $warningThreshold, int $criticalThreshold, string $path) - { - $this->skip = $skip; - $this->warningThreshold = $warningThreshold; - $this->criticalThreshold = $criticalThreshold; - $this->path = $path; - } + public function __construct( + protected bool $skip, + protected int $warningThreshold, + protected int $criticalThreshold, + protected string $path + ) {} /** * {@inheritDoc} @@ -49,32 +43,26 @@ public function check(): ResultInterface return new Skip('Check was skipped'); } - $df = disk_free_space($this->path); - $dt = disk_total_space($this->path); + $df = \disk_free_space($this->path); + $dt = \disk_total_space($this->path); $du = $dt - $df; $dp = ($du / $dt) * 100; + $data = [ + 'used' => \formatBytes($du), + 'free' => \formatBytes($df), + 'total' => \formatBytes($dt), + ]; + if ($dp >= $this->criticalThreshold) { - return new Failure(sprintf('Disk usage too high: %2d%%', $dp), [ - 'used' => formatBytes($du), - 'free' => formatBytes($df), - 'total' => formatBytes($dt), - ]); + return new Failure(\sprintf('Disk usage too high: %2d%%', $dp), $data); } if ($dp >= $this->warningThreshold) { - return new Warning(sprintf('Disk usage high: %2d%%', $dp), [ - 'used' => formatBytes($du), - 'free' => formatBytes($df), - 'total' => formatBytes($dt), - ]); + return new Warning(\sprintf('Disk usage high: %2d%%', $dp), $data); } - return new Success(sprintf('Disk usage is %2d%%', $dp), [ - 'used' => formatBytes($du), - 'free' => formatBytes($df), - 'total' => formatBytes($dt), - ]); + return new Success(\sprintf('Disk usage is %2d%%', $dp), $data); } /** diff --git a/src/PimcoreMonitorBundle/Check/DoctrineMigrations.php b/src/PimcoreMonitorBundle/Check/DoctrineMigrations.php index 7f5e8fa..dee20c9 100644 --- a/src/PimcoreMonitorBundle/Check/DoctrineMigrations.php +++ b/src/PimcoreMonitorBundle/Check/DoctrineMigrations.php @@ -22,7 +22,6 @@ use Doctrine\Migrations\Metadata\AvailableMigration; use Doctrine\Migrations\Metadata\ExecutedMigration; use Doctrine\Migrations\Version\Version; -use InvalidArgumentException; use Laminas\Diagnostics\Result\Failure; use Laminas\Diagnostics\Result\ResultInterface; use Laminas\Diagnostics\Result\Skip; @@ -32,8 +31,6 @@ class DoctrineMigrations extends AbstractCheck { protected const IDENTIFIER = 'system:doctrine_migrations'; - protected bool $skip; - /** * Type depends on the installed version of doctrine/migrations: * for ^2.0 it is string[], for ^3.0 it is Version[] @@ -50,10 +47,8 @@ class DoctrineMigrations extends AbstractCheck */ protected array $migratedVersions; - public function __construct(bool $skip, $input) + public function __construct(protected bool $skip, $input) { - $this->skip = $skip; - // check for doctrine/migrations:^3.0 if ($input instanceof DependencyFactory) { $this->availableVersions = $this->getAvailableVersionsFromDependencyFactory($input); @@ -63,15 +58,15 @@ public function __construct(bool $skip, $input) // check for doctrine/migrations:^2.0 if ($input instanceof Configuration && - method_exists($input, 'getAvailableVersions') && - method_exists($input, 'getMigratedVersions') + \method_exists($input, 'getAvailableVersions') && + \method_exists($input, 'getMigratedVersions') ) { $this->availableVersions = $input->getAvailableVersions(); $this->migratedVersions = $input->getMigratedVersions(); return; } - throw new InvalidArgumentException(<<<'MESSAGE' + throw new \InvalidArgumentException(<<<'MESSAGE' Invalid Argument for DoctrineMigration check. If you are using doctrine/migrations ^3.0, pass Doctrine\Migrations\DependencyFactory as argument. If you are using doctrine/migrations ^2.0, pass Doctrine\Migrations\Configuration\Configuration as argument. @@ -88,25 +83,27 @@ public function check(): ResultInterface return new Skip('Check was skipped'); } - $notMigratedVersions = array_diff($this->availableVersions, $this->migratedVersions); + $notMigratedVersions = \array_diff($this->availableVersions, $this->migratedVersions); + if (! empty($notMigratedVersions)) { return new Failure( 'Not all migrations applied', - array_values(array_map('strval', $notMigratedVersions)) + \array_values(\array_map('strval', $notMigratedVersions)) ); } - $notAvailableVersions = array_diff($this->migratedVersions, $this->availableVersions); + $notAvailableVersions = \array_diff($this->migratedVersions, $this->availableVersions); + if (! empty($notAvailableVersions)) { return new Failure( 'Migrations applied which are not available', - array_values(array_map('strval', $notAvailableVersions)) + \array_values(\array_map('strval', $notAvailableVersions)) ); } return new Success( 'All migrations are correctly applied', - array_values(array_map('strval', $this->migratedVersions)) + \array_values(\array_map('strval', $this->migratedVersions)) ); } @@ -125,9 +122,10 @@ private function getAvailableVersionsFromDependencyFactory(DependencyFactory $de { $allMigrations = $dependencyFactory->getMigrationRepository()->getMigrations(); - return array_map(static function (AvailableMigration $availableMigration) { - return $availableMigration->getVersion(); - }, $allMigrations->getItems()); + return \array_map( + static fn (AvailableMigration $availableMigration) => $availableMigration->getVersion(), + $allMigrations->getItems() + ); } /** @@ -137,8 +135,9 @@ private function getMigratedVersionsFromDependencyFactory(DependencyFactory $dep { $executedMigrations = $dependencyFactory->getMetadataStorage()->getExecutedMigrations(); - return array_map(static function (ExecutedMigration $executedMigration) { - return $executedMigration->getVersion(); - }, $executedMigrations->getItems()); + return \array_map( + static fn (ExecutedMigration $executedMigration) => $executedMigration->getVersion(), + $executedMigrations->getItems() + ); } } diff --git a/src/PimcoreMonitorBundle/Check/HostingSize.php b/src/PimcoreMonitorBundle/Check/HostingSize.php index 38c73cb..8e7a01c 100644 --- a/src/PimcoreMonitorBundle/Check/HostingSize.php +++ b/src/PimcoreMonitorBundle/Check/HostingSize.php @@ -1,5 +1,20 @@ skip = $skip; - $this->warningThreshold = $warningThreshold; - $this->criticalThreshold = $criticalThreshold; - $this->path = $path; - } + public function __construct( + protected bool $skip, + protected int $warningThreshold, + protected int $criticalThreshold, + protected string $path + ) {} /** * {@inheritDoc} @@ -35,25 +44,20 @@ public function check(): ResultInterface } $size = $this->getDirectorySize(); + $data = [ + 'path' => $this->path, + 'size' => \formatBytes($size), + ]; if ($size >= $this->criticalThreshold) { - return new Failure(sprintf('Hosting size is too high: %s', formatBytes($size)), [ - 'path' => $this->path, - 'size' => formatBytes($size), - ]); + return new Failure(\sprintf('Hosting size is too high: %s', \formatBytes($size)), $data); } if ($size >= $this->warningThreshold) { - return new Warning(sprintf('Hosting size is high: %s', formatBytes($size)), [ - 'path' => $this->path, - 'size' => formatBytes($size), - ]); + return new Warning(\sprintf('Hosting size is high: %s', \formatBytes($size)), $data); } - return new Success(sprintf('Hosting size is %s', formatBytes($size)), [ - 'path' => $this->path, - 'size' => formatBytes($size), - ]); + return new Success(sprintf('Hosting size is %s', \formatBytes($size)), $data); } /** @@ -69,10 +73,10 @@ public function getLabel(): string */ private function getDirectorySize(): int { - $io = popen('/usr/bin/du -sk ' . $this->path, 'r'); - $size = fgets($io, 4096); - $size = (int) substr($size, 0, strpos($size, "\t")); - pclose($io); + $io = \popen('/usr/bin/du -sk ' . $this->path, 'r'); + $size = \fgets($io, 4096); + $size = (int) \substr($size, 0, \strpos($size, "\t")); + \pclose($io); return $size * 1024; } diff --git a/src/PimcoreMonitorBundle/Check/HttpsConnection.php b/src/PimcoreMonitorBundle/Check/HttpsConnection.php index d796d87..0e030c2 100644 --- a/src/PimcoreMonitorBundle/Check/HttpsConnection.php +++ b/src/PimcoreMonitorBundle/Check/HttpsConnection.php @@ -1,5 +1,20 @@ skip = $skip; - $this->systemConfig = $systemConfig; - } + public function __construct(protected bool $skip, protected array $systemConfig) {} /** * {@inheritDoc} @@ -37,15 +45,15 @@ public function check(): ResultInterface } // Create a stream context - $stream = stream_context_create(['ssl' => ['capture_peer_cert' => true]]); - $url = sprintf('https://%s', $host); + $stream = \stream_context_create(['ssl' => ['capture_peer_cert' => true]]); + $url = \sprintf('https://%s', $host); try { // Bind the resource $url to $stream - $read = fopen($url, 'rb', false, $stream); + $read = \fopen($url, 'rb', false, $stream); // Get the stream parameters - $params = stream_context_get_params($read); + $params = \stream_context_get_params($read); } catch (\Exception) { // Ignore exceptions thrown ... } diff --git a/src/PimcoreMonitorBundle/Check/MySqlVersion.php b/src/PimcoreMonitorBundle/Check/MySqlVersion.php index 4190617..0be3678 100644 --- a/src/PimcoreMonitorBundle/Check/MySqlVersion.php +++ b/src/PimcoreMonitorBundle/Check/MySqlVersion.php @@ -1,29 +1,38 @@ skip = $skip; - $this->version = $expectedVersion; - $this->operator = $operator; - $this->db = $db; - } + public function __construct( + protected bool $skip, + protected string $expectedVersion, + protected string $operator, + protected Connection $connection + ) {} /** * {@inheritDoc} @@ -35,17 +44,17 @@ public function check(): ResultInterface } try { - $mysqlVersion = $this->db->fetchOne('SELECT VERSION()'); + $mysqlVersion = $this->connection->fetchOne('SELECT VERSION()'); } catch (\Exception) { $mysqlVersion = null; } - if (! version_compare($mysqlVersion, $this->version, $this->operator)) { - return new Failure(sprintf( + if (! \version_compare($mysqlVersion, $this->expectedVersion, $this->operator)) { + return new Failure(\sprintf( 'Current MySQL version is %s, expected %s %s', $mysqlVersion, $this->operator, - $this->version + $this->expectedVersion ), $mysqlVersion); } diff --git a/src/PimcoreMonitorBundle/Check/PhpVersion.php b/src/PimcoreMonitorBundle/Check/PhpVersion.php index f86acf5..f9ca1c4 100644 --- a/src/PimcoreMonitorBundle/Check/PhpVersion.php +++ b/src/PimcoreMonitorBundle/Check/PhpVersion.php @@ -26,16 +26,7 @@ class PhpVersion extends AbstractCheck { protected const IDENTIFIER = 'system:php_version'; - protected bool $skip; - protected string $version; - protected string $operator; - - public function __construct(bool $skip, string $expectedVersion, string $operator) - { - $this->skip = $skip; - $this->version = $expectedVersion; - $this->operator = $operator; - } + public function __construct(protected bool $skip, protected string $expectedVersion, protected string $operator) {} /** * {@inheritDoc} @@ -46,12 +37,12 @@ public function check(): ResultInterface return new Skip('Check was skipped'); } - if (! version_compare(PHP_VERSION, $this->version, $this->operator)) { - return new Failure(sprintf( + if (! \version_compare(PHP_VERSION, $this->expectedVersion, $this->operator)) { + return new Failure(\sprintf( 'Current PHP version is %s, expected %s %s', PHP_VERSION, $this->operator, - $this->version + $this->expectedVersion ), PHP_VERSION); } diff --git a/src/PimcoreMonitorBundle/Check/PimcoreAreabricks.php b/src/PimcoreMonitorBundle/Check/PimcoreAreabricks.php index 6f3de94..5a30303 100644 --- a/src/PimcoreMonitorBundle/Check/PimcoreAreabricks.php +++ b/src/PimcoreMonitorBundle/Check/PimcoreAreabricks.php @@ -26,14 +26,7 @@ class PimcoreAreabricks extends AbstractCheck { protected const IDENTIFIER = 'pimcore:areabricks'; - protected bool $skip; - protected AreabrickManagerInterface $areabrickManager; - - public function __construct(bool $skip, AreabrickManagerInterface $areabrickManager) - { - $this->skip = $skip; - $this->areabrickManager = $areabrickManager; - } + public function __construct(protected bool $skip, protected AreabrickManagerInterface $areabrickManager) {} public function check(): ResultInterface { @@ -52,7 +45,7 @@ public function check(): ResultInterface ]; } - return new Success(sprintf('There are %s Areabricks in the system', \count($bricks)), $bricks); + return new Success(\sprintf('There are %s Areabricks in the system', \count($bricks)), $bricks); } public function getLabel(): string diff --git a/src/PimcoreMonitorBundle/Check/PimcoreBundles.php b/src/PimcoreMonitorBundle/Check/PimcoreBundles.php index 75b7fdf..4ded6c1 100644 --- a/src/PimcoreMonitorBundle/Check/PimcoreBundles.php +++ b/src/PimcoreMonitorBundle/Check/PimcoreBundles.php @@ -26,14 +26,7 @@ class PimcoreBundles extends AbstractCheck { protected const IDENTIFIER = 'pimcore:bundles'; - protected bool $skip; - protected PimcoreBundleManager $pimcoreBundleManager; - - public function __construct(bool $skip, PimcoreBundleManager $pimcoreBundleManager) - { - $this->skip = $skip; - $this->pimcoreBundleManager = $pimcoreBundleManager; - } + public function __construct(protected bool $skip, protected PimcoreBundleManager $pimcoreBundleManager) {} public function check(): ResultInterface { @@ -53,7 +46,7 @@ public function check(): ResultInterface ]; } - return new Success(sprintf('There are %s Pimcore bundles in the system', \count($bundles)), $bundles); + return new Success(\sprintf('There are %s Pimcore bundles in the system', \count($bundles)), $bundles); } public function getLabel(): string diff --git a/src/PimcoreMonitorBundle/Check/PimcoreElementCount.php b/src/PimcoreMonitorBundle/Check/PimcoreElementCount.php index a94ad81..bc13747 100644 --- a/src/PimcoreMonitorBundle/Check/PimcoreElementCount.php +++ b/src/PimcoreMonitorBundle/Check/PimcoreElementCount.php @@ -17,6 +17,7 @@ namespace Wvision\Bundle\PimcoreMonitorBundle\Check; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\Exception as DBALDriverException; use Doctrine\DBAL\Exception as DBALException; use Laminas\Diagnostics\Result\Failure; @@ -24,24 +25,17 @@ use Laminas\Diagnostics\Result\Skip; use Laminas\Diagnostics\Result\Success; use Laminas\Diagnostics\Result\Warning; -use Pimcore\Db\ConnectionInterface; class PimcoreElementCount extends AbstractCheck { protected const IDENTIFIER = 'pimcore:element_count'; - protected bool $skip; - protected int $warningThreshold; - protected int $criticalThreshold; - protected ConnectionInterface $connection; - - public function __construct(bool $skip, int $warningThreshold, int $criticalThreshold, ConnectionInterface $connection) - { - $this->skip = $skip; - $this->warningThreshold = $warningThreshold; - $this->criticalThreshold = $criticalThreshold; - $this->connection = $connection; - } + public function __construct( + protected bool $skip, + protected int $warningThreshold, + protected int $criticalThreshold, + protected Connection $connection + ) {} public function check(): ResultInterface { @@ -54,30 +48,22 @@ public function check(): ResultInterface $objectCount = $this->getTableRowCount('objects', 'o_id'); $totalCount = $documentCount + $assetCount + $objectCount; + $data = [ + 'documents' => $documentCount, + 'assets' => $assetCount, + 'objects' => $objectCount, + 'total' => $totalCount, + ]; + if ($totalCount >= $this->criticalThreshold) { - return new Failure(sprintf('Element count too high: %s', $totalCount), [ - 'documents' => $documentCount, - 'assets' => $assetCount, - 'objects' => $objectCount, - 'total' => $totalCount, - ]); + return new Failure(\sprintf('Element count too high: %s', $totalCount), $data); } if ($totalCount >= $this->warningThreshold) { - return new Warning(sprintf('Element count high: %s', $totalCount), [ - 'documents' => $documentCount, - 'assets' => $assetCount, - 'objects' => $objectCount, - 'total' => $totalCount, - ]); + return new Warning(\sprintf('Element count high: %s', $totalCount), $data); } - return new Success(sprintf('There are %s Pimcore elements in the system', $totalCount), [ - 'documents' => $documentCount, - 'assets' => $assetCount, - 'objects' => $objectCount, - 'total' => $totalCount, - ]); + return new Success(\sprintf('There are %s Pimcore elements in the system', $totalCount), $data); } public function getLabel(): string @@ -93,7 +79,7 @@ protected function getTableRowCount(string $tableName, string $idColumn): int try { $count = $qb->execute()->fetchOne(); - } catch (DBALException | DBALDriverException $e) { + } catch (DBALException | DBALDriverException) { $count = 0; } diff --git a/src/PimcoreMonitorBundle/Check/PimcoreMaintenance.php b/src/PimcoreMonitorBundle/Check/PimcoreMaintenance.php index 9894100..21801ff 100644 --- a/src/PimcoreMonitorBundle/Check/PimcoreMaintenance.php +++ b/src/PimcoreMonitorBundle/Check/PimcoreMaintenance.php @@ -28,14 +28,7 @@ class PimcoreMaintenance extends AbstractCheck { protected const IDENTIFIER = 'pimcore:maintenance'; - protected bool $skip; - protected ExecutorInterface $maintenanceExecutor; - - public function __construct(bool $skip, ExecutorInterface $maintenanceExecutor) - { - $this->skip = $skip; - $this->maintenanceExecutor = $maintenanceExecutor; - } + public function __construct(protected bool $skip, protected ExecutorInterface $maintenanceExecutor) {} /** * {@inheritDoc} @@ -54,7 +47,7 @@ public function check(): ResultInterface ]; // Maintenance script should run at least every hour + a little tolerance - if ($lastExecution && (time() - $lastExecution) < 3660) { + if ($lastExecution && (\time() - $lastExecution) < 3660) { $data['active'] = true; return new Success('Pimcore maintenance is activated', $data); diff --git a/src/PimcoreMonitorBundle/Check/PimcoreUsers.php b/src/PimcoreMonitorBundle/Check/PimcoreUsers.php index 3976586..4bfc6fd 100644 --- a/src/PimcoreMonitorBundle/Check/PimcoreUsers.php +++ b/src/PimcoreMonitorBundle/Check/PimcoreUsers.php @@ -27,12 +27,7 @@ class PimcoreUsers extends AbstractCheck { protected const IDENTIFIER = 'pimcore:users'; - protected bool $skip; - - public function __construct(bool $skip) - { - $this->skip = $skip; - } + public function __construct(protected bool $skip) {} /** * {@inheritDoc} @@ -62,7 +57,7 @@ public function check(): ResultInterface ]; } - return new Success(sprintf('There are %s Pimcore users in the system', \count($users)), $users); + return new Success(\sprintf('There are %s Pimcore users in the system', \count($users)), $users); } /** diff --git a/src/PimcoreMonitorBundle/Check/PimcoreVersion.php b/src/PimcoreMonitorBundle/Check/PimcoreVersion.php index f525e25..7c2644d 100644 --- a/src/PimcoreMonitorBundle/Check/PimcoreVersion.php +++ b/src/PimcoreMonitorBundle/Check/PimcoreVersion.php @@ -26,12 +26,7 @@ class PimcoreVersion extends AbstractCheck { protected const IDENTIFIER = 'pimcore:version'; - protected bool $skip; - - public function __construct(bool $skip) - { - $this->skip = $skip; - } + public function __construct(protected bool $skip) {} /** * {@inheritDoc} @@ -42,11 +37,12 @@ public function check(): ResultInterface return new Skip('Check was skipped'); } - $version = InstalledVersions::getPrettyVersion('pimcore/pimcore'); + $packageName = 'pimcore/pimcore'; + $version = InstalledVersions::getPrettyVersion($packageName); - return new Success(sprintf('The system is running on Pimcore %s', $version), [ + return new Success(\sprintf('The system is running on Pimcore %s', $version), [ 'semver' => $version, - 'reference' => InstalledVersions::getReference('pimcore/pimcore'), + 'reference' => InstalledVersions::getReference($packageName), ]); } diff --git a/src/PimcoreMonitorBundle/Command/HealthCheckCommand.php b/src/PimcoreMonitorBundle/Command/HealthCheckCommand.php index 1b02409..b026d47 100644 --- a/src/PimcoreMonitorBundle/Command/HealthCheckCommand.php +++ b/src/PimcoreMonitorBundle/Command/HealthCheckCommand.php @@ -27,13 +27,9 @@ class HealthCheckCommand extends Command { protected static $defaultName = 'pimcore:monitor:health-check'; - private RunnerManager $runnerManager; - - public function __construct(RunnerManager $runnerManager) + public function __construct(private RunnerManager $runnerManager) { parent::__construct(); - - $this->runnerManager = $runnerManager; } protected function execute(InputInterface $input, OutputInterface $output): int diff --git a/src/PimcoreMonitorBundle/Command/HealthReportCommand.php b/src/PimcoreMonitorBundle/Command/HealthReportCommand.php index 1e9a62b..5933200 100644 --- a/src/PimcoreMonitorBundle/Command/HealthReportCommand.php +++ b/src/PimcoreMonitorBundle/Command/HealthReportCommand.php @@ -34,30 +34,15 @@ class HealthReportCommand extends Command { protected static $defaultName = 'pimcore:monitor:health-report'; - private string $reportEndpoint; - private string $apiKey; - private array $pimcoreSystemConfig; - private string $secret; - private HttpClientInterface $httpClient; - private RunnerManager $runnerManager; - public function __construct( - string $reportEndpoint, - string $apiKey, - array $pimcoreSystemConfig, - string $secret, - HttpClientInterface $httpClient, - RunnerManager $runnerManager + private string $reportEndpoint, + private string $apiKey, + private array $pimcoreSystemConfig, + private string $secret, + private HttpClientInterface $httpClient, + private RunnerManager $runnerManager ) { - $this->reportEndpoint = $reportEndpoint; - parent::__construct(); - - $this->apiKey = $apiKey; - $this->pimcoreSystemConfig = $pimcoreSystemConfig; - $this->secret = $secret; - $this->httpClient = $httpClient; - $this->runnerManager = $runnerManager; } protected function configure(): void @@ -126,15 +111,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int ], ]); $payload = $response->toArray(); - } catch (TransportExceptionInterface | ClientExceptionInterface | DecodingExceptionInterface | RedirectionExceptionInterface | ServerExceptionInterface $e) { + } catch ( + TransportExceptionInterface | + ClientExceptionInterface | + DecodingExceptionInterface | + RedirectionExceptionInterface | + ServerExceptionInterface $e + ) { $output->writeln( - sprintf('Sending the data to the endpoint failed! – %s', $e->getMessage()) + \sprintf('Sending the data to the endpoint failed! – %s', $e->getMessage()) ); return Command::FAILURE; } - $output->writeln(sprintf('%s: %s', $payload['status'], $payload['message'])); + $output->writeln(\sprintf('%s: %s', $payload['status'], $payload['message'])); return $response->getStatusCode() === 200 ? Command::SUCCESS : Command::FAILURE; } @@ -146,7 +137,7 @@ private function getInstanceId(): ?string } try { - $instanceId = sha1(substr($this->secret, 3, -3)); + $instanceId = \sha1(\substr($this->secret, 3, -3)); } catch (\Exception) { $instanceId = null; } diff --git a/src/PimcoreMonitorBundle/Controller/Admin/HealthCheckController.php b/src/PimcoreMonitorBundle/Controller/Admin/HealthCheckController.php index 6ba361d..15b87ae 100644 --- a/src/PimcoreMonitorBundle/Controller/Admin/HealthCheckController.php +++ b/src/PimcoreMonitorBundle/Controller/Admin/HealthCheckController.php @@ -73,7 +73,7 @@ public function status(RunnerManager $runnerManager): Response $results = $reporter->getResults(); - return $this->render('@PimcoreMonitor/Admin/Health/status.html.twig', [ + return $this->render('@PimcoreMonitor/admin/health/status.html.twig', [ 'results' => $results, ]); } diff --git a/src/PimcoreMonitorBundle/DependencyInjection/Compiler/CheckTagCompilerPass.php b/src/PimcoreMonitorBundle/DependencyInjection/Compiler/CheckTagCompilerPass.php index 26acf8b..6c08517 100644 --- a/src/PimcoreMonitorBundle/DependencyInjection/Compiler/CheckTagCompilerPass.php +++ b/src/PimcoreMonitorBundle/DependencyInjection/Compiler/CheckTagCompilerPass.php @@ -31,7 +31,7 @@ public function process(ContainerBuilder $container): void foreach ($container->findTaggedServiceIds('pimcore_monitor.check') as $id => $tags) { foreach ($tags as $attributes) { $alias = empty($attributes['alias']) ? $id : $attributes['alias']; - $enabledParamName = sprintf('pimcore_monitor.checks.%s.enabled', $alias); + $enabledParamName = \sprintf('pimcore_monitor.checks.%s.enabled', $alias); if ($container->hasParameter($enabledParamName) && $container->getParameter($enabledParamName)) { $runnerDefinition = $container->getDefinition('pimcore_monitor.runner'); diff --git a/src/PimcoreMonitorBundle/DependencyInjection/PimcoreMonitorExtension.php b/src/PimcoreMonitorBundle/DependencyInjection/PimcoreMonitorExtension.php index fd6f421..666345f 100644 --- a/src/PimcoreMonitorBundle/DependencyInjection/PimcoreMonitorExtension.php +++ b/src/PimcoreMonitorBundle/DependencyInjection/PimcoreMonitorExtension.php @@ -17,7 +17,6 @@ namespace Wvision\Bundle\PimcoreMonitorBundle\DependencyInjection; -use Exception; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\Extension; @@ -28,7 +27,7 @@ class PimcoreMonitorExtension extends Extension /** * {@inheritdoc} * - * @throws Exception + * @throws \Exception */ public function load(array $configs, ContainerBuilder $container): void { @@ -38,7 +37,7 @@ public function load(array $configs, ContainerBuilder $container): void // Register report parameters foreach ($config['report'] ?? [] as $confName => $confValue) { $container->setParameter( - sprintf('pimcore_monitor.report.%s', $confName), + \sprintf('pimcore_monitor.report.%s', $confName), $confValue ); } @@ -47,7 +46,7 @@ public function load(array $configs, ContainerBuilder $container): void foreach ($config['checks'] ?? [] as $checkName => $checkConfig) { foreach ($checkConfig as $confName => $confValue) { $container->setParameter( - sprintf('pimcore_monitor.checks.%s.%s', $checkName, $confName), + \sprintf('pimcore_monitor.checks.%s.%s', $checkName, $confName), $confValue ); } diff --git a/src/PimcoreMonitorBundle/Manager/RunnerManager.php b/src/PimcoreMonitorBundle/Manager/RunnerManager.php index 8addaf3..0e1f742 100644 --- a/src/PimcoreMonitorBundle/Manager/RunnerManager.php +++ b/src/PimcoreMonitorBundle/Manager/RunnerManager.php @@ -22,12 +22,7 @@ class RunnerManager { - protected ContainerInterface $container; - - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } + public function __construct(protected ContainerInterface $container) {} public function getRunner(): Runner { diff --git a/src/PimcoreMonitorBundle/PimcoreMonitorBundle.php b/src/PimcoreMonitorBundle/PimcoreMonitorBundle.php index 644bb9d..fad5b34 100644 --- a/src/PimcoreMonitorBundle/PimcoreMonitorBundle.php +++ b/src/PimcoreMonitorBundle/PimcoreMonitorBundle.php @@ -61,7 +61,6 @@ public function getCssPaths(): array ]; } - /** * {@inheritDoc} */ @@ -77,8 +76,9 @@ public function getJsPaths(): array */ public function build(ContainerBuilder $container): void { - if (method_exists($container, 'registerForAutoconfiguration')) { - $container->registerForAutoconfiguration(CheckInterface::class) + if (\method_exists($container, 'registerForAutoconfiguration')) { + $container + ->registerForAutoconfiguration(CheckInterface::class) ->addTag('pimcore_monitor.check'); } diff --git a/src/PimcoreMonitorBundle/Reporter/ArrayReporter.php b/src/PimcoreMonitorBundle/Reporter/ArrayReporter.php index 19ec0b5..8b982d2 100644 --- a/src/PimcoreMonitorBundle/Reporter/ArrayReporter.php +++ b/src/PimcoreMonitorBundle/Reporter/ArrayReporter.php @@ -33,16 +33,12 @@ class ArrayReporter implements ReporterInterface protected string $globalStatus = self::STATUS_OK; protected array $results = []; - protected bool $flattenOutput; - protected array $excludeChecks; - protected array $includeChecks; - public function __construct(bool $flattenOutput = false, array $excludeChecks = [], array $includeChecks = []) - { - $this->flattenOutput = $flattenOutput; - $this->excludeChecks = $excludeChecks; - $this->includeChecks = $includeChecks; - } + public function __construct( + protected bool $flattenOutput = false, + protected array $excludeChecks = [], + protected array $includeChecks = [] + ) {} public function getResults(): array { @@ -112,7 +108,7 @@ public function onAfterRun(BaseCheckInterface|CheckInterface $check, ResultInter $this->results[] = $data; } else { $temp =& $this->results; - foreach (explode(':', $check->getIdentifier()) as $key) { + foreach (\explode(':', $check->getIdentifier()) as $key) { $temp =& $temp[$key]; } diff --git a/src/PimcoreMonitorBundle/Resources/config/services.yaml b/src/PimcoreMonitorBundle/Resources/config/services.yaml index 4d58b78..8b60bab 100644 --- a/src/PimcoreMonitorBundle/Resources/config/services.yaml +++ b/src/PimcoreMonitorBundle/Resources/config/services.yaml @@ -16,5 +16,5 @@ services: # Runner pimcore_monitor.runner: - class: Wvision\Bundle\PimcoreMonitorBundle\Runner\Runner + class: Laminas\Diagnostics\Runner\Runner public: true diff --git a/src/PimcoreMonitorBundle/Resources/config/services/checks.yaml b/src/PimcoreMonitorBundle/Resources/config/services/checks.yaml index 72fb25a..b955e35 100644 --- a/src/PimcoreMonitorBundle/Resources/config/services/checks.yaml +++ b/src/PimcoreMonitorBundle/Resources/config/services/checks.yaml @@ -50,7 +50,7 @@ services: - '%pimcore_monitor.checks.mysql_version.skip%' - '%pimcore_monitor.checks.mysql_version.version%' - '%pimcore_monitor.checks.mysql_version.operator%' - - '@Pimcore\Db\ConnectionInterface' + - '@doctrine.dbal.default_connection' tags: - { name: pimcore_monitor.check, alias: mysql_version } @@ -85,7 +85,7 @@ services: - '%pimcore_monitor.checks.pimcore_element_count.skip%' - '%pimcore_monitor.checks.pimcore_element_count.warning_threshold%' - '%pimcore_monitor.checks.pimcore_element_count.critical_threshold%' - - '@Pimcore\Db\ConnectionInterface' + - '@doctrine.dbal.default_connection' tags: - { name: pimcore_monitor.check, alias: pimcore_element_count } diff --git a/src/PimcoreMonitorBundle/Resources/views/Admin/Health/status.html.twig b/src/PimcoreMonitorBundle/Resources/views/admin/health/status.html.twig similarity index 89% rename from src/PimcoreMonitorBundle/Resources/views/Admin/Health/status.html.twig rename to src/PimcoreMonitorBundle/Resources/views/admin/health/status.html.twig index db9873f..0f73060 100644 --- a/src/PimcoreMonitorBundle/Resources/views/Admin/Health/status.html.twig +++ b/src/PimcoreMonitorBundle/Resources/views/admin/health/status.html.twig @@ -1,13 +1,13 @@ - + System Health Status - - + +
@@ -15,7 +15,7 @@

System Health Status

- {% if results is defined and results is not empty %} + {% if results is iterable and results is not empty %} - {% if results is defined and results is not empty %} + {% if results is iterable and results is not empty %}
diff --git a/src/PimcoreMonitorBundle/Runner/Runner.php b/src/PimcoreMonitorBundle/Runner/Runner.php deleted file mode 100644 index 294ae8c..0000000 --- a/src/PimcoreMonitorBundle/Runner/Runner.php +++ /dev/null @@ -1,24 +0,0 @@ -