Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
12 / 15 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| UserElement | |
80.00% |
12 / 15 |
|
50.00% |
2 / 4 |
5.20 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| isDeletedAccount | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getUserId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setCreatedAt | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Db; |
| 10 | |
| 11 | use OCP\AppFramework\Db\Entity; |
| 12 | use OCP\DB\Types; |
| 13 | |
| 14 | /** |
| 15 | * @method void setId(int $id) |
| 16 | * @method int getId() |
| 17 | * @method void setType(string $type) |
| 18 | * @method string getType() |
| 19 | * @method void setNodeId(int $nodeId) |
| 20 | * @method int getNodeId() |
| 21 | * @method void setUserId(string $userId) |
| 22 | * @method void setStarred(int $starred) |
| 23 | * @method int getStarred() |
| 24 | * @method ?\DateTime getCreatedAt() |
| 25 | * @method void setMetadata(array $metadata) |
| 26 | * @method ?array getMetadata() |
| 27 | */ |
| 28 | class UserElement extends Entity { |
| 29 | public string $type = ''; |
| 30 | protected int $nodeId = 0; |
| 31 | protected string $userId = ''; |
| 32 | public bool $starred = false; |
| 33 | public ?\DateTime $createdAt = null; |
| 34 | protected ?array $metadata = null; |
| 35 | /** @var ?array{url: string, nodeId: non-negative-int} */ |
| 36 | public ?array $file = null; |
| 37 | public function __construct() { |
| 38 | $this->addType('id', Types::INTEGER); |
| 39 | $this->addType('type', Types::STRING); |
| 40 | $this->addType('nodeId', Types::INTEGER); |
| 41 | $this->addType('userId', Types::STRING); |
| 42 | $this->addType('starred', Types::INTEGER); |
| 43 | $this->addType('createdAt', Types::DATETIME); |
| 44 | $this->addType('metadata', Types::JSON); |
| 45 | } |
| 46 | |
| 47 | public function isDeletedAccount(): bool { |
| 48 | $metadata = $this->getMetadata(); |
| 49 | return isset($metadata['deleted_account']); |
| 50 | } |
| 51 | |
| 52 | public function getUserId(): string { |
| 53 | $metadata = $this->getMetadata(); |
| 54 | return $metadata['deleted_account']['account'] ?? $this->userId; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @param \DateTime|string $createdAt |
| 59 | */ |
| 60 | public function setCreatedAt($createdAt): void { |
| 61 | if (!$createdAt instanceof \DateTime) { |
| 62 | $createdAt = new \DateTime($createdAt, new \DateTimeZone('UTC')); |
| 63 | } |
| 64 | $this->createdAt = $createdAt; |
| 65 | $this->markFieldUpdated('createdAt'); |
| 66 | } |
| 67 | } |