diff --git a/lib/private/Authentication/Token/IToken.php b/lib/private/Authentication/Token/IToken.php index 5ca4eaea84372..1c47807934fb6 100644 --- a/lib/private/Authentication/Token/IToken.php +++ b/lib/private/Authentication/Token/IToken.php @@ -37,8 +37,6 @@ interface IToken extends JsonSerializable { /** * Get the token ID - * - * @return int */ public function getId(): int; @@ -74,6 +72,7 @@ public function getLastCheck(): int; * Set the timestamp of the last password check * * @param int $time + * @return void */ public function setLastCheck(int $time); @@ -95,6 +94,7 @@ public function getScopeAsArray(): array; * Set the authentication scope for this token * * @param array $scope + * @return void */ public function setScope($scope); @@ -115,6 +115,7 @@ public function getRemember(): int; * Set the token * * @param string $token + * @return void */ public function setToken(string $token); @@ -122,6 +123,7 @@ public function setToken(string $token); * Set the password * * @param string $password + * @return void */ public function setPassword(string $password); @@ -129,6 +131,7 @@ public function setPassword(string $password); * Set the expiration time of the token * * @param int|null $expires + * @return void */ public function setExpires($expires); } diff --git a/lib/private/Authentication/Token/PublicKeyToken.php b/lib/private/Authentication/Token/PublicKeyToken.php index 45335e17c3161..5b05a7814f71f 100644 --- a/lib/private/Authentication/Token/PublicKeyToken.php +++ b/lib/private/Authentication/Token/PublicKeyToken.php @@ -119,7 +119,11 @@ public function __construct() { } public function getId(): int { - return $this->id; + if ($this->id !== null) { + return $this->id; + } else { + throw new \InvalidArgumentException('Cannot call getId on an token which was not inserted yet'); + } } public function getUID(): string { diff --git a/lib/private/Tagging/Tag.php b/lib/private/Tagging/Tag.php index 17af385418d60..0e8559e0efe82 100644 --- a/lib/private/Tagging/Tag.php +++ b/lib/private/Tagging/Tag.php @@ -36,22 +36,12 @@ * @method void setName(string $name) */ class Tag extends Entity { - protected $owner; - protected $type; - protected $name; - - /** - * Constructor. - * - * @param string $owner The tag's owner - * @param string $type The type of item this tag is used for - * @param string $name The tag's name - */ - public function __construct($owner = null, $type = null, $name = null) { - $this->setOwner($owner); - $this->setType($type); - $this->setName($name); - } + /** @psalm-suppress PropertyNotSetInConstructor */ + protected string $owner; + /** @psalm-suppress PropertyNotSetInConstructor */ + protected string $type; + /** @psalm-suppress PropertyNotSetInConstructor */ + protected string $name; /** * Transform a database columnname to a property diff --git a/lib/private/Tags.php b/lib/private/Tags.php index 8da1e7edc3b8a..37462a42ab9e6 100644 --- a/lib/private/Tags.php +++ b/lib/private/Tags.php @@ -304,7 +304,7 @@ public function add(string $name) { return false; } try { - $tag = new Tag($this->user, $this->type, $name); + $tag = Tag::fromParams(['owner' => $this->user, 'type' => $this->type, 'name' => $name]); $tag = $this->mapper->insert($tag); $this->tags[] = $tag; } catch (\Exception $e) { @@ -314,8 +314,8 @@ public function add(string $name) { ]); return false; } - $this->logger->debug(__METHOD__ . ' Added an tag with ' . $tag->getId(), ['app' => 'core']); - return $tag->getId(); + $this->logger->debug(__METHOD__ . ' Added an tag with ' . ($tag->getId() ?? ''), ['app' => 'core']); + return $tag->getId() ?? false; } /** @@ -382,7 +382,7 @@ public function addMultiple($names, bool $sync = false, ?int $id = null): bool { $newones = []; foreach ($names as $name) { if (!$this->hasTag($name) && $name !== '') { - $newones[] = new Tag($this->user, $this->type, $name); + $newones[] = Tag::fromParams(['owner' => $this->user, 'type' => $this->type, 'name' => $name]); } if (!is_null($id)) { // Insert $objectid, $categoryid pairs if not exist. diff --git a/lib/public/AppFramework/Db/Entity.php b/lib/public/AppFramework/Db/Entity.php index 1ae938f6e32f8..258237fd73d5c 100644 --- a/lib/public/AppFramework/Db/Entity.php +++ b/lib/public/AppFramework/Db/Entity.php @@ -29,16 +29,16 @@ use function substr; /** - * @method int getId() + * @method ?int getId() * @method void setId(int $id) * @since 7.0.0 * @psalm-consistent-constructor */ abstract class Entity { /** - * @var int + * @var ?int */ - public $id; + public $id = null; private array $_updatedFields = []; private array $_fieldTypes = ['id' => 'integer']; @@ -105,7 +105,7 @@ public function resetUpdatedFields() { protected function setter(string $name, array $args): void { // setters should only work for existing attributes if (property_exists($this, $name)) { - if ($this->$name === $args[0]) { + if (isset($this->$name) && $this->$name === $args[0]) { return; } $this->markFieldUpdated($name);