Skip to content

Commit

Permalink
Merge pull request #65 from humhub/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 27fd730 + 9aa5fcf commit 670b642
Show file tree
Hide file tree
Showing 23 changed files with 94 additions and 91 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:
tests:
uses: humhub/actions/.github/workflows/module-php-cs-fixer.yml@main
2 changes: 1 addition & 1 deletion Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static function onProfileSettingMenuInit($event)
'label' => Yii::t('TwofaModule.base', 'Two-Factor Authentication'),
'url' => Yii::$app->user->identity->createUrl(TwofaUrl::ROUTE_USER_SETTINGS),
'isActive' => $isActiveMenu,
'sortOrder' => 300
'sortOrder' => 300,
]);

if ($isActiveMenu) {
Expand Down
6 changes: 3 additions & 3 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function isTwofaCheckUrl()
* Get available drivers options for the 2fa module settings
*
* @param array|null Init options(Key - Driver class name, Value - Drive name), used to init None option and/or forced/default Driver
* @param boolean true - to load only enabled drivers, false - to load all implemented drivers for the module
* @param bool true - to load only enabled drivers, false - to load all implemented drivers for the module
* @return array
*/
public function getDriversOptions($driversOptions = [], $onlyEnabled = false)
Expand Down Expand Up @@ -123,7 +123,7 @@ public function getEnabledDrivers(bool $checkActive = true): array
/**
* Get length of verifying code
*
* @return integer
* @return int
*/
public function getCodeLength()
{
Expand All @@ -133,7 +133,7 @@ public function getCodeLength()
/**
* Get length in days of remember me option
*
* @return integer
* @return int
*/
public function getRememberMeDays()
{
Expand Down
2 changes: 1 addition & 1 deletion assets/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ class Assets extends AssetBundle
* @inheritDoc
*/
public $publishOptions = [
'forceCopy' => false
'forceCopy' => false,
];
}
3 changes: 1 addition & 2 deletions controllers/CheckController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ public function actionIndex()

return $this->render('index', [
'model' => $model, 'driver' => TwofaHelper::getDriver(),
'rememberDays' => Yii::$app->getModule('twofa')->getRememberMeDays()
'rememberDays' => Yii::$app->getModule('twofa')->getRememberMeDays(),
]);
}

}

100 changes: 50 additions & 50 deletions controllers/ConfigController.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2020 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/

namespace humhub\modules\twofa\controllers;

use humhub\modules\admin\permissions\ManageModules;
use humhub\modules\admin\components\Controller;
use humhub\modules\twofa\helpers\TwofaHelper;
use humhub\modules\twofa\models\Config;
use Yii;

class ConfigController extends Controller
{
/**
* @inheritdoc
*/
public function getAccessRules()
{
return [['permissions' => ManageModules::class]];
}

/**
* Configuration action for system admins.
*/
public function actionIndex()
{
$model = new Config();

if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->view->saved();
}

$ip = Yii::$app->request->userIP;
if ($ip !== Yii::$app->request->remoteIP) {
$ip .= ', ' . Yii::$app->request->remoteIP;
}

return $this->render('module', [
'model' => $model,
'defaultDriverName' => TwofaHelper::getDriverByClassName($model->module->defaultDriver)->name,
'ip' => $ip,
]);
}
}
<?php

/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2020 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/

namespace humhub\modules\twofa\controllers;

use humhub\modules\admin\permissions\ManageModules;
use humhub\modules\admin\components\Controller;
use humhub\modules\twofa\helpers\TwofaHelper;
use humhub\modules\twofa\models\Config;
use Yii;

class ConfigController extends Controller
{
/**
* @inheritdoc
*/
public function getAccessRules()
{
return [['permissions' => ManageModules::class]];
}

/**
* Configuration action for system admins.
*/
public function actionIndex()
{
$model = new Config();

if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->view->saved();
}

$ip = Yii::$app->request->userIP;
if ($ip !== Yii::$app->request->remoteIP) {
$ip .= ', ' . Yii::$app->request->remoteIP;
}

return $this->render('module', [
'model' => $model,
'defaultDriverName' => TwofaHelper::getDriverByClassName($model->module->defaultDriver)->name,
'ip' => $ip,
]);
}
}
2 changes: 1 addition & 1 deletion controllers/UserSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function actionIndex()
Assets::register($this->view);

return $this->render('@twofa/views/config/user', [
'model' => $model
'model' => $model,
]);
}

Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
1.1.4 (Unreleased)
----------------------
- Enh #58: Tests for `next` version
- Enh #65: Use PHP CS Fixer

1.1.3 (June 8, 2023)
--------------------
Expand Down
6 changes: 3 additions & 3 deletions drivers/EmailDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function send()
/** @var BaseMessage $mail */
$mail = Yii::$app->mailer->compose([
'html' => '@twofa/views/mails/VerifyingCode',
'text' => '@twofa/views/mails/plaintext/VerifyingCode'
'text' => '@twofa/views/mails/plaintext/VerifyingCode',
], [
'user' => $user,
'code' => $this->getCode(),
Expand All @@ -61,6 +61,6 @@ protected function isValidUserEmail(): bool
/* @var User $user */
$user = Yii::$app->user->getIdentity();

return !empty($user->email) && (new EmailValidator)->validate($user->email);
return !empty($user->email) && (new EmailValidator())->validate($user->email);
}
}
}
6 changes: 3 additions & 3 deletions drivers/GoogleAuthenticatorDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class GoogleAuthenticatorDriver extends BaseDriver
/**
* @var string Setting name for secret code per User
*/
const SECRET_SETTING = 'twofaGoogleAuthSecret';
const SECRET_TEMP_SETTING = 'twofaGoogleAuthSecretTemp';
public const SECRET_SETTING = 'twofaGoogleAuthSecret';
public const SECRET_TEMP_SETTING = 'twofaGoogleAuthSecretTemp';

