Skip to content

Commit

Permalink
Add type hints for mappers
Browse files Browse the repository at this point in the history
Signed-off-by: jld3103 <[email protected]>
  • Loading branch information
provokateurin committed Apr 3, 2023
1 parent 8e529df commit a9a0a38
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions apps/dav/lib/CalDAV/Proxy/ProxyMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
* Class ProxyMapper
*
* @package OCA\DAV\CalDAV\Proxy
*
* @template-extends QBMapper<Proxy>
*/
class ProxyMapper extends QBMapper {
public const PERMISSION_READ = 1;
Expand Down
3 changes: 3 additions & 0 deletions apps/files/lib/Db/OpenLocalEditorMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
use OCP\DB\Exception;
use OCP\IDBConnection;

/**
* @template-extends QBMapper<OpenLocalEditor>
*/
class OpenLocalEditorMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'open_local_editor', OpenLocalEditor::class);
Expand Down
3 changes: 3 additions & 0 deletions apps/files/lib/Db/TransferOwnershipMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection;

/**
* @template-extends QBMapper<TransferOwnership>
*/
class TransferOwnershipMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'user_transfer_owner', TransferOwnership::class);
Expand Down
3 changes: 3 additions & 0 deletions core/Db/LoginFlowV2Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IDBConnection;

/**
* @template-extends QBMapper<LoginFlowV2>
*/
class LoginFlowV2Mapper extends QBMapper {
private const lifetime = 1200;

Expand Down
3 changes: 3 additions & 0 deletions core/Db/ProfileConfigMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection;

/**
* @template-extends QBMapper<ProfileConfig>
*/
class ProfileConfigMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'profile_config', ProfileConfig::class);
Expand Down
2 changes: 2 additions & 0 deletions lib/private/KnownUser/KnownUserMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

/**
* @method KnownUser mapRowToEntity(array $row)
*
* @template-extends QBMapper<KnownUser>
*/
class KnownUserMapper extends QBMapper {
/**
Expand Down
7 changes: 5 additions & 2 deletions lib/private/Metadata/FileMetadataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;

/**
* @template-extends QBMapper<FileMetadata>
*/
class FileMetadataMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'file_metadata', FileMetadata::class);
Expand Down Expand Up @@ -109,11 +112,11 @@ public function clear(int $fileId): void {
* Updates an entry in the db from an entity
*
* @param Entity $entity the entity that should be created
* @return Entity the saved entity with the set id
* @return FileMetadata the saved entity with the set id
* @throws Exception
* @throws \InvalidArgumentException if entity has no id
*/
public function update(Entity $entity): Entity {
public function update(Entity $entity): FileMetadata {
if (!($entity instanceof FileMetadata)) {
throw new \Exception("Entity should be a FileMetadata entity");
}
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Settings/AuthorizedGroupMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
use OCP\IGroupManager;
use OCP\IUser;

/**
* @template-extends QBMapper<AuthorizedGroup>
*/
class AuthorizedGroupMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'authorized_groups', AuthorizedGroup::class);
Expand Down
2 changes: 2 additions & 0 deletions lib/private/Tagging/TagMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

/**
* Mapper for Tag entity
*
* @template-extends QBMapper<Tag>
*/
class TagMapper extends QBMapper {
/**
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Updater/ChangesMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;

/**
* @template-extends QBMapper<ChangesResult>
*/
class ChangesMapper extends QBMapper {
public const TABLE_NAME = 'whats_new';

Expand Down
3 changes: 1 addition & 2 deletions lib/public/AppFramework/Db/QBMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ 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|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
* @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

0 comments on commit a9a0a38

Please sign in to comment.