fix phpstan lvl 9 bugs

This commit is contained in:
Dennis Eichhorn 2022-12-26 20:52:57 +01:00
parent 672879e724
commit 1957796677
4 changed files with 15 additions and 7 deletions

View File

@ -97,7 +97,8 @@ final class ApiController extends Controller
public function apiCommentListUpdate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
/** @var \Modules\Comments\Models\CommentList $old */
$old = clone CommentListMapper::get()->where('id', (int) $request->getData('id'))->execute();
$old = CommentListMapper::get()->where('id', (int) $request->getData('id'))->execute();
$old = clone $old;
$new = $this->updateCommentListFromRequest($request);
$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);
@ -319,7 +320,8 @@ final class ApiController extends Controller
public function apiCommentUpdate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
/** @var \Modules\Comments\Models\Comment $old */
$old = clone CommentMapper::get()->where('id', (int) $request->getData('id'))->execute();
$old = CommentMapper::get()->where('id', (int) $request->getData('id'))->execute();
$old = clone $old;
$new = $this->updateCommentFromRequest($request);
$this->updateModel($request->header->account, $old, $new, CommentMapper::class, 'comment', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Comment', 'Comment successfully updated', $new);
@ -338,10 +340,10 @@ final class ApiController extends Controller
{
/** @var \Modules\Comments\Models\Comment $comment */
$comment = CommentMapper::get()->where('id', (int) $request->getData('id'))->execute();
$comment->title = $request->getData('title') ?? $comment->title;
$comment->contentRaw = $request->getData('plain') ?? $comment->contentRaw;
$comment->title = (string) ($request->getData('title') ?? $comment->title);
$comment->contentRaw = (string) ($request->getData('plain') ?? $comment->contentRaw);
$comment->content = Markdown::parse((string) ($request->getData('plain') ?? $comment->contentRaw));
$comment->ref = $request->getData('ref') ?? $comment->ref;
$comment->ref = $request->hasData('ref') ? (int) $request->getData('ref') : $comment->ref;
return $comment;
}

View File

@ -76,7 +76,11 @@ final class CommentVoteMapper extends DataMapperFactory
*/
public static function findVote(int $comment, int $account) : CommentVote
{
$results = self::getAll()->where('comment', $comment)->where('createdBy', $account)->execute();
/** @var CommentVote[] $results */
$results = self::getAll()
->where('comment', $comment)
->where('createdBy', $account)
->execute();
return empty($results) ? new NullCommentVote() : \reset($results);
}

View File

@ -36,7 +36,7 @@ class CreateView extends View
* @var int
* @since 1.0.0
*/
protected $list = 0;
protected int $list = 0;
/**
* {@inheritdoc}
@ -52,6 +52,7 @@ class CreateView extends View
*/
public function render(mixed ...$data) : string
{
/** @var array{0:int} $data */
$this->list = $data[0];
return parent::render();

View File

@ -53,6 +53,7 @@ class ListView extends View
*/
public function render(mixed ...$data) : string
{
/** @var array{0:null|CommentList} $data */
$this->commentList = $data[0];
return parent::render();