fix phpstan/phpcs

This commit is contained in:
Dennis Eichhorn 2021-06-26 14:38:08 +02:00
parent 8cf249716a
commit 5d11460abd
6 changed files with 70 additions and 29 deletions

View File

@ -26,6 +26,17 @@ return [
],
],
],
'^.*/comment/list(\?.*|$)' => [
[
'dest' => '\Modules\Comments\Controller\ApiController:apiCommentListUpdate',
'verb' => RouteVerb::SET,
'permission' => [
'module' => ApiController::MODULE_NAME,
'type' => PermissionType::CREATE,
'state' => PermissionState::LIST,
],
],
],
'^.*/comment/vote(\?.*|$)' => [
[
'dest' => '\Modules\Comments\Controller\ApiController:apiChangeCommentVote',

View File

@ -91,7 +91,7 @@ final class ApiController extends Controller
{
$old = clone CommentListMapper::get((int) $request->getData('id'));
$new = $this->updateCommentListFromRequest($request);
$this->updateModel($request->header->account, $old, $new, CommentMapper::class, 'comment_list', $request->getOrigin());
$this->updateModel($request->header->account, $old, $new, CommentListMapper::class, 'comment_list', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Comment List', 'Comment list successfully updated', $new);
}
@ -100,16 +100,16 @@ final class ApiController extends Controller
*
* @param RequestAbstract $request Request
*
* @return Comment
* @return CommentList
*
* @since 1.0.0
*/
private function updateCommentListFromRequest(RequestAbstract $request) : Comment
private function updateCommentListFromRequest(RequestAbstract $request) : CommentList
{
$list = CommentListMapper::get((int) $request->getData('id'));
$list->allowEdit = (bool) ($request->getData('allow_edit') ?? $list->allowEdit);
$list->allowVoting = (bool) ($request->getData('allow_voting') ?? $list->allowVoting);
$list->allowFiles = (bool) ($request->getData('allow_upload') ?? $list->allowFiles);
$list->allowEdit = (bool) ($request->getData('allow_edit') ?? false);
$list->allowVoting = (bool) ($request->getData('allow_voting') ?? false);
$list->allowFiles = (bool) ($request->getData('allow_upload') ?? false);
$list->status = (int) ($request->getData('commentlist_status') ?? $list->status);
return $list;
@ -280,19 +280,20 @@ final class ApiController extends Controller
*/
private function apiChangeCommentVote(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
if (!empty($val = $this->validateAnswerVote($request))) {
if (!empty($val = $this->validateCommentVote($request))) {
$response->set('qa_answer_vote', new FormValidation($val));
$response->header->status = RequestStatusCode::R_400;
return;
}
$vote = CommentVoteMapper::findVote((int) $reqeust->getData('id'), $request->header->account);
$vote = CommentVoteMapper::findVote((int) $request->getData('id'), $request->header->account);
if ($vote instanceof NullCommentVote) {
$new = new CommentVote();
$new->score = (int) $request->getData('type');
$new->createdBy = $request->header->account;
$new->comment = (int) $request->getData('id');
$new->createdBy = new NullAccount($request->header->account);
$this->createModel($request->header->account, $new, CommentVoteMapper::class, 'comment_vote', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Vote', 'Sucessfully voted.', $new);

View File

@ -63,4 +63,26 @@ final class CommentVoteMapper extends DataMapperAbstract
* @since 1.0.0
*/
protected static string $primaryField = 'comments_comment_vote_id';
/**
* Find vote for comment from user
*
* @param int $comment Comment id
* @param int $account Account id
*
* @return CommentVote
*
* @since 1.0.0
*/
public static function findVote(int $comment, int $account) : CommentVote
{
$depth = 3;
$query = self::getQuery();
$query->where(self::$table . '_d' . $depth . '.comments_comment_vote_created_by', '=', $account)
->andWhere(self::$table . '_d' . $depth . '.comments_comment_vote_comment', '=', $comment);
$results = self::getAllByQuery($query);
return \reset($results);
}
}

View File

@ -1,6 +1,7 @@
<?php declare(strict_types=1);
use Modules\Comments\Models\CommentListStatus;
use phpOMS\Uri\UriFactory;
/** @var \Modules\Comments\Models\Comment[] $comments */
$comments = $this->commentList->getComments();
@ -10,32 +11,32 @@ $comments = $this->commentList->getComments();
<div class="col-xs-12">
<section class="portlet">
<div class="portlet-body">
<form method="POST" action="<?= \phpOMS\Uri\UriFactory::build('{/api}comment/list?id=' . $this->commentList->getId() . '{?}&csrf={$CSRF}'); ?>">
<form id="iComentListSettings" method="POST" action="<?= UriFactory::build('{/api}comment/list?id=' . $this->commentList->getId() . '{?}&csrf={$CSRF}'); ?>">
<div class="form-group">
<div class="input-control">
<select name="commentlist_status">
<option value="<?= CommentListStatus::ACTIVE; ?>"><?= $this->getHtml('lstatus-' . CommentListStatus::ACTIVE); ?>
<option value="<?= CommentListStatus::INACTIVE; ?>"><?= $this->getHtml('lstatus-' . CommentListStatus::INACTIVE); ?>
<option value="<?= CommentListStatus::LOCKED; ?>"><?= $this->getHtml('lstatus-' . CommentListStatus::LOCKED); ?>
<option value="<?= CommentListStatus::ACTIVE; ?>"<?= $this->commentList->status === CommentListStatus::ACTIVE ? ' selected' : ''; ?>><?= $this->getHtml('lstatus-' . CommentListStatus::ACTIVE); ?>
<option value="<?= CommentListStatus::INACTIVE; ?>"<?= $this->commentList->status === CommentListStatus::INACTIVE ? ' selected' : ''; ?>><?= $this->getHtml('lstatus-' . CommentListStatus::INACTIVE); ?>
<option value="<?= CommentListStatus::LOCKED; ?>"<?= $this->commentList->status === CommentListStatus::LOCKED ? ' selected' : ''; ?>><?= $this->getHtml('lstatus-' . CommentListStatus::LOCKED); ?>
</select>
</div>
<div class="input-control">
<label class="checkbox" for="iComment">
<input id="iComment" type="checkbox" name="allow_voting" value="1">
<label class="checkbox" for="iCommentVoting">
<input id="iCommentVoting" type="checkbox" name="allow_voting" value="1"<?= $this->commentList->allowVoting ? ' checked' : ''; ?>>
<span class="checkmark"></span>
<?= $this->getHtml('Voting'); ?>
</label>
</div>
<div class="input-control">
<label class="checkbox" for="iComment">
<input id="iComment" type="checkbox" name="allow_edit" value="1">
<label class="checkbox" for="iCommentEdit">
<input id="iCommentEdit" type="checkbox" name="allow_edit" value="1"<?= $this->commentList->allowEdit ? ' checked' : ''; ?>>
<span class="checkmark"></span>
<?= $this->getHtml('Edit'); ?>
</label>
</div>
<div class="input-control">
<label class="checkbox" for="iComment">
<input id="iComment" type="checkbox" name="allow_upload" value="1">
<label class="checkbox" for="iCommentFiles">
<input id="iCommentFiles" type="checkbox" name="allow_upload" value="1"<?= $this->commentList->allowFiles ? ' checked' : ''; ?>>
<span class="checkmark"></span>
<?= $this->getHtml('Upload'); ?>
</label>
@ -55,17 +56,17 @@ foreach ($comments as $comment) : ?>
<div class="row">
<div class="col-xs-12">
<section class="portlet">
<div class="portlet-body">
<article>
<?= $comment->content; ?>
</article>
</div>
<div class="portlet-foot">
<?= $this->printHtml(
<div class="portlet-body">
<article>
<?= $comment->content; ?>
</article>
</div>
<div class="portlet-foot">
<?= $this->printHtml(
\sprintf('%3$s %2$s %1$s', $comment->createdBy->name1, $comment->createdBy->name2, $comment->createdBy->name3)
); ?>
<span class="floatRight"><?= $comment->createdAt->format('Y-m-d H:i:s'); ?></span>
</div>
<span class="floatRight"><?= $comment->createdAt->format('Y-m-d H:i:s'); ?></span>
</div>
</section>
</div>
</div>

View File

@ -15,4 +15,10 @@ declare(strict_types=1);
return ['Comments' => [
'Created' => 'Created',
'Creator' => 'Creator',
'Voting' => 'Voting',
'Edit' => 'Edit',
'Upload' => 'Upload',
'lstatus-1' => 'Active',
'lstatus-2' => 'Inactive',
'lstatus-3' => 'Locked',
]];

View File

@ -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",