/**
* @inheritdoc
Expand Down Expand Up @@ -102,7 +102,7 @@ public function renderUserSettings($params)
'confirm.action.question' => Yii::t('TwofaModule.config', 'Do you really want to request a new code?') . '<br><br>'
. Yii::t('TwofaModule.config', 'Please <strong>do not forget</strong> to update the code in your authenticator app! If you do not do so, you will not be able to login.'),
'confirm.action.button' => Yii::t('TwofaModule.config', 'Request new code'),
]
],
]);

$model = $this->getUserSettings();
Expand Down
8 changes: 4 additions & 4 deletions helpers/TwofaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

class TwofaHelper
{
const USER_SETTING = 'twofaDriver';
const CODE_SETTING = 'twofaCode';
const CODE_CHARS = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
public const USER_SETTING = 'twofaDriver';
public const CODE_SETTING = 'twofaCode';
public const CODE_CHARS = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';

/**
* Get settings manager of current User
Expand Down Expand Up @@ -131,7 +131,7 @@ public static function getDriver()
/**
* Check if at least one Group of the current User is enforced to 2fa
*
* @return boolean
* @return bool
*/
public static function isEnforcedUser()
{
Expand Down
8 changes: 4 additions & 4 deletions helpers/TwofaUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ class TwofaUrl extends Url
/**
* @var string Route to display a form to check user by two-factor authentication
*/
const ROUTE_CHECK = '/twofa/check';
public const ROUTE_CHECK = '/twofa/check';

/**
* @var string Route to configure general module settings by admin
*/
const ROUTE_CONFIG = '/twofa/config';
public const ROUTE_CONFIG = '/twofa/config';

/**
* @var string Route to configure user settings by current User
*/
const ROUTE_USER_SETTINGS = '/twofa/user-settings';
public const ROUTE_USER_SETTINGS = '/twofa/user-settings';

public static function toCheck()
{
Expand All @@ -36,4 +36,4 @@ public static function toConfig()
{
return static::toRoute(static::ROUTE_CONFIG);
}
}
}
2 changes: 1 addition & 1 deletion models/CheckCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function rules()
['code', 'required'],
['code', 'string'],
['code', 'verifyCode'],
['rememberBrowser', 'boolean']
['rememberBrowser', 'boolean'],
];
}

Expand Down
2 changes: 1 addition & 1 deletion models/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function rules()
['rememberMeDays', 'integer', 'max' => 365],
['enforcedGroups', 'in', 'range' => array_keys($this->module->getGroupsOptions()), 'allowArray' => true],
['enforcedMethod', 'in', 'range' => array_keys($this->module->getDriversOptions())],
['trustedNetworks', 'string']
['trustedNetworks', 'string'],
];
}

Expand Down
3 changes: 1 addition & 2 deletions models/GoogleAuthenticatorUserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
*/
class GoogleAuthenticatorUserSettings extends Model
{

/**
* @var string Pin code
*/
public $pinCode;

/**
* @var boolean Change secret code?
* @var bool Change secret code?
*/
public $changeSecretCode;

Expand Down
1 change: 0 additions & 1 deletion models/UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
class UserSettings extends Model
{

/**
* @var Module
*/
Expand Down
3 changes: 1 addition & 2 deletions tests/codeception/_pages/TwofaAuthPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
*/
class TwofaAuthPage extends BasePage
{

public $route = 'twofa/check';

/**
* @param string $code
*/
public function verify($code)
{
if(method_exists($this->actor, 'waitForText')) {
if (method_exists($this->actor, 'waitForText')) {
$this->actor->waitForText('Two-factor authentication');
}
$this->actor->fillField('CheckCode[code]', $code);
Expand Down
8 changes: 4 additions & 4 deletions tests/codeception/_support/FunctionalTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
class FunctionalTester extends \FunctionalTester
{
use _generated\FunctionalTesterActions;
/**
* Define custom actions here
*/

/**
* Define custom actions here
*/

/**
* @return string
Expand Down
6 changes: 3 additions & 3 deletions tests/codeception/_support/UnitTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class UnitTester extends \UnitTester
{
use _generated\UnitTesterActions;

/**
* Define custom actions here
*/
/**
* Define custom actions here
*/
}
2 changes: 1 addition & 1 deletion tests/codeception/config/unit.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

return \tests\codeception\_support\HumHubTestConfiguration::getSuiteConfig('unit');
return \tests\codeception\_support\HumHubTestConfiguration::getSuiteConfig('unit');
3 changes: 1 addition & 2 deletions tests/codeception/functional/TwofaCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

class TwofaCest
{

public function testCheckWrongVerifyingCode(FunctionalTester $I)
{
$I->wantTo('check wrong verifying code');
Expand All @@ -39,7 +38,7 @@ public function testVerifyCodeFromEmail(FunctionalTester $I)
$I->see('Two-factor authentication');

$adminMail = $I->grabLastSentEmail();
if(!array_key_exists('admin@example.com', $adminMail->getTo())) {
if (!array_key_exists('admin@example.com', $adminMail->getTo())) {
$I->see('admin@example.com not in mails');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/codeception/unit/TwofaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ public function testDisableVerifying()
$this->assertTrue(TwofaHelper::disableVerifying());
$this->assertFalse(TwofaHelper::isVerifyingRequired());
}
}
}
2 changes: 1 addition & 1 deletion tests/config/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
'fixtures' => [
'default',
//'twofa' => \tests\codeception\fixtures\TwofaFixture::class
]
],
];

0 comments on commit 670b642

Please sign in to comment.