Skip to content

Commit

Permalink
Method refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Feb 12, 2024
1 parent a5cde6a commit 3ced84c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
14 changes: 2 additions & 12 deletions src/controllers/DiagnosticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,13 @@ public function beforeAction($action): bool

public function actionIndex(string $path): Response
{
Craft::$app->getView()->registerAssetBundle(BlitzAsset::class);

Sprig::bootstrap();
Sprig::$core->components->setConfig(['requestClass' => 'busy']);

$siteId = null;
$site = Craft::$app->getRequest()->getParam('site');
if ($site) {
$site = Craft::$app->getSites()->getSiteByHandle($site);
$siteId = $site ? $site->id : null;
}
if (empty($siteId)) {
$siteId = Craft::$app->getSites()->getCurrentSite()->id;
}
Craft::$app->getView()->registerAssetBundle(BlitzAsset::class);

return $this->renderTemplate('blitz/_utilities/diagnostics/' . $path, [
'siteId' => $siteId,
'siteId' => DiagnosticsHelper::getSiteId(),
]);
}

Expand Down
15 changes: 15 additions & 0 deletions src/helpers/DiagnosticsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
*/
class DiagnosticsHelper
{
public static function getSiteId(): ?int
{
$siteId = null;
$site = Craft::$app->getRequest()->getParam('site');
if ($site) {
$site = Craft::$app->getSites()->getSiteByHandle($site);
$siteId = $site ? $site->id : null;
}
if (empty($siteId)) {
$siteId = Craft::$app->getSites()->getCurrentSite()->id;
}

return $siteId;
}

public static function getPagesCount(int $siteId): int
{
return CacheRecord::find()
Expand Down
13 changes: 2 additions & 11 deletions src/utilities/DiagnosticsUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Craft;
use craft\base\Utility;
use putyourlightson\blitz\assets\BlitzAsset;
use putyourlightson\blitz\helpers\DiagnosticsHelper;

/**
* @since 4.10.0
Expand Down Expand Up @@ -51,18 +52,8 @@ public static function contentHtml(): string
{
Craft::$app->getView()->registerAssetBundle(BlitzAsset::class);

$siteId = null;
$site = Craft::$app->getRequest()->getParam('site');
if ($site) {
$site = Craft::$app->getSites()->getSiteByHandle($site);
$siteId = $site ? $site->id : null;
}
if (empty($siteId)) {
$siteId = Craft::$app->getSites()->getCurrentSite()->id;
}

return Craft::$app->getView()->renderTemplate('blitz/_utilities/diagnostics/', [
'siteId' => $siteId,
'siteId' => DiagnosticsHelper::getSiteId(),
]);
}
}

0 comments on commit 3ced84c

Please sign in to comment.