Skip to content

Commit

Permalink
Merge pull request #26 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 3, 2024
2 parents 82c068f + 37ba2d5 commit 2f01fd4
Show file tree
Hide file tree
Showing 33 changed files with 115 additions and 109 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 Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getPermissions($contentContainer = null)
if ($contentContainer instanceof Space) {
return [
new permissions\CreateQuestion(),
new permissions\SelectBestAnswer()
new permissions\SelectBestAnswer(),
];
}

Expand Down
2 changes: 1 addition & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
'namespace' => 'humhub\modules\questions',
'events' => [
[WallEntryLinks::class, WallEntryLinks::EVENT_INIT, [Events::class, 'onWallEntryLinksInit']],
]
],
];
21 changes: 10 additions & 11 deletions controllers/AnswerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*/
class AnswerController extends ContentContainerController
{

/**
* @param int $id
* @throws ForbiddenHttpException
Expand All @@ -48,8 +47,8 @@ public function actionContent($id)
'answer' => $answer->id,
'content' => Answer::widget([
'answer' => $answer,
'highlight' => true
])
'highlight' => true,
]),
]);
}

Expand Down Expand Up @@ -95,18 +94,18 @@ public function actionEdit($qid, $id = null)
'count' => $question->getAnswerService()->getExceptBestQuery()->count(),
'content' => Answer::widget([
'answer' => $answer,
'highlight' => true
'highlight' => true,
]),
'form' => $answerFormId === 0 ? AnswerForm::widget(['question' => $question]) : null
'form' => $answerFormId === 0 ? AnswerForm::widget(['question' => $question]) : null,
]);
}

return $this->asJson([
'answerFormId' => $answerFormId,
'form' => AnswerForm::widget([
'question' => $question,
'answer' => $answer
])
'answer' => $answer,
]),
]);
}

Expand All @@ -133,7 +132,7 @@ public function actionVote($id, $vote)

return $this->asJson([
'success' => true,
'content' => AnswerVoting::widget(['answer' => $answer])
'content' => AnswerVoting::widget(['answer' => $answer]),
]);
}

Expand Down Expand Up @@ -169,7 +168,7 @@ public function actionSelectBest($id)
'count' => $question->getAnswerService()->getExceptBestQuery()->count(),
'action' => $answer->is_best ? 'selected' : 'unselected',
'titleSelect' => Yii::t('QuestionsModule.base', 'Select best answer'),
'titleUnselect' => Yii::t('QuestionsModule.base', 'Unselect best answer')
'titleUnselect' => Yii::t('QuestionsModule.base', 'Unselect best answer'),
]);
}

Expand All @@ -196,15 +195,15 @@ public function actionDelete($id)
if (!$answer->delete()) {
return $this->asJson([
'success' => false,
'message' => Yii::t('QuestionsModule.base', 'Cannot delete the Answer!')
'message' => Yii::t('QuestionsModule.base', 'Cannot delete the Answer!'),
]);
}

return $this->asJson([
'success' => true,
'answer' => $deletedAnswerId,
'count' => $question->getAnswerService()->getExceptBestQuery()->count(),
'message' => Yii::t('QuestionsModule.base', 'Deleted')
'message' => Yii::t('QuestionsModule.base', 'Deleted'),
]);
}

Expand Down
7 changes: 3 additions & 4 deletions controllers/QuestionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*/
class QuestionController extends ContentContainerController
{

/**
* @return string
* @throws ForbiddenHttpException
Expand Down Expand Up @@ -102,8 +101,8 @@ public function actionEdit($id)
'content-component' => 'questions.Question',
'content-key' => $question->content->id,
],
'class' => 'content_edit'
]
'class' => 'content_edit',
],
]);
}

Expand All @@ -129,7 +128,7 @@ public function actionView($id, $aid = null)
return $this->render('view', [
'question' => $question,
'currentAnswerId' => $aid,
'renderOptions' => $renderOptions
'renderOptions' => $renderOptions,
]);
}

Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.0.7 (Unreleased)
------------------------
- Enh #26: Use PHP CS Fixer

1.0.6 (March 3, 2023)
------------------------
- Fix #21: Space configuration checks permissions insufficiently
Expand Down
37 changes: 20 additions & 17 deletions helpers/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@

class Url extends BaseUrl
{
const ROUTE_MODULE = '/questions';
const ROUTE_SETTINGS = self::ROUTE_MODULE . '/settings';

const ROUTE_QUESTION = self::ROUTE_MODULE . '/question';
const ROUTE_QUESTION_CREATE = self::ROUTE_QUESTION . '/create';
const ROUTE_QUESTION_CREATE_FORM = self::ROUTE_QUESTION . '/create-form';
const ROUTE_QUESTION_EDIT = self::ROUTE_QUESTION . '/edit';
const ROUTE_QUESTION_VIEW = self::ROUTE_QUESTION . '/view';

const ROUTE_ANSWER = self::ROUTE_MODULE . '/answer';
const ROUTE_ANSWER_EDIT = self::ROUTE_ANSWER . '/edit';
const ROUTE_ANSWER_CONTENT = self::ROUTE_ANSWER . '/content';
const ROUTE_ANSWER_VOTE = self::ROUTE_ANSWER . '/vote';
const ROUTE_ANSWER_SELECT_BEST = self::ROUTE_ANSWER . '/select-best';
const ROUTE_ANSWER_DELETE = self::ROUTE_ANSWER . '/delete';
public const ROUTE_MODULE = '/questions';
public const ROUTE_SETTINGS = self::ROUTE_MODULE . '/settings';

public const ROUTE_QUESTION = self::ROUTE_MODULE . '/question';
public const ROUTE_QUESTION_CREATE = self::ROUTE_QUESTION . '/create';
public const ROUTE_QUESTION_CREATE_FORM = self::ROUTE_QUESTION . '/create-form';
public const ROUTE_QUESTION_EDIT = self::ROUTE_QUESTION . '/edit';
public const ROUTE_QUESTION_VIEW = self::ROUTE_QUESTION . '/view';

public const ROUTE_ANSWER = self::ROUTE_MODULE . '/answer';
public const ROUTE_ANSWER_EDIT = self::ROUTE_ANSWER . '/edit';
public const ROUTE_ANSWER_CONTENT = self::ROUTE_ANSWER . '/content';
public const ROUTE_ANSWER_VOTE = self::ROUTE_ANSWER . '/vote';
public const ROUTE_ANSWER_SELECT_BEST = self::ROUTE_ANSWER . '/select-best';
public const ROUTE_ANSWER_DELETE = self::ROUTE_ANSWER . '/delete';

private static function create($route, $params = [], ContentContainerActiveRecord $container = null, bool $scheme = false)
{
Expand All @@ -54,9 +54,12 @@ public static function toViewQuestion(Question $question, array $params = [], bo
$anchor = '';
}

return static::create(static::ROUTE_QUESTION_VIEW,
return static::create(
static::ROUTE_QUESTION_VIEW,
array_merge(['id' => $question->id], $params),
$question->content->container, $scheme) . $anchor;
$question->content->container,
$scheme,
) . $anchor;
}

public static function toEditQuestion(Question $question): string
Expand Down
4 changes: 2 additions & 2 deletions migrations/m230626_112542_initial.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function safeUp()
'created_at' => $this->dateTime()->notNull(),
'created_by' => $this->integer()->notNull(),
'updated_at' => $this->dateTime()->notNull(),
'updated_by' => $this->integer()->notNull()
'updated_by' => $this->integer()->notNull(),
]);
$this->safeAddForeignKey('fk_questions_question_id', 'question_answer', 'question_id', 'question', 'id', 'CASCADE');
$this->safeCreateIndex('idx_is_best', 'question_answer', 'is_best');
Expand All @@ -42,7 +42,7 @@ public function safeUp()
$this->safeCreateTable('question_answer_vote', [
'answer_id' => $this->integer()->notNull(),
'user_id' => $this->integer()->notNull(),
'type' => $this->tinyInteger(1)->notNull()
'type' => $this->tinyInteger(1)->notNull(),
]);
$this->safeAddPrimaryKey('pk_question_answer_vote', 'question_answer_vote', 'answer_id,user_id');
$this->safeAddForeignKey('fk_questions_answer_id', 'question_answer_vote', 'answer_id', 'question_answer', 'id', 'CASCADE');
Expand Down
48 changes: 24 additions & 24 deletions migrations/uninstall.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

use humhub\components\Migration;

class uninstall extends Migration
{
public function up()
{
$this->safeDropTable('question_answer_vote');
$this->safeDropTable('question_answer');
$this->safeDropTable('question');
}

public function down()
{
echo "uninstall does not support migration down.\n";
return false;
}
}
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

use humhub\components\Migration;

class uninstall extends Migration
{
public function up()
{
$this->safeDropTable('question_answer_vote');
$this->safeDropTable('question_answer');
$this->safeDropTable('question');
}

public function down()
{
echo "uninstall does not support migration down.\n";
return false;
}
}
4 changes: 2 additions & 2 deletions models/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Question model class.
*
* The followings are the available columns in table 'question':
* @property integer $id
* @property int $id
* @property string $question
* @property string $description
*
Expand Down Expand Up @@ -141,7 +141,7 @@ public function getSearchAttributes()
return [
'question' => $this->question,
'description' => $this->description,
'itemAnswers' => trim($itemAnswers)
'itemAnswers' => trim($itemAnswers),
];
}

Expand Down
6 changes: 3 additions & 3 deletions models/QuestionAnswer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
* @property int $votes_summary
* @property bool $is_best
* @property string $created_at
* @property integer $created_by
* @property int $created_by
* @property string $updated_at
* @property integer $updated_by
* @property int $updated_by
*
* @property-read Question $question
*
Expand Down Expand Up @@ -63,7 +63,7 @@ public function rules()
public function attributeLabels()
{
return [
'answer' => Yii::t('QuestionsModule.base', 'Provide an answer')
'answer' => Yii::t('QuestionsModule.base', 'Provide an answer'),
];
}

Expand Down
4 changes: 2 additions & 2 deletions models/QuestionAnswerVote.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
*/
class QuestionAnswerVote extends ActiveRecord
{
const TYPE_UP = 1;
const TYPE_DOWN = -1;
public const TYPE_UP = 1;
public const TYPE_DOWN = -1;

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

public ContentContainerActiveRecord $contentContainer;
protected ?ContentContainerSettingsManager $settings = null;
public bool $showAnswersInStream = false;
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Q&A",
"description": "Elevate your knowledge sharing experience by enabling users to ask questions and upvote the most helpful answers.",
"keywords": ["Q&A", "questions answers"],
"version": "1.0.6",
"version": "1.0.7",
"humhub": {
"minVersion": "1.14"
},
Expand Down
6 changes: 3 additions & 3 deletions notifications/AnsweredNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public function html()
return Yii::t('QuestionsModule.base', '{displayName} has answered your Question "{contentTitle}" in Space {spaceName}.', [
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
'contentTitle' => $this->getContentInfo($this->source->question, false),
'spaceName' => Html::encode($this->source->question->content->container->displayName)
'spaceName' => Html::encode($this->source->question->content->container->displayName),
]);
}

return Yii::t('QuestionsModule.base', '{displayName} has answered your Question "{contentTitle}".', [
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
'contentTitle' => $this->getContentInfo($this->source->question, false)
'contentTitle' => $this->getContentInfo($this->source->question, false),
]);
}

Expand All @@ -64,7 +64,7 @@ public function html()
public function getMailSubject()
{
return Yii::t('QuestionsModule.base', 'New answer to your Question "{questionTitle}"', [
'questionTitle' => $this->source->question->question
'questionTitle' => $this->source->question->question,
]);
}

Expand Down
6 changes: 3 additions & 3 deletions notifications/NewQuestionNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public function html()
return Yii::t('QuestionsModule.base', '{displayName} has created the Question "{contentTitle}" in Space {spaceName}.', [
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
'contentTitle' => $this->getContentInfo($this->source, false),
'spaceName' => Html::encode($this->source->content->container->displayName)
'spaceName' => Html::encode($this->source->content->container->displayName),
]);
}

return Yii::t('QuestionsModule.base', '{displayName} has created the Question "{contentTitle}".', [
'displayName' => Html::tag('strong', Html::encode($this->originator->displayName)),
'contentTitle' => $this->getContentInfo($this->source, false)
'contentTitle' => $this->getContentInfo($this->source, false),
]);
}

Expand All @@ -63,7 +63,7 @@ public function html()
public function getMailSubject()
{
return Yii::t('QuestionsModule.base', 'New Question "{questionTitle}"', [
'questionTitle' => $this->source->question
'questionTitle' => $this->source->question,
]);
}

Expand Down
Loading

0 comments on commit 2f01fd4

Please sign in to comment.