Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions apps/contactsinteraction/lib/Db/RecentContactMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
use OCP\IDBConnection;
use OCP\IUser;

/**
* @template-extends QBMapper<RecentContact>
*/
class RecentContactMapper extends QBMapper {
public const TABLE_NAME = 'recent_contact';

Expand Down
3 changes: 3 additions & 0 deletions apps/twofactor_backupcodes/lib/Db/BackupCodeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
use OCP\IDBConnection;
use OCP\IUser;

/**
* @template-extends QBMapper<BackupCode>
*/
class BackupCodeMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'twofactor_backupcodes');
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Authentication/Token/DefaultTokenMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;

/**
* @template-extends QBMapper<DefaultToken>
*/
class DefaultTokenMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'authtoken');
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Authentication/Token/PublicKeyTokenMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;

/**
* @template-extends QBMapper<PublicKeyToken>
*/
class PublicKeyTokenMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'authtoken');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function updateTokenActivity(IToken $token) {
$activityInterval = $this->config->getSystemValueInt('token_auth_activity_update', 60);
$activityInterval = min(max($activityInterval, 0), 300);

/** @var DefaultToken $token */
/** @var PublicKeyToken $token */
$now = $this->time->getTime();
if ($token->getLastActivity() < ($now - $activityInterval)) {
// Update token only once per minute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection;

/**
* @template-extends QBMapper<PublicKeyCredentialEntity>
*/
class PublicKeyCredentialMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'webauthn', PublicKeyCredentialEntity::class);
Expand Down
19 changes: 17 additions & 2 deletions lib/public/AppFramework/Db/QBMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
* may be subject to change in the future
*
* @since 14.0.0
*
* @template T of Entity
*/
abstract class QBMapper {

/** @var string */
protected $tableName;

/** @var string */
/** @var string|class-string<T> */
protected $entityClass;

/** @var IDBConnection */
Expand All @@ -54,7 +56,8 @@ abstract class QBMapper {
/**
* @param IDBConnection $db Instance of the Db abstraction layer
* @param string $tableName the name of the table. set this to allow entity
* @param string $entityClass the name of the entity that the sql should be
* @param string|null $entityClass the name of the entity that the sql should be
* @psalm-param class-string<T>|null $entityClass the name of the entity that the sql should be
* mapped to queries without using sql
* @since 14.0.0
*/
Expand Down Expand Up @@ -84,7 +87,9 @@ public function getTableName(): string {
/**
* Deletes an entity from the table
* @param Entity $entity the entity that should be deleted
* @psalm-param T $entity the entity that should be deleted
* @return Entity the deleted entity
* @psalm-return T the deleted entity
* @since 14.0.0
*/
public function delete(Entity $entity): Entity {
Expand All @@ -104,7 +109,9 @@ public function delete(Entity $entity): Entity {
/**
* Creates a new entry in the db from an entity
* @param Entity $entity the entity that should be created
* @psalm-param T $entity the entity that should be created
* @return Entity the saved entity with the set id
* @psalm-return T the saved entity with the set id
* @since 14.0.0
*/
public function insert(Entity $entity): Entity {
Expand Down Expand Up @@ -141,7 +148,9 @@ public function insert(Entity $entity): Entity {
* by the database
*
* @param Entity $entity the entity that should be created/updated
* @psalm-param T $entity the entity that should be created/updated
* @return Entity the saved entity with the (new) id
* @psalm-return T the saved entity with the (new) id
* @throws \InvalidArgumentException if entity has no id
* @since 15.0.0
*/
Expand All @@ -157,7 +166,9 @@ public function insertOrUpdate(Entity $entity): Entity {
* Updates an entry in the db from an entity
* @throws \InvalidArgumentException if entity has no id
* @param Entity $entity the entity that should be created
* @psalm-param T $entity the entity that should be created
* @return Entity the saved entity with the set id
* @psalm-return T the saved entity with the set id
* @since 14.0.0
*/
public function update(Entity $entity): Entity {
Expand Down Expand Up @@ -207,6 +218,7 @@ public function update(Entity $entity): Entity {
* of the $entity
*
* @param Entity $entity The entity to get the types from
* @psalm-param T $entity
* @param string $property The property of $entity to get the type for
* @return int
* @since 16.0.0
Expand Down Expand Up @@ -288,6 +300,7 @@ private function buildDebugMessage(string $msg, IQueryBuilder $sql): string {
*
* @param array $row the row which should be converted to an entity
* @return Entity the entity
* @psalm-return T the entity
* @since 14.0.0
*/
protected function mapRowToEntity(array $row): Entity {
Expand All @@ -300,6 +313,7 @@ protected function mapRowToEntity(array $row): Entity {
*
* @param IQueryBuilder $query
* @return Entity[] all fetched entities
* @psalm-return T[] all fetched entities
* @since 14.0.0
*/
protected function findEntities(IQueryBuilder $query): array {
Expand All @@ -325,6 +339,7 @@ protected function findEntities(IQueryBuilder $query): array {
* @throws DoesNotExistException if the item does not exist
* @throws MultipleObjectsReturnedException if more than one item exist
* @return Entity the entity
* @psalm-return T the entity
* @since 14.0.0
*/
protected function findEntity(IQueryBuilder $query): Entity {
Expand Down