Skip to content

Commit

Permalink
Merge pull request #182 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 8, 2024
2 parents f4f1b1e + 7ce2394 commit 049d673
Show file tree
Hide file tree
Showing 62 changed files with 129 additions and 153 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
5 changes: 2 additions & 3 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@

class Module extends BaseModule
{

/**
* @event triggered before a request (inside event Application::EVENT_BEFORE_REQUEST of this Module)
*/
const EVENT_REST_API_ADD_RULES = 'restApiAddRules';
public const EVENT_REST_API_ADD_RULES = 'restApiAddRules';

/**
* @var string Prefix for REST API endpoint URLs
*/
const API_URL_PREFIX = 'api/v1/';
public const API_URL_PREFIX = 'api/v1/';

/**
* @inheritdoc
Expand Down
11 changes: 5 additions & 6 deletions components/BaseContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use yii\web\HttpException;
use yii\web\UploadedFile;


/**
* BaseContentController provides basic CRUD operations for HumHub content records
*
Expand Down Expand Up @@ -90,7 +89,7 @@ public function actionFind()
/**
* Finds content by given container
*
* @param integer $containerId the id of the content container
* @param int $containerId the id of the content container
* @return array the rest output
* @throws \yii\db\IntegrityException
*/
Expand Down Expand Up @@ -504,9 +503,9 @@ protected function updateScheduledAt(ContentActiveRecord $activeRecord, array $d
}

$validator = DynamicModel::validateData([
'scheduled_at' => $data['scheduled_at']
'scheduled_at' => $data['scheduled_at'],
], [
['scheduled_at', 'datetime', 'format' => 'php:Y-m-d H:i:s']
['scheduled_at', 'datetime', 'format' => 'php:Y-m-d H:i:s'],
]);

if (!$validator->validate()) {
Expand All @@ -527,9 +526,9 @@ public function updateCreatedAt(ContentActiveRecord $activeRecord, array $data):
}

$validator = DynamicModel::validateData([
'created_at' => $data['created_at']
'created_at' => $data['created_at'],
], [
['created_at', 'datetime', 'format' => 'php:Y-m-d H:i:s']
['created_at', 'datetime', 'format' => 'php:Y-m-d H:i:s'],
]);

if (!$validator->validate()) {
Expand Down
6 changes: 3 additions & 3 deletions components/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function behaviors()
]] : [],
ConfigureForm::getInstance()->enableBasicAuth ? [[
'class' => HttpBasicAuth::class,
'auth' => function($username, $password) {
'auth' => function ($username, $password) {
if (($identity = AuthController::authByUserAndPassword($username, $password)) && $this->isUserEnabled($identity)) {
return $identity;
}
Expand All @@ -79,12 +79,12 @@ public function behaviors()
]] : [],
[[
'class' => ImpersonateAuth::class,
]]
]],
),
],
'languagePicker' => [
'class' => LanguagePickerBehavior::class,
]
],
], parent::behaviors());
}

Expand Down
2 changes: 1 addition & 1 deletion components/auth/JwtAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function authenticate($user, $request, $response)
{
$authHeader = $request->getHeaders()->get($this->header);

if ($request->getHeaders()->get($this->header) &&$this->pattern !== null && preg_match($this->pattern, $authHeader, $matches)) {
if ($request->getHeaders()->get($this->header) && $this->pattern !== null && preg_match($this->pattern, $authHeader, $matches)) {
$token = $matches[1];

try {
Expand Down
14 changes: 7 additions & 7 deletions controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function actionIndex()
return $this->render('tabs', [
'tab' => $this->renderPartial('index', [
'model' => $model,
])
]),
]);
}

Expand All @@ -54,7 +54,7 @@ public function actionJwtAuth()
return $this->render('tabs', [
'tab' => $this->renderPartial('jwt-auth', [
'model' => $model,
])
]),
]);
}

Expand All @@ -72,19 +72,19 @@ public function actionBearerAuth()
'bearerTokenModel' => $bearerTokenModel,
'bearerTokensProvider' => new ActiveDataProvider([
'query' => RestUserBearerToken::find()->with('user'),
'sort'=> [
'defaultOrder' => ['id' => SORT_ASC]
'sort' => [
'defaultOrder' => ['id' => SORT_ASC],
],
])
])
]),
]),
]);
}

