Skip to content

Commit

Permalink
refactor: PHPstan code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Feb 8, 2024
1 parent b5fac27 commit 86d46c2
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 37 deletions.
24 changes: 12 additions & 12 deletions src/Webperf.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ protected function installEventListeners(): void
Event::on(
Plugins::class,
Plugins::EVENT_AFTER_INSTALL_PLUGIN,
function (PluginEvent $event) {
function(PluginEvent $event) {
if ($event->plugin === $this) {
// Invalidate our caches after we've been installed
$this->clearAllCaches();
Expand Down Expand Up @@ -355,7 +355,7 @@ protected function installGlobalEventListeners(): void
Event::on(
CraftVariable::class,
CraftVariable::EVENT_INIT,
function (Event $event) {
function(Event $event) {
/** @var CraftVariable $variable */
$variable = $event->sender;
$variable->set('webperf', [
Expand All @@ -368,7 +368,7 @@ function (Event $event) {
Event::on(
Plugins::class,
Plugins::EVENT_AFTER_LOAD_PLUGINS,
function () {
function() {
// Install these only after all other plugins have loaded
$request = Craft::$app->getRequest();
// Only respond to non-console site requests
Expand All @@ -392,7 +392,7 @@ protected function installSiteEventListeners(): void
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_SITE_URL_RULES,
function (RegisterUrlRulesEvent $event) {
function(RegisterUrlRulesEvent $event) {
Craft::debug(
'UrlManager::EVENT_REGISTER_SITE_URL_RULES',
__METHOD__
Expand All @@ -415,7 +415,7 @@ protected function installCpEventListeners(): void
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_CP_URL_RULES,
function (RegisterUrlRulesEvent $event) {
function(RegisterUrlRulesEvent $event) {
Craft::debug(
'UrlManager::EVENT_REGISTER_CP_URL_RULES',
__METHOD__
Expand All @@ -431,7 +431,7 @@ function (RegisterUrlRulesEvent $event) {
Event::on(
UserPermissions::class,
UserPermissions::EVENT_REGISTER_PERMISSIONS,
function (RegisterUserPermissionsEvent $event) {
function(RegisterUserPermissionsEvent $event) {
Craft::debug(
'UserPermissions::EVENT_REGISTER_PERMISSIONS',
__METHOD__
Expand Down Expand Up @@ -464,7 +464,7 @@ protected function handleSiteRequest(): void
Event::on(
View::class,
View::EVENT_END_PAGE,
static function () {
static function() {
Craft::debug(
'View::EVENT_END_PAGE',
__METHOD__
Expand Down Expand Up @@ -492,7 +492,7 @@ static function () {
Event::on(
View::class,
View::EVENT_END_BODY,
static function () {
static function() {
Craft::debug(
'View::EVENT_END_BODY',
__METHOD__
Expand All @@ -515,7 +515,7 @@ static function () {
Event::on(
Application::class,
Application::EVENT_AFTER_REQUEST,
function () {
function() {
Craft::debug(
'Application::EVENT_AFTER_REQUEST',
__METHOD__
Expand All @@ -540,7 +540,7 @@ protected function handleAdminCpRequest(): void
Event::on(
Element::class,
Element::EVENT_DEFINE_SIDEBAR_HTML,
function (DefineHtmlEvent $event) {
function(DefineHtmlEvent $event) {
Craft::debug(
'Element::EVENT_DEFINE_SIDEBAR_HTML',
__METHOD__
Expand Down Expand Up @@ -738,7 +738,7 @@ protected function getRecommendationsCount(): string
{
$cache = Craft::$app->getCache();
// See if there are any recommendations to add as a badge
$recommendations = $cache->getOrSet(self::RECOMMENDATIONS_CACHE_KEY, function () {
$recommendations = $cache->getOrSet(self::RECOMMENDATIONS_CACHE_KEY, function() {
$data = [];
$now = new DateTime();
$end = $now->format('Y-m-d');
Expand Down Expand Up @@ -768,7 +768,7 @@ protected function getErrorsCount(): string
{
$cache = Craft::$app->getCache();
// See if there are any recommendations to add as a badge
$errors = $cache->getOrSet(self::ERRORS_CACHE_KEY, function () {
$errors = $cache->getOrSet(self::ERRORS_CACHE_KEY, function() {
$now = new DateTime();
$end = $now->format('Y-m-d');
$start = $now->modify('-30 days')->format('Y-m-d');
Expand Down
12 changes: 4 additions & 8 deletions src/controllers/ChartsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public function actionDashboardStatsAverage(
string $column = 'pageLoad',
$pageUrl = '',
int $siteId = 0,
): Response
{
): Response {
PermissionHelper::controllerPermissionCheck('webperf:dashboard');
$data = [];
if (empty($end) || empty($start)) {
Expand Down Expand Up @@ -117,8 +116,7 @@ public function actionDashboardSlowestPages(
string $column = 'pageLoad',
int $limit = 3,
int $siteId = 0,
): Response
{
): Response {
PermissionHelper::controllerPermissionCheck('webperf:dashboard');
$data = [];
// Add a day since YYYY-MM-DD is really YYYY-MM-DD 00:00:00
Expand Down Expand Up @@ -180,8 +178,7 @@ public function actionPagesAreaChart(
string $end,
$pageUrl = '',
int $siteId = 0,
): Response
{
): Response {
PermissionHelper::controllerPermissionCheck('webperf:dashboard');
$data = [];
// Add a day since YYYY-MM-DD is really YYYY-MM-DD 00:00:00
Expand Down Expand Up @@ -315,8 +312,7 @@ public function actionErrorsAreaChart(
string $end,
$pageUrl = '',
int $siteId = 0,
): Response
{
): Response {
PermissionHelper::controllerPermissionCheck('webperf:errors');
$data = [];
// Add a day since YYYY-MM-DD is really YYYY-MM-DD 00:00:00
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/RecommendationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public function actionList(
string $start = '',
string $end = '',
$siteId = 0,
): Response
{
): Response {
PermissionHelper::controllerPermissionCheck('webperf:recommendations');
$data = [];
$stats = Webperf::$plugin->recommendations->data($pageUrl, $start, $end, $siteId);
Expand Down
12 changes: 4 additions & 8 deletions src/controllers/TablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ public function actionPagesIndex(
int $per_page = 20,
$filter = '',
$siteId = 0,
): Response
{
): Response {
PermissionHelper::controllerPermissionCheck('webperf:performance');
$data = [];
$sortField = 'pageLoad';
Expand Down Expand Up @@ -267,8 +266,7 @@ public function actionPageDetail(
$filter = '',
$pageUrl = '',
$siteId = 0,
): Response
{
): Response {
PermissionHelper::controllerPermissionCheck('webperf:performance');
$data = [];
$sortField = 'pageLoad';
Expand Down Expand Up @@ -403,8 +401,7 @@ public function actionErrorsIndex(
int $per_page = 20,
$filter = '',
$siteId = 0,
): Response
{
): Response {
PermissionHelper::controllerPermissionCheck('webperf:errors');
$data = [];
$sortField = 'url';
Expand Down Expand Up @@ -550,8 +547,7 @@ public function actionErrorsDetail(
$filter = '',
$pageUrl = '',
$siteId = 0,
): Response
{
): Response {
PermissionHelper::controllerPermissionCheck('webperf:errors');
$data = [];
$sortField = 'dateCreated';
Expand Down
1 change: 0 additions & 1 deletion src/helpers/MultiSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static function setSitesMenuVariables(array &$variables)
// Enabled sites
$sites = Craft::$app->getSites();
if (Craft::$app->getIsMultiSite()) {

foreach ($sites->getAllGroups() as $group) {
$groupSites = $sites->getSitesByGroupId($group->id);
$variables['sitesMenu'][$group->name]
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/PluginTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ public static function renderPluginTemplate(
$htmlText = Craft::$app->view->renderTemplate('webperf/' . $templatePath, $params);
if ($minifier) {
// If Minify is installed, minify the html
/** @var ?Minify $minify */
/** @var Minify|null $minify */
$minify = Craft::$app->getPlugins()->getPlugin(self::MINIFY_PLUGIN_HANDLE);
if ($minify) {
$htmlText = Minify::$plugin->minify->$minifier($htmlText);
/** @phpstan-ignore-next-line */
$htmlText = $minify->minify->$minifier($htmlText);
}
}
} catch (\Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function init(): void
{
parent::init();
// If Blitz is installed & enabled, flip the $staticCachedSite on
/** @var Blitz $blitz */
/** @var Blitz|null $blitz */
$blitz = Craft::$app->getPlugins()->getPlugin(self::BLITZ_PLUGIN_HANDLE);
if ($blitz && $blitz->settings->cachingEnabled) {
$this->staticCachedSite = true;
Expand Down
7 changes: 4 additions & 3 deletions src/services/DataSamples.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
use craft\db\Query;
use Exception;
use nystudio107\webperf\base\CraftDataSample;
use nystudio107\webperf\base\DbDataSampleInterface;
use nystudio107\webperf\events\DataSampleEvent;
use nystudio107\webperf\models\BoomerangDbDataSample;
use nystudio107\webperf\models\CraftDbDataSample;
use nystudio107\webperf\Webperf;

/**
Expand Down Expand Up @@ -125,9 +126,9 @@ public function pageTitle(string $url, int $siteId = 0): string
/**
* Add a data sample to the webperf_data_samples table
*
* @param DbDataSampleInterface $dataSample
* @param BoomerangDbDataSample|CraftDbDataSample $dataSample
*/
public function addDataSample(DbDataSampleInterface $dataSample)
public function addDataSample(BoomerangDbDataSample|CraftDbDataSample $dataSample)
{
// Validate the model before saving it to the db
if ($dataSample->validate() === false) {
Expand Down

0 comments on commit 86d46c2

Please sign in to comment.