Skip to content

Commit

Permalink
Merge pull request #4 from humhub-contrib/enh/php-cs-fixer
Browse files Browse the repository at this point in the history
Use PHP CS Fixer
  • Loading branch information
luke- authored Oct 11, 2024
2 parents aa22a10 + a6b897f commit 043772c
Show file tree
Hide file tree
Showing 38 changed files with 118 additions and 125 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: PHP CS Fixer

on: push

jobs:
fixers:
uses: humhub/actions/.github/workflows/module-php-cs-fixer.yml@main
1 change: 0 additions & 1 deletion Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class Events extends BaseObject
{

}
4 changes: 2 additions & 2 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace humhub\modules\profiler;

use Yii;
use yii\helpers\Url;
use Yii;
use yii\helpers\Url;

class Module extends \humhub\components\Module
{
Expand Down
6 changes: 3 additions & 3 deletions config.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [
'id' => 'profiler',
'class' => 'humhub\modules\profiler\Module',
'namespace' => 'humhub\modules\profiler',
'id' => 'profiler',
'class' => 'humhub\modules\profiler\Module',
'namespace' => 'humhub\modules\profiler',
];
37 changes: 17 additions & 20 deletions controllers/DashboardStreamController.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?php


namespace humhub\modules\profiler\controllers;


use humhub\modules\content\models\Content;
use humhub\modules\dashboard\stream\DashboardStreamQuery;

use humhub\modules\dashboard\stream\DeprecatedDashboardStreamQuery;
use humhub\modules\profiler\models\ProfilerResult;

Expand All @@ -25,13 +22,13 @@ public function options($actionID)

public function actionRunGuest()
{
$result = $this->runProfiler(function(ProfilerResult $result) {
$query = new DashboardStreamQuery(['activity' => (boolean) $this->activity]);
$result = $this->runProfiler(function (ProfilerResult $result) {
$query = new DashboardStreamQuery(['activity' => (bool) $this->activity]);
$result->setResult($query->all());
}, $this->title);

$competing = $this->runProfiler(function(ProfilerResult $result) {
$query = new DeprecatedDashboardStreamQuery(['activity' => (boolean) $this->activity]);
$competing = $this->runProfiler(function (ProfilerResult $result) {
$query = new DeprecatedDashboardStreamQuery(['activity' => (bool) $this->activity]);
$result->setResult($query->all());
}, $this->title);

Expand All @@ -44,13 +41,13 @@ public function actionRunMember()
{
$user = $this->getUser();

$result = $this->runProfiler(function(ProfilerResult $result) use ($user) {
$query = new DashboardStreamQuery(['activity' => (boolean) $this->activity, 'user' => $user]);
$result = $this->runProfiler(function (ProfilerResult $result) use ($user) {
$query = new DashboardStreamQuery(['activity' => (bool) $this->activity, 'user' => $user]);
$result->setResult($query->all());
}, $this->title);

$competing = $this->runProfiler(function(ProfilerResult $result) use ($user) {
$query = new DeprecatedDashboardStreamQuery(['activity' => (boolean) $this->activity, 'user' => $user]);
$competing = $this->runProfiler(function (ProfilerResult $result) use ($user) {
$query = new DeprecatedDashboardStreamQuery(['activity' => (bool) $this->activity, 'user' => $user]);
$result->setResult($query->all());
}, $this->title);

Expand All @@ -65,17 +62,17 @@ public function actionRunMemberDeprecated()
{
$user = $this->getUser();

/* $result = $this->runProfiler(function(ProfilerResult $result) use ($user) {
$query = new DashboardStreamQuery(['activity' => (boolean) $this->activity, 'user' => $user]);
$result->setResult($query->all());
}, $this->title);*/

$competing = $this->runProfiler(function(ProfilerResult $result) use ($user) {
$query = new DeprecatedDashboardStreamQuery(['activity' => (boolean) $this->activity, 'user' => $user]);
/* $result = $this->runProfiler(function(ProfilerResult $result) use ($user) {
$query = new DashboardStreamQuery(['activity' => (boolean) $this->activity, 'user' => $user]);
$result->setResult($query->all());
}, $this->title);
}, $this->title);*/

$competing = $this->runProfiler(function (ProfilerResult $result) use ($user) {
$query = new DeprecatedDashboardStreamQuery(['activity' => (bool) $this->activity, 'user' => $user]);
$result->setResult($query->all());
}, $this->title);

// $result->setTotalCount('Content entries', Content::find()->count());
// $result->setTotalCount('Content entries', Content::find()->count());

$this->printResult($competing);
}
Expand Down
14 changes: 6 additions & 8 deletions controllers/FixtureController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace humhub\modules\profiler\controllers;


use humhub\modules\profiler\faker\ContentContainerProvider;
use humhub\modules\profiler\faker\SpaceMemberProvider;
use Yii;
Expand Down Expand Up @@ -43,7 +41,7 @@ class FixtureController extends FakerFixtureController

public $providers = [
ContentContainerProvider::class,
SpaceMemberProvider::class
SpaceMemberProvider::class,
];

public function init()
Expand All @@ -60,7 +58,7 @@ public function init()
'post/post' => 40000,
'activity/activity' => 40000,
'file/file' => 100,
'content/contentcontainer' => function() {
'content/contentcontainer' => function () {
return count(ContentContainerProvider::$container);
},
'user/group' => 1,
Expand All @@ -74,7 +72,7 @@ public function actionGenerateAll()
{
parent::actionGenerateAll();

if(!empty(ContentContainerProvider::$container)) {
if (!empty(ContentContainerProvider::$container)) {
$this->count = count(ContentContainerProvider::$container);

$templatePath = Yii::getAlias($this->templatePath);
Expand All @@ -86,14 +84,14 @@ public function actionGenerateAll()

public function generateFixtureFile($templateName, $templatePath, $fixtureDataPath)
{
if(isset(static::$templateCount[$templateName])) {
if (isset(static::$templateCount[$templateName])) {
$this->count = (is_callable(static::$templateCount[$templateName]))
? call_user_func(static::$templateCount[$templateName]) : static::$templateCount[$templateName];
} else {
$this->count = $this->defaultCount;
}

$this->stdout($templateName.'('.$this->count.")\n", Console::FG_GREEN);
$this->stdout($templateName . '(' . $this->count . ")\n", Console::FG_GREEN);
parent::generateFixtureFile($templateName, $templatePath, $fixtureDataPath);
}

Expand All @@ -102,7 +100,7 @@ public function generateFixtureFile($templateName, $templatePath, $fixtureDataPa
protected function findTemplatesFiles(array $templatesNames = [])
{
$result = parent::findTemplatesFiles($templatesNames);
$result = array_diff($result,$this->excludeTemplates);
$result = array_diff($result, $this->excludeTemplates);
return $result;
}

Expand Down
20 changes: 9 additions & 11 deletions controllers/GalleryController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace humhub\modules\profiler\controllers;


use humhub\modules\gallery\models\StreamGallery;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
Expand All @@ -19,7 +17,7 @@ class GalleryController extends Controller
public function options($actionID)
{
return array_merge(parent::options($actionID), [
'count'
'count',
]);
}

Expand All @@ -32,7 +30,7 @@ public function init()
public function actionRun()
{

if(!Yii::$app->getModule('gallery')) {
if (!Yii::$app->getModule('gallery')) {
$this->stdout('Gallery Module needs to be enabled!', Console::FG_RED);
return;
}
Expand All @@ -43,17 +41,17 @@ public function actionRun()

PHP_Timer::start();

for($i = 0; $i < $this->count;$i++) {
//$gallery->fileListQuery()->one();
$gallery->fileListQueryOld()->one();
// $this->stdout($query->createCommand()->rawSql, Console::FG_GREEN);
for ($i = 0; $i < $this->count;$i++) {
//$gallery->fileListQuery()->one();
$gallery->fileListQueryOld()->one();
// $this->stdout($query->createCommand()->rawSql, Console::FG_GREEN);
}

$timeTotal = PHP_Timer::stop();

$timeAvg = $timeTotal / $this->count;

$this->printResultRow('getPreviewImageUrl('.$this->count.')', $timeTotal);
$this->printResultRow('getPreviewImageUrl(' . $this->count . ')', $timeTotal);
$this->printResultRow('getPreviewImageUrl(avg)', $timeAvg);
$this->stdout("\n");
$this->printResourceUsage();
Expand All @@ -66,12 +64,12 @@ protected function printResourceUsage()
$this->printResultRow('load (1m)', $load[0]);
$this->printResultRow('load (5m)', $load[1]);
$this->printResultRow('load (15m)', $load[2]);
$this->stdout(PHP_Timer::resourceUsage()."\n", Console::FG_GREEN);
$this->stdout(PHP_Timer::resourceUsage() . "\n", Console::FG_GREEN);

}

protected function printResultRow($title, $value, $color = Console::FG_GREEN)
{
$this->stdout(sprintf("%-30.30s| %5f \n", $title,$value), $color);
$this->stdout(sprintf("%-30.30s| %5f \n", $title, $value), $color);
}
}
38 changes: 19 additions & 19 deletions controllers/ProfileController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace humhub\modules\profiler\controllers;


use humhub\modules\profiler\models\ProfilerResult;
use humhub\modules\user\models\User;
use PHP_Timer;
Expand All @@ -30,18 +28,19 @@ public function options($actionID)
return array_merge(parent::options($actionID), [
'count',
'title',
'userId'
'userId',
]);
}

public function beforeAction($action)
{
try {
$test = Yii::$app->getDb()->createCommand('SHOW VARIABLES LIKE \'query_cache_size\';')->queryOne();
if($test['Value'] != 0) {
if ($test['Value'] != 0) {
$this->stdout("query_cache_size not 0\n", Console::FG_RED);
}
} catch (\Throwable $e) {}
} catch (\Throwable $e) {
}

return parent::beforeAction($action); // TODO: Change the autogenerated stub
}
Expand All @@ -55,14 +54,14 @@ public function runProfiler($profiler, $title, $dryRun = true)
{
$result = new ProfilerResult(['title' => $title]);

if($dryRun) {
if ($dryRun) {
// We make a dry run in order to make sure no internal caches do not affect the result
call_user_func($profiler, $result, -1);
}

$this->startProfiling();

for($i = 0; $i < $this->count;$i++) {
for ($i = 0; $i < $this->count;$i++) {
call_user_func($profiler, $result, $i);
}

Expand All @@ -85,7 +84,7 @@ public function printResult(ProfilerResult $result, ProfilerResult $competing =
{
$this->printResultHeadline();

if($result->totalCount && $result->totalCountTitle) {
if ($result->totalCount && $result->totalCountTitle) {
$this->printResultRow($result->totalCountTitle, $result->totalCount, false);
}

Expand All @@ -98,8 +97,9 @@ public function printResult(ProfilerResult $result, ProfilerResult $competing =
$this->cli_beep();
}

protected function cli_beep() {
fprintf( STDOUT, "%s", "\x07");
protected function cli_beep()
{
fprintf(STDOUT, "%s", "\x07");
}

protected function printTotalRunCount()
Expand All @@ -109,7 +109,7 @@ protected function printTotalRunCount()

protected function printTotalTimeRow(ProfilerResult $result, ProfilerResult $competing = null)
{
if($competing) {
if ($competing) {
return $this->printCompetingResultRow('Total run time (s)', $result->timeTotal, $competing->timeTotal);
}
return $this->printResultRow('Total run time (s)', $result->timeTotal);
Expand All @@ -119,7 +119,7 @@ protected function printAvarageTimeRow(ProfilerResult $result, ProfilerResult $c
{
$timeAvg = $result->timeTotal / $this->count;

if($competing) {
if ($competing) {
$timeAvgComp = $competing->timeTotal / $this->count;
return $this->printCompetingResultRow('Average run time (s)', $timeAvg, $timeAvgComp, true);
}
Expand All @@ -129,8 +129,8 @@ protected function printAvarageTimeRow(ProfilerResult $result, ProfilerResult $c

protected function printResultRowPerRun(ProfilerResult $result, ProfilerResult $competing = null)
{
if($competing) {
return $this->printCompetingResultRow('Result count per run', $result->getResultCount(), $competing->getResultCount(), false,false);
if ($competing) {
return $this->printCompetingResultRow('Result count per run', $result->getResultCount(), $competing->getResultCount(), false, false);
}

return $this->printResultRow('Result count per run', $result->getResultCount(), false);
Expand All @@ -142,14 +142,14 @@ protected function printResourceUsage()
$this->printResultRow('load % (1m)', $load[0] * 100, false);
$this->printResultRow('load % (5m)', $load[1] * 100, false);
$this->printResultRow('load % (15m)', $load[2] * 100, false);
$this->stdout(PHP_Timer::resourceUsage()."\n", Console::FG_GREEN);
$this->stdout(PHP_Timer::resourceUsage() . "\n", Console::FG_GREEN);

}

protected function printResultHeadline()
{
$this->stdout("---------------------------------------------------------------\n", Console::FG_GREEN);
$this->stdout($this->title."\n", Console::FG_GREEN);
$this->stdout($this->title . "\n", Console::FG_GREEN);
$this->stdout("---------------------------------------------------------------\n", Console::FG_GREEN);
}

Expand All @@ -159,9 +159,9 @@ protected function printCompetingResultRow($title, $value1, $value2, $diff = fal
$format .= $float ? "%3f" : "%u";
$format .= $float ? " vs %3f" : " vs %u";

if(!$diff) {
if (!$diff) {
$format .= " \n";
$this->stdout(sprintf($format, $title,$value1, $value2), $color);
$this->stdout(sprintf($format, $title, $value1, $value2), $color);
return;
}

Expand All @@ -179,7 +179,7 @@ protected function printResultRow($title, $value, $float = true, $color = Consol
$format = "%-50.50s|";
$format .= $float ? "%3f" : "%u";
$format .= " \n";
$this->stdout(sprintf($format, $title,$value), $color);
$this->stdout(sprintf($format, $title, $value), $color);
}

/**
Expand Down
Loading

0 comments on commit 043772c

Please sign in to comment.