public function actionRevokeAccessToken($id)
{
RestUserBearerToken::deleteAll(['id' => $id]);

$this->view->success(Yii::t('RestModule.base','Bearer Access Token Successfully Revoked'));
$this->view->success(Yii::t('RestModule.base', 'Bearer Access Token Successfully Revoked'));

return $this->redirect(['bearer-auth']);
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/ErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

namespace humhub\modules\rest\controllers;
use humhub\modules\rest\components\BaseController;

use humhub\modules\rest\components\BaseController;

/**
* Class ErrorController
Expand All @@ -18,4 +18,4 @@ public function actionNotfound()
{
return $this->returnError(404, 'Requested action not found!');
}
}
}
2 changes: 1 addition & 1 deletion controllers/activity/ActivityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ public function actionFindByContainer($containerId)
}
return $this->returnPagination($query, $pagination, $results);
}
}
}
6 changes: 3 additions & 3 deletions controllers/auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function actionIndex()
'iss' => Yii::$app->settings->get('baseUrl'),
'nbf' => $issuedAt,
'uid' => $user->id,
'email' => $user->email
'email' => $user->email,
];

$config = JwtAuthForm::getInstance();
Expand All @@ -65,14 +65,14 @@ public function actionIndex()

return $this->returnSuccess('Success', 200, [
'auth_token' => $jwt,
'expired_at' => (!isset($data['exp'])) ? 0 : $data['exp']
'expired_at' => (!isset($data['exp'])) ? 0 : $data['exp'],
]);
}


public static function authByUserAndPassword($username, $password)
{
$login = new Login;
$login = new Login();
if (!$login->load(['username' => $username, 'password' => $password], '') || !$login->validate()) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/comment/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function actionFindByObject($objectModel, $objectId)
{
$content = Content::findOne([
'object_model' => $objectModel,
'object_id' => $objectId
'object_id' => $objectId,
]);

return $this->getPagedComments($content);
Expand Down Expand Up @@ -175,4 +175,4 @@ public function getObject()
return $this->_object;
}

}
}
4 changes: 1 addition & 3 deletions controllers/content/ContainerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
use humhub\modules\rest\definitions\ContentDefinitions;
use humhub\modules\content\models\ContentContainer;


class ContainerController extends BaseController
{

public function actionList()
{
$results = [];
Expand All @@ -30,4 +28,4 @@ public function actionList()



}
}
10 changes: 4 additions & 6 deletions controllers/content/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
use humhub\modules\rest\definitions\ContentDefinitions;
use humhub\modules\content\models\Content;


class ContentController extends BaseController
{

public function actionFindByContainer($id, $orderBy = 'creationTime', $dateUpdatedFrom = null, $dateUpdatedTo = null)
{
$contentContainer = ContentContainer::findOne(['id' => (int) $id]);
Expand All @@ -41,17 +39,17 @@ public function actionFindByContainer($id, $orderBy = 'creationTime', $dateUpdat
->orderBy([Content::tableName() . '.' . $orderByColumn => SORT_DESC])
->readable();

if(!empty($dateUpdatedFrom)) {
if (!empty($dateUpdatedFrom)) {
$dateUpdatedFrom = is_numeric($dateUpdatedFrom) ? (int) $dateUpdatedFrom : strtotime($dateUpdatedFrom);
$query->andWhere([
'>=', Content::tableName() . '.updated_at', date('Y-m-d H:i:s', $dateUpdatedFrom)
'>=', Content::tableName() . '.updated_at', date('Y-m-d H:i:s', $dateUpdatedFrom),
]);
}

if(!empty($dateUpdatedTo)) {
if (!empty($dateUpdatedTo)) {
$dateUpdatedTo = is_numeric($dateUpdatedTo) ? (int) $dateUpdatedTo : strtotime($dateUpdatedTo);
$query->andWhere([
'<=', Content::tableName() . '.updated_at', date('Y-m-d H:i:s', $dateUpdatedTo)
'<=', Content::tableName() . '.updated_at', date('Y-m-d H:i:s', $dateUpdatedTo),
]);
}

Expand Down
3 changes: 1 addition & 2 deletions controllers/file/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

class FileController extends BaseController
{

public function actionDownload($id)
{
$file = File::findOne(['id' => $id]);
Expand All @@ -40,4 +39,4 @@ public function actionDownload($id)
}
}

}
}
4 changes: 1 addition & 3 deletions controllers/like/LikeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
use humhub\modules\like\models\Like;
use Yii;


class LikeController extends BaseController
{

public function actionFindByObject()
{
$contentFilter = [
Expand Down Expand Up @@ -76,4 +74,4 @@ public function actionDelete($id)
}


}
}
2 changes: 1 addition & 1 deletion controllers/notification/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ public function actionMarkAsSeen()

return $this->returnSuccess('All notifications successfully marked as seen');
}
}
}
4 changes: 1 addition & 3 deletions controllers/post/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

namespace humhub\modules\rest\controllers\post;


use humhub\modules\content\components\ContentActiveRecord;
use humhub\modules\post\models\Post;
use humhub\modules\rest\components\BaseContentController;
use humhub\modules\rest\definitions\PostDefinitions;


class PostController extends BaseContentController
{
/**
Expand All @@ -33,4 +31,4 @@ public function returnContentDefinition(ContentActiveRecord $contentRecord)
$post = Post::findOne(['id' => $contentRecord->id]);
return PostDefinitions::getPost($post);
}
}
}
2 changes: 1 addition & 1 deletion controllers/space/ArchiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ public function actionUnarchive($id)

return $this->returnSuccess('Space successfully unarchived!');
}
}
}
2 changes: 1 addition & 1 deletion controllers/space/MembershipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ public function actionRole($spaceId, $userId)

return $this->returnSuccess('Member updated!');
}
}
}
5 changes: 2 additions & 3 deletions controllers/space/SpaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
class SpaceController extends BaseController
{

public function actionIndex()
{
$results = [];
Expand Down Expand Up @@ -50,7 +49,7 @@ public function actionView($id)

public function actionCreate()
{
if (!Yii::$app->user->permissionmanager->can(new CreatePublicSpace) && !Yii::$app->user->permissionmanager->can(new CreatePrivateSpace)) {
if (!Yii::$app->user->permissionmanager->can(new CreatePublicSpace()) && !Yii::$app->user->permissionmanager->can(new CreatePrivateSpace())) {
return $this->returnError(403, 'You are not allowed to create spaces!');
}

Expand Down Expand Up @@ -136,4 +135,4 @@ public function actionDelete($id)

return $this->returnError(500, 'Internal error while delete space!');
}
}
}
Loading

0 comments on commit 049d673

Please sign in to comment.