diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 0000000..2144827 --- /dev/null +++ b/.github/workflows/php-cs-fixer.yml @@ -0,0 +1,7 @@ +name: PHP CS Fixer + +on: push + +jobs: + tests: + uses: humhub/actions/.github/workflows/module-php-cs-fixer.yml@main diff --git a/Module.php b/Module.php index 54b0084..14f4a0f 100644 --- a/Module.php +++ b/Module.php @@ -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 diff --git a/components/BaseContentController.php b/components/BaseContentController.php index e525917..13d57fc 100644 --- a/components/BaseContentController.php +++ b/components/BaseContentController.php @@ -25,7 +25,6 @@ use yii\web\HttpException; use yii\web\UploadedFile; - /** * BaseContentController provides basic CRUD operations for HumHub content records * @@ -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 */ @@ -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()) { @@ -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()) { diff --git a/components/BaseController.php b/components/BaseController.php index d0f8924..8bd1478 100644 --- a/components/BaseController.php +++ b/components/BaseController.php @@ -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; } @@ -79,12 +79,12 @@ public function behaviors() ]] : [], [[ 'class' => ImpersonateAuth::class, - ]] + ]], ), ], 'languagePicker' => [ 'class' => LanguagePickerBehavior::class, - ] + ], ], parent::behaviors()); } diff --git a/components/auth/JwtAuth.php b/components/auth/JwtAuth.php index 2310307..9e3e09a 100644 --- a/components/auth/JwtAuth.php +++ b/components/auth/JwtAuth.php @@ -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 { diff --git a/controllers/AdminController.php b/controllers/AdminController.php index f2d684f..8867c8c 100644 --- a/controllers/AdminController.php +++ b/controllers/AdminController.php @@ -37,7 +37,7 @@ public function actionIndex() return $this->render('tabs', [ 'tab' => $this->renderPartial('index', [ 'model' => $model, - ]) + ]), ]); } @@ -54,7 +54,7 @@ public function actionJwtAuth() return $this->render('tabs', [ 'tab' => $this->renderPartial('jwt-auth', [ 'model' => $model, - ]) + ]), ]); } @@ -72,11 +72,11 @@ public function actionBearerAuth() 'bearerTokenModel' => $bearerTokenModel, 'bearerTokensProvider' => new ActiveDataProvider([ 'query' => RestUserBearerToken::find()->with('user'), - 'sort'=> [ - 'defaultOrder' => ['id' => SORT_ASC] + 'sort' => [ + 'defaultOrder' => ['id' => SORT_ASC], ], - ]) - ]) + ]), + ]), ]); } @@ -84,7 +84,7 @@ 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']); } diff --git a/controllers/ErrorController.php b/controllers/ErrorController.php index 8a9508f..4a5e25f 100644 --- a/controllers/ErrorController.php +++ b/controllers/ErrorController.php @@ -6,8 +6,8 @@ */ namespace humhub\modules\rest\controllers; -use humhub\modules\rest\components\BaseController; +use humhub\modules\rest\components\BaseController; /** * Class ErrorController @@ -18,4 +18,4 @@ public function actionNotfound() { return $this->returnError(404, 'Requested action not found!'); } -} \ No newline at end of file +} diff --git a/controllers/activity/ActivityController.php b/controllers/activity/ActivityController.php index 7106c00..85e91f4 100644 --- a/controllers/activity/ActivityController.php +++ b/controllers/activity/ActivityController.php @@ -61,4 +61,4 @@ public function actionFindByContainer($containerId) } return $this->returnPagination($query, $pagination, $results); } -} \ No newline at end of file +} diff --git a/controllers/auth/AuthController.php b/controllers/auth/AuthController.php index 360d568..f911fde 100644 --- a/controllers/auth/AuthController.php +++ b/controllers/auth/AuthController.php @@ -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(); @@ -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; } diff --git a/controllers/comment/CommentController.php b/controllers/comment/CommentController.php index c2e0067..f294d1c 100644 --- a/controllers/comment/CommentController.php +++ b/controllers/comment/CommentController.php @@ -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); @@ -175,4 +175,4 @@ public function getObject() return $this->_object; } -} \ No newline at end of file +} diff --git a/controllers/content/ContainerController.php b/controllers/content/ContainerController.php index 3592742..9509df1 100644 --- a/controllers/content/ContainerController.php +++ b/controllers/content/ContainerController.php @@ -11,10 +11,8 @@ use humhub\modules\rest\definitions\ContentDefinitions; use humhub\modules\content\models\ContentContainer; - class ContainerController extends BaseController { - public function actionList() { $results = []; @@ -30,4 +28,4 @@ public function actionList() -} \ No newline at end of file +} diff --git a/controllers/content/ContentController.php b/controllers/content/ContentController.php index 28422a9..4fccb12 100644 --- a/controllers/content/ContentController.php +++ b/controllers/content/ContentController.php @@ -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]); @@ -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), ]); } diff --git a/controllers/file/FileController.php b/controllers/file/FileController.php index aec2c4f..500bcbf 100644 --- a/controllers/file/FileController.php +++ b/controllers/file/FileController.php @@ -14,7 +14,6 @@ class FileController extends BaseController { - public function actionDownload($id) { $file = File::findOne(['id' => $id]); @@ -40,4 +39,4 @@ public function actionDownload($id) } } -} \ No newline at end of file +} diff --git a/controllers/like/LikeController.php b/controllers/like/LikeController.php index c6d3c95..5e391c2 100644 --- a/controllers/like/LikeController.php +++ b/controllers/like/LikeController.php @@ -13,10 +13,8 @@ use humhub\modules\like\models\Like; use Yii; - class LikeController extends BaseController { - public function actionFindByObject() { $contentFilter = [ @@ -76,4 +74,4 @@ public function actionDelete($id) } -} \ No newline at end of file +} diff --git a/controllers/notification/NotificationController.php b/controllers/notification/NotificationController.php index c81e69e..c4f6394 100644 --- a/controllers/notification/NotificationController.php +++ b/controllers/notification/NotificationController.php @@ -68,4 +68,4 @@ public function actionMarkAsSeen() return $this->returnSuccess('All notifications successfully marked as seen'); } -} \ No newline at end of file +} diff --git a/controllers/post/PostController.php b/controllers/post/PostController.php index 918c488..f9c2162 100644 --- a/controllers/post/PostController.php +++ b/controllers/post/PostController.php @@ -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 { /** @@ -33,4 +31,4 @@ public function returnContentDefinition(ContentActiveRecord $contentRecord) $post = Post::findOne(['id' => $contentRecord->id]); return PostDefinitions::getPost($post); } -} \ No newline at end of file +} diff --git a/controllers/space/ArchiveController.php b/controllers/space/ArchiveController.php index 6582547..5603c2c 100644 --- a/controllers/space/ArchiveController.php +++ b/controllers/space/ArchiveController.php @@ -65,4 +65,4 @@ public function actionUnarchive($id) return $this->returnSuccess('Space successfully unarchived!'); } -} \ No newline at end of file +} diff --git a/controllers/space/MembershipController.php b/controllers/space/MembershipController.php index 2ae59e3..88efc6a 100644 --- a/controllers/space/MembershipController.php +++ b/controllers/space/MembershipController.php @@ -106,4 +106,4 @@ public function actionRole($spaceId, $userId) return $this->returnSuccess('Member updated!'); } -} \ No newline at end of file +} diff --git a/controllers/space/SpaceController.php b/controllers/space/SpaceController.php index 361fa2c..b687e9b 100644 --- a/controllers/space/SpaceController.php +++ b/controllers/space/SpaceController.php @@ -20,7 +20,6 @@ */ class SpaceController extends BaseController { - public function actionIndex() { $results = []; @@ -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!'); } @@ -136,4 +135,4 @@ public function actionDelete($id) return $this->returnError(500, 'Internal error while delete space!'); } -} \ No newline at end of file +} diff --git a/controllers/topic/TopicController.php b/controllers/topic/TopicController.php index 5ef9123..0ba2c84 100644 --- a/controllers/topic/TopicController.php +++ b/controllers/topic/TopicController.php @@ -67,7 +67,7 @@ public function actionCreate($containerId) { $contentContainer = ContentContainer::findOne(['id' => $containerId]); $container = $contentContainer->getPolymorphicRelation(); - + if ($contentContainer->class === User::class && ($contentContainer->pk !== Yii::$app->user->id && ! Yii::$app->user->isAdmin())) { return $this->returnError(403, 'You are not allowed to create topic for user!'); } @@ -80,7 +80,7 @@ public function actionCreate($containerId) $topic->load(Yii::$app->request->getBodyParams(), ''); $topic->validate(); - if($topic->hasErrors()) { + if ($topic->hasErrors()) { return $this->returnError(422, 'Validation failed', [ $topic->getErrors(), ]); @@ -115,7 +115,7 @@ public function actionUpdate($id) $topic->load(Yii::$app->request->getBodyParams(), ''); $topic->validate(); - if($topic->hasErrors()) { + if ($topic->hasErrors()) { return $this->returnError(422, 'Validation failed', [ $topic->getErrors(), ]); @@ -185,11 +185,11 @@ protected function prepareContainerQuery($query, $contentContainerId, $spaceIds) } else { $query->andWhere(['and', ['contentcontainer.pk' => $contentContainer->pk, 'contentcontainer.class' => $contentContainer->class], - ['contentcontainer.pk' => $spaceIds, 'contentcontainer.class' => Space::class] + ['contentcontainer.pk' => $spaceIds, 'contentcontainer.class' => Space::class], ]); } } return $query; } -} \ No newline at end of file +} diff --git a/controllers/user/GroupController.php b/controllers/user/GroupController.php index bbf47d6..0da8017 100644 --- a/controllers/user/GroupController.php +++ b/controllers/user/GroupController.php @@ -15,13 +15,11 @@ use humhub\modules\user\models\User; use Yii; - /** * Class GroupController */ class GroupController extends BaseController { - /** * @inheritdoc */ diff --git a/controllers/user/SessionController.php b/controllers/user/SessionController.php index 6b6fbde..5d2c20f 100644 --- a/controllers/user/SessionController.php +++ b/controllers/user/SessionController.php @@ -12,10 +12,8 @@ use humhub\modules\user\models\Session; use humhub\modules\user\models\User; - class SessionController extends BaseController { - /** * @inheritdoc */ diff --git a/controllers/user/UserController.php b/controllers/user/UserController.php index df1b290..d2dc84c 100644 --- a/controllers/user/UserController.php +++ b/controllers/user/UserController.php @@ -17,13 +17,11 @@ use Yii; use yii\web\HttpException; - /** * Class AccountController */ class UserController extends BaseController { - /** * @inheritdoc */ diff --git a/definitions/ActivityDefinitions.php b/definitions/ActivityDefinitions.php index f12bfc1..efcd896 100644 --- a/definitions/ActivityDefinitions.php +++ b/definitions/ActivityDefinitions.php @@ -24,7 +24,7 @@ public static function getActivity(Activity $activity) 'content' => static::getActivityContent($activity, $baseActivity), 'originator' => UserDefinitions::getUserShort($baseActivity->originator), 'source' => SourceDefinitions::getSource($baseActivity->source), - 'createdAt' => $activity->content->created_at + 'createdAt' => $activity->content->created_at, ]; } @@ -33,12 +33,12 @@ private static function getActivityContent($activity, $baseActivity) return [ 'id' => $activity->content->id, 'guid' => $activity->content->guid, - 'pinned' => (boolean) $activity->content->pinned, - 'archived' => (boolean) $activity->content->archived, + 'pinned' => (bool) $activity->content->pinned, + 'archived' => (bool) $activity->content->archived, 'output' => static::getActivityOutput($baseActivity), ]; } - + private static function getActivityOutput($baseActivity) { try { @@ -48,4 +48,4 @@ private static function getActivityOutput($baseActivity) return ''; } } -} \ No newline at end of file +} diff --git a/definitions/CommentDefinitions.php b/definitions/CommentDefinitions.php index 0b81c1f..65091f4 100644 --- a/definitions/CommentDefinitions.php +++ b/definitions/CommentDefinitions.php @@ -17,7 +17,6 @@ */ class CommentDefinitions { - public static function getCommentsSummary(ActiveRecord $record) { $result = []; @@ -36,7 +35,7 @@ public static function getCommentsSummary(ActiveRecord $record) foreach (Comment::GetCommentsLimited($model, $pk) as $comment) { $result['latest'][] = static::getComment($comment); } - } + } return $result; } @@ -55,7 +54,7 @@ public static function getComment(Comment $comment) ]; $subComments = static::getSubComments($comment); - $subCommentsCount = count($subComments ); + $subCommentsCount = count($subComments); if ($subCommentsCount) { $result['commentsCount'] = $subCommentsCount; $result['comments'] = $subComments; @@ -89,4 +88,4 @@ public static function getSubComments(Comment $comment): array return $comments; } -} \ No newline at end of file +} diff --git a/definitions/ContentDefinitions.php b/definitions/ContentDefinitions.php index 8e927b0..4a93357 100644 --- a/definitions/ContentDefinitions.php +++ b/definitions/ContentDefinitions.php @@ -13,14 +13,12 @@ use humhub\modules\topic\models\Topic; use Yii; - /** * Class ContentDefinitions * @package humhub\modules\rest\definitions */ class ContentDefinitions { - public static function getContent($content) { return [ @@ -54,7 +52,7 @@ public static function getContentMetadata(Content $content) 'scheduled_at' => $content->scheduled_at, 'url' => $content->getUrl(true), 'contentcontainer_id' => $content->contentcontainer_id, - 'stream_channel' => $content->stream_channel + 'stream_channel' => $content->stream_channel, ]; } @@ -106,4 +104,4 @@ public static function handleTopicsParam(ActiveQueryContent $query, $contentCont } -} \ No newline at end of file +} diff --git a/definitions/FileDefinitions.php b/definitions/FileDefinitions.php index 3703d35..3d9f3c3 100644 --- a/definitions/FileDefinitions.php +++ b/definitions/FileDefinitions.php @@ -13,7 +13,6 @@ use humhub\modules\content\models\Content; use humhub\modules\file\models\File; - /** * Class FileDefinitions * @@ -21,7 +20,6 @@ */ class FileDefinitions { - public static function getFiles(ActiveRecord $record) { if ($record instanceof Content) { @@ -42,7 +40,7 @@ public static function getFile(File $file) 'mime_type' => $file->mime_type, 'size' => $file->size, 'file_name' => $file->file_name, - 'url' => $file->getUrl([], true) + 'url' => $file->getUrl([], true), ]; } -} \ No newline at end of file +} diff --git a/definitions/LikeDefinitions.php b/definitions/LikeDefinitions.php index d7e636c..0a279b6 100644 --- a/definitions/LikeDefinitions.php +++ b/definitions/LikeDefinitions.php @@ -17,7 +17,6 @@ */ class LikeDefinitions { - public static function getLikesSummary(ActiveRecord $record) { $result = []; @@ -38,8 +37,8 @@ public static function getLike(Like $like) return [ 'id' => $like->id, 'createdBy' => UserDefinitions::getUserShort($like->user), - 'createdAt' => $like->created_at + 'createdAt' => $like->created_at, ]; } -} \ No newline at end of file +} diff --git a/definitions/NotificationDefinitions.php b/definitions/NotificationDefinitions.php index 3fa1cc5..a04dcc2 100644 --- a/definitions/NotificationDefinitions.php +++ b/definitions/NotificationDefinitions.php @@ -21,7 +21,7 @@ public static function getNotification(Notification $notification) 'output' => $baseNotification->html(), 'originator' => UserDefinitions::getUserShort($baseNotification->originator), 'source' => SourceDefinitions::getSource($baseNotification->source), - 'createdAt' => $notification->created_at + 'createdAt' => $notification->created_at, ]; } -} \ No newline at end of file +} diff --git a/definitions/PostDefinitions.php b/definitions/PostDefinitions.php index 81fa914..a653eab 100644 --- a/definitions/PostDefinitions.php +++ b/definitions/PostDefinitions.php @@ -6,8 +6,8 @@ */ namespace humhub\modules\rest\definitions; -use humhub\modules\post\models\Post; +use humhub\modules\post\models\Post; /** * Class PostDefinitions @@ -21,8 +21,8 @@ public static function getPost(Post $post) return [ 'id' => $post->id, 'message' => $post->message, - 'content' => ContentDefinitions::getContent($post->content) + 'content' => ContentDefinitions::getContent($post->content), ]; } -} \ No newline at end of file +} diff --git a/definitions/SourceDefinitions.php b/definitions/SourceDefinitions.php index 859dd2d..2e21550 100644 --- a/definitions/SourceDefinitions.php +++ b/definitions/SourceDefinitions.php @@ -18,16 +18,16 @@ class SourceDefinitions public static function getSource($source) { switch (true) { - case $source instanceof Space : + case $source instanceof Space: return SpaceDefinitions::getSpaceShort($source); - case $source instanceof Post : + case $source instanceof Post: return PostDefinitions::getPost($source); - case $source instanceof Comment : + case $source instanceof Comment: return CommentDefinitions::getComment($source); - case $source instanceof Like : + case $source instanceof Like: return LikeDefinitions::getLike($source); } return get_class($source) . ' definitions are not yet supported.'; } -} \ No newline at end of file +} diff --git a/definitions/SpaceDefinitions.php b/definitions/SpaceDefinitions.php index ad6f610..acca8d8 100644 --- a/definitions/SpaceDefinitions.php +++ b/definitions/SpaceDefinitions.php @@ -11,13 +11,11 @@ use humhub\modules\space\models\Space; use yii\helpers\Url; - /** * Class SpaceDefinitions */ class SpaceDefinitions { - public static function getSpaceShort(Space $space) { return [ @@ -25,7 +23,7 @@ public static function getSpaceShort(Space $space) 'guid' => $space->guid, 'name' => $space->name, 'description' => $space->description, - 'url' => Url::to(['/', 'container' => $space], true) + 'url' => Url::to(['/', 'container' => $space], true), ]; } @@ -70,4 +68,3 @@ public static function getSpaceMembership(Membership $membership) } } - diff --git a/definitions/TopicDefinitions.php b/definitions/TopicDefinitions.php index 8c4a679..1da3249 100644 --- a/definitions/TopicDefinitions.php +++ b/definitions/TopicDefinitions.php @@ -18,4 +18,4 @@ public static function getTopic(Topic $topic) 'name' => $topic->name, ]; } -} \ No newline at end of file +} diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3f14602..2d8b29c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +0.10.5 (Unreleased) +-------------------------- +- Enh #182: Use PHP CS Fixer + 0.10.4 (September 9, 2024) -------------------------- - Enh #180: Improved `user/get-by-authclient` endpoint to support additional authentication clients. diff --git a/migrations/uninstall.php b/migrations/uninstall.php index 285602f..073254f 100644 --- a/migrations/uninstall.php +++ b/migrations/uninstall.php @@ -4,7 +4,6 @@ class uninstall extends Migration { - public function up() { $this->dropTable('impersonate_auth_tokens'); diff --git a/models/ApiUser.php b/models/ApiUser.php index 9d725e0..a77462d 100644 --- a/models/ApiUser.php +++ b/models/ApiUser.php @@ -17,7 +17,6 @@ */ class ApiUser extends Model { - public User $user; /** diff --git a/models/ConfigureForm.php b/models/ConfigureForm.php index adb9f5a..dc0f154 100644 --- a/models/ConfigureForm.php +++ b/models/ConfigureForm.php @@ -44,10 +44,10 @@ public function rules() public function attributeLabels() { return [ - 'enableJwtAuth' => Yii::t('RestModule.base','Allow JWT Authentication'), - 'enableBasicAuth' => Yii::t('RestModule.base','Allow HTTP Basic Authentication'), - 'enableBearerAuth' => Yii::t('RestModule.base','Allow Bearer Authentication'), - 'enableQueryParamAuth' => Yii::t('RestModule.base','Allow Query Param Bearer Authentication'), + 'enableJwtAuth' => Yii::t('RestModule.base', 'Allow JWT Authentication'), + 'enableBasicAuth' => Yii::t('RestModule.base', 'Allow HTTP Basic Authentication'), + 'enableBearerAuth' => Yii::t('RestModule.base', 'Allow Bearer Authentication'), + 'enableQueryParamAuth' => Yii::t('RestModule.base', 'Allow Query Param Bearer Authentication'), 'enabledForAllUsers' => Yii::t('RestModule.base', 'Enabled for all registered users'), ]; } @@ -67,11 +67,11 @@ public function loadSettings() $settings = $module->settings; - $this->enableJwtAuth = (boolean)$settings->get('enableJwtAuth'); - $this->enableBasicAuth = (boolean)$settings->get('enableBasicAuth'); - $this->enableBearerAuth = (boolean)$settings->get('enableBearerAuth'); - $this->enableQueryParamAuth = (boolean)$settings->get('enableQueryParamAuth'); - $this->enabledForAllUsers = (boolean)$settings->get('enabledForAllUsers'); + $this->enableJwtAuth = (bool)$settings->get('enableJwtAuth'); + $this->enableBasicAuth = (bool)$settings->get('enableBasicAuth'); + $this->enableBearerAuth = (bool)$settings->get('enableBearerAuth'); + $this->enableQueryParamAuth = (bool)$settings->get('enableQueryParamAuth'); + $this->enabledForAllUsers = (bool)$settings->get('enabledForAllUsers'); $this->enabledUsers = (array)$settings->getSerialized('enabledUsers'); foreach ($module->getModulesWithRestApi() as $apiModule) { @@ -88,14 +88,14 @@ public function saveSettings() /** @var Module $module */ $module = Yii::$app->getModule('rest'); - if (!$this->enableBearerAuth ) { + if (!$this->enableBearerAuth) { $this->enableQueryParamAuth = false; } - $module->settings->set('enableJwtAuth', (boolean)$this->enableJwtAuth); - $module->settings->set('enableBasicAuth', (boolean)$this->enableBasicAuth); - $module->settings->set('enableBearerAuth', (boolean)$this->enableBearerAuth); - $module->settings->set('enableQueryParamAuth', (boolean)$this->enableQueryParamAuth); + $module->settings->set('enableJwtAuth', (bool)$this->enableJwtAuth); + $module->settings->set('enableBasicAuth', (bool)$this->enableBasicAuth); + $module->settings->set('enableBearerAuth', (bool)$this->enableBearerAuth); + $module->settings->set('enableQueryParamAuth', (bool)$this->enableQueryParamAuth); $module->settings->set('enabledForAllUsers', $this->enabledForAllUsers); $module->settings->setSerialized('enabledUsers', (array)$this->enabledUsers); @@ -110,7 +110,7 @@ public function saveSettings() public static function getInstance() { - $config = new static; + $config = new static(); $config->loadSettings(); return $config; diff --git a/models/ImpersonateAuthToken.php b/models/ImpersonateAuthToken.php index 26f68e8..0fa5265 100644 --- a/models/ImpersonateAuthToken.php +++ b/models/ImpersonateAuthToken.php @@ -13,7 +13,6 @@ use humhub\libs\DbDateValidator; use humhub\modules\user\models\User; - /** * @property int $id * @property int $user_id @@ -35,10 +34,10 @@ public function rules() [['user_id'], 'required'], [['user_id'], 'unique'], [['user_id'], 'exist', 'targetRelation' => 'user', 'targetAttribute' => 'id'], - [['expiration'], 'default', 'value' => function() { + [['expiration'], 'default', 'value' => function () { return new Expression('DATE_ADD(NOW(), INTERVAL 30 MINUTE)'); }], - [['token'], 'default', 'value' => function() { + [['token'], 'default', 'value' => function () { return 'impersonated-' . Yii::$app->security->generateRandomString(73); }], ]; diff --git a/models/JwtAuthForm.php b/models/JwtAuthForm.php index 0a8760b..3b7ac03 100644 --- a/models/JwtAuthForm.php +++ b/models/JwtAuthForm.php @@ -21,7 +21,7 @@ public function rules() { return [ [['jwtKey'], 'string', 'min' => 32, 'max' => 128], - [['jwtExpire'], 'integer'] + [['jwtExpire'], 'integer'], ]; } @@ -72,7 +72,7 @@ public function saveSettings() public static function getInstance() { - $config = new static; + $config = new static(); $config->loadSettings(); return $config; diff --git a/models/RestUserBearerToken.php b/models/RestUserBearerToken.php index 1d93ec7..5f65212 100644 --- a/models/RestUserBearerToken.php +++ b/models/RestUserBearerToken.php @@ -13,7 +13,6 @@ use humhub\libs\DbDateValidator; use humhub\modules\user\models\User; - /** * @property int $id * @property int $user_id @@ -48,10 +47,10 @@ public function rules() public function attributeLabels() { return [ - 'user_id' => Yii::t('RestModule.base','User'), - 'userGuid' => Yii::t('RestModule.base','User'), - 'token' => Yii::t('RestModule.base','Token'), - 'expiration' => Yii::t('RestModule.base','Expiration'), + 'user_id' => Yii::t('RestModule.base', 'User'), + 'userGuid' => Yii::t('RestModule.base', 'User'), + 'token' => Yii::t('RestModule.base', 'Token'), + 'expiration' => Yii::t('RestModule.base', 'Expiration'), ]; } diff --git a/module.json b/module.json index 41f7c1c..ec89978 100644 --- a/module.json +++ b/module.json @@ -5,7 +5,7 @@ "keywords": [ "api", "rest" ], - "version": "0.10.4", + "version": "0.10.5", "homepage": "https://github.com/humhub/rest", "humhub": { "minVersion": "1.16" diff --git a/tests/codeception/_bootstrap.php b/tests/codeception/_bootstrap.php index 6018c88..4c262f3 100644 --- a/tests/codeception/_bootstrap.php +++ b/tests/codeception/_bootstrap.php @@ -32,4 +32,4 @@ $globalConfig = require $humhubPath . '/protected/humhub/tests/codeception/_loadConfig.php'; // Load default test bootstrap (initialize Yii...) -require $globalConfig['humhub_root'] . '/protected/humhub/tests/codeception/_bootstrap.php'; \ No newline at end of file +require $globalConfig['humhub_root'] . '/protected/humhub/tests/codeception/_bootstrap.php'; diff --git a/tests/codeception/_support/AcceptanceTester.php b/tests/codeception/_support/AcceptanceTester.php index a146af2..7aea5e8 100644 --- a/tests/codeception/_support/AcceptanceTester.php +++ b/tests/codeception/_support/AcceptanceTester.php @@ -8,7 +8,9 @@ namespace rest; -use rest\_generated;; +use rest\_generated; + +; /** * Inherited Methods @@ -29,7 +31,7 @@ class AcceptanceTester extends \AcceptanceTester { use _generated\AcceptanceTesterActions; - /** - * Define custom actions here - */ + /** + * Define custom actions here + */ } diff --git a/tests/codeception/_support/ApiTester.php b/tests/codeception/_support/ApiTester.php index 35ab581..a25b736 100644 --- a/tests/codeception/_support/ApiTester.php +++ b/tests/codeception/_support/ApiTester.php @@ -1,4 +1,5 @@ sendPost('post/container/1', [ 'data' => [ 'message' => 'New created message from API test', - ] + ], ]); $I->seeSuccessResponseContainsJson($this->getRecordDefinition(15)); } @@ -71,17 +71,17 @@ public function testCreateScheduled(ApiTester $I) 'content' => [ 'metadata' => [ 'scheduled_at' => $scheduledDate, - ] - ] - ] + ], + ], + ], ]); $I->seeSuccessResponseContainsJson(ArrayHelper::merge($this->getRecordDefinition(16), [ 'content' => [ 'metadata' => [ - 'scheduled_at' => $scheduledDate - ] - ] + 'scheduled_at' => $scheduledDate, + ], + ], ])); } @@ -93,7 +93,7 @@ public function testUpdate(ApiTester $I) $I->sendPut('post/1', [ 'data' => [ 'message' => 'Updated message for Post 1', - ] + ], ]); $I->seeSuccessResponseContainsJson($this->getRecordDefinition(1)); diff --git a/tests/codeception/api/UserCest.php b/tests/codeception/api/UserCest.php index 5074997..a824d67 100644 --- a/tests/codeception/api/UserCest.php +++ b/tests/codeception/api/UserCest.php @@ -98,7 +98,7 @@ public function testUpdate(ApiTester $I) $I->sendPut('user/2', [ 'account' => [ - 'username' => 'User1_updated' + 'username' => 'User1_updated', ], 'profile' => [ 'firstname' => 'Peter Updated', diff --git a/tests/codeception/api/_bootstrap.php b/tests/codeception/api/_bootstrap.php index 0f508ca..9e54876 100644 --- a/tests/codeception/api/_bootstrap.php +++ b/tests/codeception/api/_bootstrap.php @@ -3,4 +3,4 @@ * Initialize the HumHub Application for functional testing. The default application configuration for this suite can be overwritten * in @tests/config/functional.php */ -require(Yii::getAlias('@humhubTests/codeception/acceptance/_bootstrap.php')); \ No newline at end of file +require(Yii::getAlias('@humhubTests/codeception/acceptance/_bootstrap.php')); diff --git a/tests/codeception/config/unit.php b/tests/codeception/config/unit.php index 44c0233..15d0428 100644 --- a/tests/codeception/config/unit.php +++ b/tests/codeception/config/unit.php @@ -1,3 +1,3 @@ 'Comment 1 of the Post 1', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => 1, 'created_at' => '2021-05-13 09:33:00', 'created_by' => 1, 'updated_at' => '2021-05-13 09:33:00', 'updated_by' => 1], ]; diff --git a/tests/codeception/fixtures/data/content.php b/tests/codeception/fixtures/data/content.php index 70ddb87..0d2c18b 100644 --- a/tests/codeception/fixtures/data/content.php +++ b/tests/codeception/fixtures/data/content.php @@ -1,4 +1,5 @@ 'e0acdc54-13c8-4778-adc1-7302e324e100', 'object_model' => 'humhub\modules\activity\models\Activity', 'object_id' => 100, 'visibility' => '0', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 4, 'created_at' => '2021-05-14 14:40:00', 'created_by' => '2', 'updated_at' => '2021-05-14 14:40:00', 'updated_by' => '2', 'stream_channel' => 'activity'], ['guid' => 'e0acdc54-13c8-4778-adc1-7302e324e101', 'object_model' => 'humhub\modules\activity\models\Activity', 'object_id' => 101, 'visibility' => '0', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 4, 'created_at' => '2021-05-14 14:40:00', 'created_by' => '3', 'updated_at' => '2021-05-14 14:40:00', 'updated_by' => '3', 'stream_channel' => 'activity'], diff --git a/tests/codeception/fixtures/data/notification.php b/tests/codeception/fixtures/data/notification.php index 18099eb..f1fbab1 100644 --- a/tests/codeception/fixtures/data/notification.php +++ b/tests/codeception/fixtures/data/notification.php @@ -1,4 +1,5 @@ 'humhub\modules\comment\notifications\NewComment', 'user_id' => 1, 'seen' => 0, 'source_class' => 'humhub\modules\comment\models\Comment', 'source_pk' => 1, 'space_id' => 1, 'created_at' => '2021-05-14 19:16:00', 'originator_user_id' => 3, 'module' => 'comment', 'group_key' => 'humhub\modules\post\models\Post-1'], ['class' => 'humhub\modules\comment\notifications\NewComment', 'user_id' => 2, 'seen' => 0, 'source_class' => 'humhub\modules\comment\models\Comment', 'source_pk' => 1, 'space_id' => 1, 'created_at' => '2021-05-14 19:16:00', 'originator_user_id' => 3, 'module' => 'comment', 'group_key' => 'humhub\modules\post\models\Post-1'], diff --git a/tests/codeception/fixtures/data/setting.php b/tests/codeception/fixtures/data/setting.php index 98ddeb6..3840802 100644 --- a/tests/codeception/fixtures/data/setting.php +++ b/tests/codeception/fixtures/data/setting.php @@ -1,4 +1,5 @@ 'enableJwtAuth', 'value' => '1', 'module_id' => 'rest'], ['name' => 'enableBearerAuth', 'value' => '1', 'module_id' => 'rest'], diff --git a/tests/config/test.php b/tests/config/test.php index 726273e..9e3029f 100644 --- a/tests/config/test.php +++ b/tests/config/test.php @@ -21,6 +21,3 @@ 'humhub\modules\rest\tests\codeception\fixtures\BearerAccessTokenFixture', ], ]; - - -