mirror of
https://github.com/Karaka-Management/oms-QA.git
synced 2026-01-11 15:48:42 +00:00
fix phpstan/phpcs
This commit is contained in:
parent
fd9a5ce821
commit
dde78cf377
|
|
@ -242,13 +242,13 @@ final class ApiController extends Controller
|
|||
{
|
||||
$mardkownParser = new Markdown();
|
||||
|
||||
$answer = new QAAnswer();
|
||||
$answer->answerRaw = (string) $request->getData('plain');
|
||||
$answer->answer = Markdown::parse((string) ($request->getData('plain') ?? ''));
|
||||
$answer->question = new NullQAQuestion((int) $request->getData('question'));
|
||||
$answer->isAccepted = false;
|
||||
$answer = new QAAnswer();
|
||||
$answer->answerRaw = (string) $request->getData('plain');
|
||||
$answer->answer = Markdown::parse((string) ($request->getData('plain') ?? ''));
|
||||
$answer->question = new NullQAQuestion((int) $request->getData('question'));
|
||||
$answer->isAccepted = false;
|
||||
$answer->setStatus((int) $request->getData('status'));
|
||||
$answer->createdBy = new NullAccount($request->header->account);
|
||||
$answer->createdBy = new Profile(new NullAccount($request->header->account));
|
||||
|
||||
return $answer;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -215,6 +215,13 @@ class QAAnswer implements \JsonSerializable
|
|||
$this->isAccepted = $accepted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total vote score
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getVoteScore() : int
|
||||
{
|
||||
$score = 0;
|
||||
|
|
@ -225,6 +232,15 @@ class QAAnswer implements \JsonSerializable
|
|||
return $score;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the vote score from an account
|
||||
*
|
||||
* @param int $account Account id
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getAccountVoteScore(int $account) : int
|
||||
{
|
||||
foreach ($this->votes as $vote) {
|
||||
|
|
@ -236,18 +252,6 @@ class QAAnswer implements \JsonSerializable
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the answer accepted
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function isAccepted() : bool
|
||||
{
|
||||
return $this->isAccepted;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -78,12 +78,22 @@ final class QAAnswerVoteMapper extends DataMapperAbstract
|
|||
*/
|
||||
protected static string $primaryField = 'qa_answer_vote_id';
|
||||
|
||||
public static function findVote(int $question, int $account)
|
||||
/**
|
||||
* Find vote for answer from user
|
||||
*
|
||||
* @param int $answer Answer id
|
||||
* @param int $account Account id
|
||||
*
|
||||
* @return QAAnswerVote
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function findVote(int $answer, int $account) : QAAnswerVote
|
||||
{
|
||||
$depth = 3;
|
||||
$query = self::getQuery();
|
||||
$query->where(self::$table . '_' . $depth . '.qa_answer_vote_created_by', '=', $account)
|
||||
->andWhere(self::$table . '_' . $depth . '.qa_answer_vote_answer', '=', $question);
|
||||
$query->where(self::$table . '_d' . $depth . '.qa_answer_vote_created_by', '=', $account)
|
||||
->andWhere(self::$table . '_d' . $depth . '.qa_answer_vote_answer', '=', $answer);
|
||||
|
||||
$results = self::getAllByQuery($query);
|
||||
|
||||
|
|
|
|||
|
|
@ -267,6 +267,8 @@ class QAQuestion implements \JsonSerializable
|
|||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getTags() : array
|
||||
{
|
||||
|
|
@ -277,8 +279,10 @@ class QAQuestion implements \JsonSerializable
|
|||
* Add tag to question
|
||||
*
|
||||
* @param int|Tag $tag Tag
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function addTag($tag) : void
|
||||
public function addTag(int|Tag $tag) : void
|
||||
{
|
||||
$this->tags[] = $tag;
|
||||
}
|
||||
|
|
@ -287,17 +291,33 @@ class QAQuestion implements \JsonSerializable
|
|||
* Set tags to question
|
||||
*
|
||||
* @param array<int, int|Tag> $tags Tags
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setTags(array $tags) : void
|
||||
{
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the answers
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getAnswerCount() : int
|
||||
{
|
||||
return \count($this->answers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total vote score
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getVoteScore() : int
|
||||
{
|
||||
$score = 0;
|
||||
|
|
@ -308,6 +328,15 @@ class QAQuestion implements \JsonSerializable
|
|||
return $score;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the vote score from an account
|
||||
*
|
||||
* @param int $account Account id
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getAccountVoteScore(int $account) : int
|
||||
{
|
||||
foreach ($this->votes as $vote) {
|
||||
|
|
|
|||
|
|
@ -78,12 +78,22 @@ final class QAQuestionVoteMapper extends DataMapperAbstract
|
|||
*/
|
||||
protected static string $primaryField = 'qa_question_vote_id';
|
||||
|
||||
public static function findVote(int $question, int $account)
|
||||
/**
|
||||
* Find vote for question from user
|
||||
*
|
||||
* @param int $question Question id
|
||||
* @param int $account Account id
|
||||
*
|
||||
* @return QAQuestionVote
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function findVote(int $question, int $account) : QAQuestionVote
|
||||
{
|
||||
$depth = 3;
|
||||
$query = self::getQuery();
|
||||
$query->where(self::$table . '_' . $depth . '.qa_question_vote_created_by', '=', $account)
|
||||
->andWhere(self::$table . '_' . $depth . '.qa_question_vote_question', '=', $question);
|
||||
$query->where(self::$table . '_d' . $depth . '.qa_question_vote_created_by', '=', $account)
|
||||
->andWhere(self::$table . '_d' . $depth . '.qa_question_vote_question', '=', $question);
|
||||
|
||||
$results = self::getAllByQuery($query);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
],
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": ">=9.4",
|
||||
"friendsofphp/php-cs-fixer": ">=2.18",
|
||||
"friendsofphp/php-cs-fixer": ">=3.0",
|
||||
"squizlabs/php_codesniffer": ">=3.5",
|
||||
"phpmd/phpmd": ">=2.9",
|
||||
"phpstan/phpstan": ">=0.12.58",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user