fix phpstan lvl 9 bugs

This commit is contained in:
Dennis Eichhorn 2022-12-26 20:52:58 +01:00
parent c714688f58
commit c140c89935
3 changed files with 13 additions and 9 deletions

View File

@ -162,7 +162,9 @@ final class ApiController extends Controller
*/ */
public function apiTicketSet(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void public function apiTicketSet(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{ {
$old = clone TicketMapper::get()->where('id', (int) $request->getData('id'))->execute(); /** @var \Modules\Support\Models\Ticket $old */
$old = TicketMapper::get()->where('id', (int) $request->getData('id'))->execute();
$old = clone $old;
$new = $this->updateTicketFromRequest($request); $new = $this->updateTicketFromRequest($request);
$this->updateModel($request->header->account, $old, $new, TicketMapper::class, 'ticket', $request->getOrigin()); $this->updateModel($request->header->account, $old, $new, TicketMapper::class, 'ticket', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Ticket', 'Ticket successfully updated.', $new); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Ticket', 'Ticket successfully updated.', $new);
@ -302,7 +304,8 @@ final class ApiController extends Controller
public function apiTicketElementSet(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void public function apiTicketElementSet(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{ {
/** @var \Modules\Support\Models\TicketElement $old */ /** @var \Modules\Support\Models\TicketElement $old */
$old = clone TicketElementMapper::get()->where('id', (int) $request->getData('id'))->execute(); $old = TicketElementMapper::get()->where('id', (int) $request->getData('id'))->execute();
$old = clone $old;
$new = $this->updateTicketElementFromRequest($request, $response); $new = $this->updateTicketElementFromRequest($request, $response);
$this->updateModel($request->header->account, $old, $new, TicketElementMapper::class, 'ticketelement', $request->getOrigin()); $this->updateModel($request->header->account, $old, $new, TicketElementMapper::class, 'ticketelement', $request->getOrigin());
@ -370,7 +373,7 @@ final class ApiController extends Controller
public function createSupportAppFromRequest(RequestAbstract $request) : SupportApp public function createSupportAppFromRequest(RequestAbstract $request) : SupportApp
{ {
$app = new SupportApp(); $app = new SupportApp();
$app->name = $request->getData('name') ?? ''; $app->name = (string) ($request->getData('name') ?? '');
return $app; return $app;
} }
@ -657,15 +660,15 @@ final class ApiController extends Controller
{ {
$attrValue = new TicketAttributeValue(); $attrValue = new TicketAttributeValue();
$type = $request->getData('type') ?? 0; $type = (int) ($request->getData('type') ?? 0);
if ($type === AttributeValueType::_INT) { if ($type === AttributeValueType::_INT) {
$attrValue->valueInt = (int) $request->getData('value'); $attrValue->valueInt = $request->hasData('value') ? (int) $request->getData('value') : null;
} elseif ($type === AttributeValueType::_STRING) { } elseif ($type === AttributeValueType::_STRING) {
$attrValue->valueStr = (string) $request->getData('value'); $attrValue->valueStr = $request->hasData('value') ? (string) $request->getData('value') : null;
} elseif ($type === AttributeValueType::_FLOAT) { } elseif ($type === AttributeValueType::_FLOAT) {
$attrValue->valueDec = (float) $request->getData('value'); $attrValue->valueDec = $request->hasData('value') ? (float) $request->getData('value') : null;
} elseif ($type === AttributeValueType::_DATETIME) { } elseif ($type === AttributeValueType::_DATETIME) {
$attrValue->valueDat = new \DateTime($request->getData('value') ?? ''); $attrValue->valueDat = $request->hasData('value') ? new \DateTime((string) ($request->getData('value') ?? '')) : null;
} }
$attrValue->type = $type; $attrValue->type = $type;

View File

@ -101,7 +101,7 @@ echo $this->getData('nav')->render(); ?>
<?php endif; ?> <?php endif; ?>
<?php $tags = $task->getTags(); foreach ($tags as $tag) : ?> <?php $tags = $task->getTags(); foreach ($tags as $tag) : ?>
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>"><?= $tag->icon !== null ? '<i class="' . $this->printHtml($tag->icon ?? '') . '"></i>' : ''; ?><?= $this->printHtml($tag->getL11n()); ?></span> <span class="tag" style="background: <?= $this->printHtml($tag->color); ?>"><?= !empty($tag->icon) ? '<i class="' . $this->printHtml($tag->icon) . '"></i>' : ''; ?><?= $this->printHtml($tag->getL11n()); ?></span>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
</div> </div>

View File

@ -67,6 +67,7 @@ class TicketView extends View
*/ */
public function getAccountImage(int $account) : string public function getAccountImage(int $account) : string
{ {
/** @var \Modules\Profile\Models\Profile $profile */
$profile = ProfileMapper::get()->with('image')->where('account', $account)->execute(); $profile = ProfileMapper::get()->with('image')->where('account', $account)->execute();
if (($profile instanceof NullProfile) || $profile->image->getPath() === '') { if (($profile instanceof NullProfile) || $profile->image->getPath() === '') {