fix phpstan/phpcs

This commit is contained in:
Dennis Eichhorn 2021-06-26 14:38:08 +02:00
parent fd9a5ce821
commit dde78cf377
6 changed files with 79 additions and 26 deletions

View File

@ -242,13 +242,13 @@ final class ApiController extends Controller
{ {
$mardkownParser = new Markdown(); $mardkownParser = new Markdown();
$answer = new QAAnswer(); $answer = new QAAnswer();
$answer->answerRaw = (string) $request->getData('plain'); $answer->answerRaw = (string) $request->getData('plain');
$answer->answer = Markdown::parse((string) ($request->getData('plain') ?? '')); $answer->answer = Markdown::parse((string) ($request->getData('plain') ?? ''));
$answer->question = new NullQAQuestion((int) $request->getData('question')); $answer->question = new NullQAQuestion((int) $request->getData('question'));
$answer->isAccepted = false; $answer->isAccepted = false;
$answer->setStatus((int) $request->getData('status')); $answer->setStatus((int) $request->getData('status'));
$answer->createdBy = new NullAccount($request->header->account); $answer->createdBy = new Profile(new NullAccount($request->header->account));
return $answer; return $answer;
} }

View File

@ -215,6 +215,13 @@ class QAAnswer implements \JsonSerializable
$this->isAccepted = $accepted; $this->isAccepted = $accepted;
} }
/**
* Get the total vote score
*
* @return int
*
* @since 1.0.0
*/
public function getVoteScore() : int public function getVoteScore() : int
{ {
$score = 0; $score = 0;
@ -225,6 +232,15 @@ class QAAnswer implements \JsonSerializable
return $score; 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 public function getAccountVoteScore(int $account) : int
{ {
foreach ($this->votes as $vote) { foreach ($this->votes as $vote) {
@ -236,18 +252,6 @@ class QAAnswer implements \JsonSerializable
return 0; return 0;
} }
/**
* Is the answer accepted
*
* @return bool
*
* @since 1.0.0
*/
public function isAccepted() : bool
{
return $this->isAccepted;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -78,12 +78,22 @@ final class QAAnswerVoteMapper extends DataMapperAbstract
*/ */
protected static string $primaryField = 'qa_answer_vote_id'; 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; $depth = 3;
$query = self::getQuery(); $query = self::getQuery();
$query->where(self::$table . '_' . $depth . '.qa_answer_vote_created_by', '=', $account) $query->where(self::$table . '_d' . $depth . '.qa_answer_vote_created_by', '=', $account)
->andWhere(self::$table . '_' . $depth . '.qa_answer_vote_answer', '=', $question); ->andWhere(self::$table . '_d' . $depth . '.qa_answer_vote_answer', '=', $answer);
$results = self::getAllByQuery($query); $results = self::getAllByQuery($query);

View File

@ -267,6 +267,8 @@ class QAQuestion implements \JsonSerializable
* @return array * @return array
* *
* @since 1.0.0 * @since 1.0.0
*
* @since 1.0.0
*/ */
public function getTags() : array public function getTags() : array
{ {
@ -277,8 +279,10 @@ class QAQuestion implements \JsonSerializable
* Add tag to question * Add tag to question
* *
* @param int|Tag $tag Tag * @param int|Tag $tag Tag
*
* @since 1.0.0
*/ */
public function addTag($tag) : void public function addTag(int|Tag $tag) : void
{ {
$this->tags[] = $tag; $this->tags[] = $tag;
} }
@ -287,17 +291,33 @@ class QAQuestion implements \JsonSerializable
* Set tags to question * Set tags to question
* *
* @param array<int, int|Tag> $tags Tags * @param array<int, int|Tag> $tags Tags
*
* @since 1.0.0
*/ */
public function setTags(array $tags) : void public function setTags(array $tags) : void
{ {
$this->tags = $tags; $this->tags = $tags;
} }
/**
* Count the answers
*
* @return int
*
* @since 1.0.0
*/
public function getAnswerCount() : int public function getAnswerCount() : int
{ {
return \count($this->answers); return \count($this->answers);
} }
/**
* Get the total vote score
*
* @return int
*
* @since 1.0.0
*/
public function getVoteScore() : int public function getVoteScore() : int
{ {
$score = 0; $score = 0;
@ -308,6 +328,15 @@ class QAQuestion implements \JsonSerializable
return $score; 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 public function getAccountVoteScore(int $account) : int
{ {
foreach ($this->votes as $vote) { foreach ($this->votes as $vote) {

View File

@ -78,12 +78,22 @@ final class QAQuestionVoteMapper extends DataMapperAbstract
*/ */
protected static string $primaryField = 'qa_question_vote_id'; 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; $depth = 3;
$query = self::getQuery(); $query = self::getQuery();
$query->where(self::$table . '_' . $depth . '.qa_question_vote_created_by', '=', $account) $query->where(self::$table . '_d' . $depth . '.qa_question_vote_created_by', '=', $account)
->andWhere(self::$table . '_' . $depth . '.qa_question_vote_question', '=', $question); ->andWhere(self::$table . '_d' . $depth . '.qa_question_vote_question', '=', $question);
$results = self::getAllByQuery($query); $results = self::getAllByQuery($query);

View File

@ -9,7 +9,7 @@
], ],
"require-dev": { "require-dev": {
"phpunit/phpunit": ">=9.4", "phpunit/phpunit": ">=9.4",
"friendsofphp/php-cs-fixer": ">=2.18", "friendsofphp/php-cs-fixer": ">=3.0",
"squizlabs/php_codesniffer": ">=3.5", "squizlabs/php_codesniffer": ">=3.5",
"phpmd/phpmd": ">=2.9", "phpmd/phpmd": ">=2.9",
"phpstan/phpstan": ">=0.12.58", "phpstan/phpstan": ">=0.12.58",