Skip to content

Commit

Permalink
refactor: make phpstan happy
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongerig committed Feb 8, 2023
1 parent 29b2a14 commit 449abee
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/PimcoreMonitorBundle/Check/AbstractCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

abstract class AbstractCheck implements BaseCheckInterface, CheckInterface
{
protected const IDENTIFIER = '__undefined__';

/**
* {@inheritDoc}
*/
Expand Down
4 changes: 2 additions & 2 deletions src/PimcoreMonitorBundle/Check/DiskUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function check(): ResultInterface
return new Skip('Check was skipped');
}

$df = \disk_free_space($this->path);
$dt = \disk_total_space($this->path);
$df = (int) \floor(\disk_free_space($this->path));
$dt = (int) \floor(\disk_total_space($this->path));
$du = $dt - $df;
$dp = ($du / $dt) * 100;

Expand Down
5 changes: 2 additions & 3 deletions src/PimcoreMonitorBundle/Check/PimcoreMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ public function check(): ResultInterface
}

$lastExecution = $this->maintenanceExecutor->getLastExecution();
$lastRun = Carbon::createFromTimestampUTC($lastExecution);
$data = [
'active' => false,
'last_execution' => $lastRun instanceof Carbon ? $lastRun->toIso8601String() : $lastExecution,
'last_execution' => Carbon::createFromTimestampUTC($lastExecution)->toIso8601String(),
];

// Maintenance script should run at least every hour + a little tolerance
if ($lastExecution && (\time() - $lastExecution) < 3660) {
if ($lastExecution > 0 && (\time() - $lastExecution) < 3660) {
$data['active'] = true;

return new Success('Pimcore maintenance is activated', $data);
Expand Down
5 changes: 2 additions & 3 deletions src/PimcoreMonitorBundle/Check/PimcoreUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ public function check(): ResultInterface
continue;
}

$lastLoginTs = $user->getLastLogin();
$lastLogin = Carbon::createFromTimestampUTC($lastLoginTs);
$lastLogin = $user->getLastLogin();

$users[] = [
'name' => $user->getName(),
'active' => $user->isActive(),
'is_admin' => $user->isAdmin(),
'last_login' => $lastLogin instanceof Carbon ? $lastLogin->toIso8601String() : $lastLoginTs,
'last_login' => Carbon::createFromTimestampUTC($lastLogin)->toIso8601String(),
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/PimcoreMonitorBundle/Command/HealthReportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HealthReportCommand extends Command
public function __construct(
private string $reportEndpoint,
private string $apiKey,
private array $pimcoreSystemConfig,
private array $systemConfig,
private string $secret,
private HttpClientInterface $httpClient,
private RunnerManager $runnerManager
Expand Down Expand Up @@ -77,7 +77,7 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$instanceId = $this->getInstanceId();
$hostDomain = $this->pimcoreSystemConfig['general']['domain'];
$hostDomain = $this->systemConfig['general']['domain'];

if (null === $instanceId) {
$output->writeln('<comment>Please define the secret parameter.</comment>');
Expand Down
16 changes: 8 additions & 8 deletions src/PimcoreMonitorBundle/PimcoreMonitorBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ class PimcoreMonitorBundle extends AbstractPimcoreBundle
{
use PackageVersionTrait;

/**
* {@inheritDoc}
*/
protected function getComposerPackageName(): string
{
return 'w-vision/pimcore-monitor-bundle';
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -84,4 +76,12 @@ public function build(ContainerBuilder $container): void

$container->addCompilerPass(new CheckTagCompilerPass());
}

/**
* {@inheritDoc}
*/
protected function getComposerPackageName(): string
{
return 'w-vision/pimcore-monitor-bundle';
}
}
5 changes: 5 additions & 0 deletions src/PimcoreMonitorBundle/Reporter/ArrayReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Laminas\Diagnostics\Result\SuccessInterface;
use Laminas\Diagnostics\Result\WarningInterface;
use Laminas\Diagnostics\Runner\Reporter\ReporterInterface;
use Pimcore\Tool\Requirements\Check;
use Wvision\Bundle\PimcoreMonitorBundle\Check\CheckInterface;

class ArrayReporter implements ReporterInterface
Expand Down Expand Up @@ -72,6 +73,10 @@ public function onBeforeRun(BaseCheckInterface|CheckInterface $check, $checkAlia

public function onAfterRun(BaseCheckInterface|CheckInterface $check, ResultInterface $result, $checkAlias = null)
{
if (!$check instanceof CheckInterface) {
return;
}

switch (true) {
case $result instanceof SuccessInterface:
$status = 0;
Expand Down

0 comments on commit 449abee

Please sign in to comment.