refactor: Fix psalm issues
- Add typing for most of the services, controllers and mappers - Add api doc for mappers - Use vendor-bin for psalm - Use attributes for controllers - Fix upload of attachments Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
This commit is contained in:
@@ -19,29 +19,25 @@ use OCP\Comments\IComment;
|
||||
abstract class ABoardImportService {
|
||||
/** @var string */
|
||||
public static $name = '';
|
||||
/** @var BoardImportService */
|
||||
private $boardImportService;
|
||||
/** @var bool */
|
||||
protected $needValidateData = true;
|
||||
private BoardImportService $boardImportService;
|
||||
protected bool $needValidateData = true;
|
||||
/** @var Stack[] */
|
||||
protected $stacks = [];
|
||||
protected array $stacks = [];
|
||||
/** @var Label[] */
|
||||
protected $labels = [];
|
||||
protected array $labels = [];
|
||||
/** @var Card[] */
|
||||
protected $cards = [];
|
||||
protected array $cards = [];
|
||||
/** @var Acl[] */
|
||||
protected $acls = [];
|
||||
protected array $acls = [];
|
||||
/** @var IComment[][] */
|
||||
protected $comments = [];
|
||||
protected array $comments = [];
|
||||
/** @var Assignment[] */
|
||||
protected $assignments = [];
|
||||
/** @var string[][] */
|
||||
protected $labelCardAssignments = [];
|
||||
protected array $assignments = [];
|
||||
/** @var int[][] */
|
||||
protected array $labelCardAssignments = [];
|
||||
|
||||
/**
|
||||
* Configure import service
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function bootstrap(): void;
|
||||
|
||||
@@ -68,10 +64,13 @@ abstract class ABoardImportService {
|
||||
|
||||
abstract public function getCardAssignments(): array;
|
||||
|
||||
/**
|
||||
* @return array<int, array<int, int>>
|
||||
*/
|
||||
abstract public function getCardLabelAssignment(): array;
|
||||
|
||||
/**
|
||||
* @return IComment[][]|array
|
||||
* @return array<int, array<string, IComment>>
|
||||
*/
|
||||
abstract public function getComments(): array;
|
||||
|
||||
@@ -98,16 +97,16 @@ abstract class ABoardImportService {
|
||||
$this->acls[$code] = $acl;
|
||||
}
|
||||
|
||||
public function updateComment(string $cardId, string $commentId, IComment $comment): void {
|
||||
public function updateComment(int $cardId, string $commentId, IComment $comment): void {
|
||||
$this->comments[$cardId][$commentId] = $comment;
|
||||
}
|
||||
|
||||
public function updateCardAssignment(string $cardId, string $assignmentId, Entity $assignment): void {
|
||||
public function updateCardAssignment(int $cardId, int $assignmentId, Entity $assignment): void {
|
||||
$this->assignments[$cardId][$assignmentId] = $assignment;
|
||||
}
|
||||
|
||||
public function updateCardLabelsAssignment(string $cardId, string $assignmentId, string $assignment): void {
|
||||
$this->labelCardAssignments[$cardId][$assignmentId] = $assignment;
|
||||
public function updateCardLabelsAssignment(int $cardId, int $assignmentId, int $labelId): void {
|
||||
$this->labelCardAssignments[$cardId][$assignmentId] = $labelId;
|
||||
}
|
||||
|
||||
public function setImportService(BoardImportService $service): void {
|
||||
|
||||
@@ -209,14 +209,15 @@ class BoardImportService {
|
||||
|
||||
public function importBoard(): void {
|
||||
$board = $this->getImportSystem()->getBoard();
|
||||
if ($board === null) {
|
||||
throw new \LogicException('Import board not found');
|
||||
}
|
||||
if (!$this->userManager->userExists($board->getOwner())) {
|
||||
throw new \Exception('Target owner ' . $board->getOwner() . ' not found. Please provide a mapping through the import config.');
|
||||
}
|
||||
|
||||
if ($board) {
|
||||
$this->boardMapper->insert($board);
|
||||
$this->board = $board;
|
||||
}
|
||||
$this->boardMapper->insert($board);
|
||||
$this->board = $board;
|
||||
}
|
||||
|
||||
public function getBoard(bool $reset = false): Board {
|
||||
@@ -292,12 +293,7 @@ class BoardImportService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $cardId
|
||||
* @param mixed $labelId
|
||||
* @return self
|
||||
*/
|
||||
public function assignCardToLabel($cardId, $labelId): self {
|
||||
public function assignCardToLabel(int $cardId, int $labelId): self {
|
||||
$this->cardMapper->assignLabel(
|
||||
$cardId,
|
||||
$labelId
|
||||
@@ -307,14 +303,14 @@ class BoardImportService {
|
||||
|
||||
public function assignCardsToLabels(): void {
|
||||
$data = $this->getImportSystem()->getCardLabelAssignment();
|
||||
foreach ($data as $cardId => $assignemnt) {
|
||||
foreach ($assignemnt as $assignmentId => $labelId) {
|
||||
foreach ($data as $cardId => $assignment) {
|
||||
foreach ($assignment as $assignmentId => $labelId) {
|
||||
try {
|
||||
$this->assignCardToLabel(
|
||||
$cardId,
|
||||
(int)$cardId,
|
||||
$labelId
|
||||
);
|
||||
$this->getImportSystem()->updateCardLabelsAssignment($cardId, $assignmentId, $labelId);
|
||||
$this->getImportSystem()->updateCardLabelsAssignment((int)$cardId, (int)$assignmentId, $labelId);
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('Failed to assign label ' . $labelId . ' to ' . $cardId, $e);
|
||||
}
|
||||
@@ -326,20 +322,20 @@ class BoardImportService {
|
||||
$allComments = $this->getImportSystem()->getComments();
|
||||
foreach ($allComments as $cardId => $comments) {
|
||||
foreach ($comments as $commentId => $comment) {
|
||||
$this->insertComment($cardId, $comment);
|
||||
$this->getImportSystem()->updateComment($cardId, $commentId, $comment);
|
||||
$this->insertComment((int)$cardId, $comment);
|
||||
$this->getImportSystem()->updateComment((int)$cardId, $commentId, $comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function insertComment(string $cardId, IComment $comment): void {
|
||||
$comment->setObject('deckCard', $cardId);
|
||||
private function insertComment(int $cardId, IComment $comment): void {
|
||||
$comment->setObject('deckCard', (string)$cardId);
|
||||
$comment->setVerb('comment');
|
||||
// Check if parent is a comment on the same card
|
||||
if ($comment->getParentId() !== '0') {
|
||||
try {
|
||||
$parent = $this->commentsManager->get($comment->getParentId());
|
||||
if ($parent->getObjectType() !== Application::COMMENT_ENTITY_TYPE || $parent->getObjectId() !== $cardId) {
|
||||
if ($parent->getObjectType() !== Application::COMMENT_ENTITY_TYPE || (int)$parent->getObjectId() !== $cardId) {
|
||||
throw new CommentNotFoundException();
|
||||
}
|
||||
} catch (CommentNotFoundException $e) {
|
||||
@@ -362,7 +358,7 @@ class BoardImportService {
|
||||
foreach ($assignments as $assignment) {
|
||||
try {
|
||||
$assignment = $this->assignmentMapper->insert($assignment);
|
||||
$this->getImportSystem()->updateCardAssignment($cardId, (string)$assignment->getId(), $assignment);
|
||||
$this->getImportSystem()->updateCardAssignment((int)$cardId, $assignment->getId(), $assignment);
|
||||
$this->addOutput('Assignment ' . $assignment->getParticipant() . ' added');
|
||||
} catch (NotFoundException $e) {
|
||||
$this->addError('No origin or mapping found for card "' . $cardId . '" and ' . $assignment->getTypeString() . ' assignment "' . $assignment->getParticipant(), $e);
|
||||
|
||||
@@ -16,6 +16,7 @@ use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Db\Label;
|
||||
use OCA\Deck\Db\Stack;
|
||||
use OCA\Deck\Service\Importer\ABoardImportService;
|
||||
use OCP\Comments\IComment;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
|
||||
@@ -118,6 +119,7 @@ class DeckJsonService extends ABoardImportService {
|
||||
$comments[$this->cards[$sourceCard->id]->getId()][$commentOriginal->id] = $comment;
|
||||
}
|
||||
}
|
||||
/** @var array<int, array<string, IComment>> */
|
||||
return $comments;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use Psr\Log\LoggerInterface;
|
||||
class TrelloApiService extends TrelloJsonService {
|
||||
/** @var string */
|
||||
public static $name = 'Trello API';
|
||||
protected $needValidateData = false;
|
||||
protected bool $needValidateData = false;
|
||||
/** @var IClient */
|
||||
private $httpClient;
|
||||
/** @var LoggerInterface */
|
||||
@@ -176,7 +176,7 @@ class TrelloApiService extends TrelloJsonService {
|
||||
if (empty($queryString['limit'])) {
|
||||
return [];
|
||||
}
|
||||
if (count($data) < $queryString['limit']) {
|
||||
if ((count($data) < $queryString['limit']) || (count($data) === 0)) {
|
||||
return [];
|
||||
}
|
||||
$queryString['before'] = end($data)->id;
|
||||
|
||||
@@ -159,6 +159,7 @@ class TrelloJsonService extends ABoardImportService {
|
||||
$comments[$cardId][$commentId] = $comment;
|
||||
}
|
||||
}
|
||||
/** @var array<int, array<string, IComment>> */
|
||||
return $comments;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user