Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/private/Authentication/Token/IToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ interface IToken extends JsonSerializable {

/**
* Get the token ID
*
* @return int
*/
public function getId(): int;

Expand Down Expand Up @@ -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);

Expand All @@ -95,6 +94,7 @@ public function getScopeAsArray(): array;
* Set the authentication scope for this token
*
* @param array $scope
* @return void
*/
public function setScope($scope);

Expand All @@ -115,20 +115,23 @@ public function getRemember(): int;
* Set the token
*
* @param string $token
* @return void
*/
public function setToken(string $token);

/**
* Set the password
*
* @param string $password
* @return void
*/
public function setPassword(string $password);

/**
* Set the expiration time of the token
*
* @param int|null $expires
* @return void
*/
public function setExpires($expires);
}
6 changes: 5 additions & 1 deletion lib/private/Authentication/Token/PublicKeyToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 6 additions & 16 deletions lib/private/Tagging/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/private/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions lib/public/AppFramework/Db/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
use function substr;

/**
* @method int getId()
* @method ?int getId()

Check failure

Code scanning / Psalm

ImplementedReturnTypeMismatch

The inherited return type 'int' for OC\Authentication\Token\IToken::getId is different to the implemented return type for OC\Authentication\Token\PublicKeyToken::getid 'int|null'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand this error, OC\Authentication\Token\PublicKeyToken::getId has a return type of int, not ?int.

* @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'];
Expand Down Expand Up @@ -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);
Expand Down