From b153340b6292c0790666e0542677bcf47f2e9b59 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Fri, 31 Mar 2023 09:28:22 +0200 Subject: [PATCH] Add type hints for mappers Signed-off-by: jld3103 --- apps/dav/lib/CalDAV/Proxy/ProxyMapper.php | 2 ++ apps/files/lib/Db/OpenLocalEditorMapper.php | 3 +++ apps/files/lib/Db/TransferOwnershipMapper.php | 3 +++ core/Db/LoginFlowV2Mapper.php | 3 +++ core/Db/ProfileConfigMapper.php | 3 +++ lib/composer/composer/autoload_classmap.php | 2 +- lib/composer/composer/autoload_static.php | 2 +- lib/private/KnownUser/KnownUserMapper.php | 2 ++ lib/private/Metadata/FileMetadataMapper.php | 7 +++++-- lib/private/Settings/AuthorizedGroupMapper.php | 3 +++ lib/private/Tagging/TagMapper.php | 2 ++ .../Updater/{ChangesResult.php => Changes.php} | 4 ++-- lib/private/Updater/ChangesCheck.php | 6 +++--- lib/private/Updater/ChangesMapper.php | 7 +++++-- lib/public/AppFramework/Db/QBMapper.php | 3 +-- tests/lib/Updater/ChangesCheckTest.php | 12 ++++++------ 16 files changed, 45 insertions(+), 19 deletions(-) rename lib/private/Updater/{ChangesResult.php => Changes.php} (96%) diff --git a/apps/dav/lib/CalDAV/Proxy/ProxyMapper.php b/apps/dav/lib/CalDAV/Proxy/ProxyMapper.php index 19c72ffa0e967..e48e283484c4c 100644 --- a/apps/dav/lib/CalDAV/Proxy/ProxyMapper.php +++ b/apps/dav/lib/CalDAV/Proxy/ProxyMapper.php @@ -34,6 +34,8 @@ * Class ProxyMapper * * @package OCA\DAV\CalDAV\Proxy + * + * @template-extends QBMapper */ class ProxyMapper extends QBMapper { public const PERMISSION_READ = 1; diff --git a/apps/files/lib/Db/OpenLocalEditorMapper.php b/apps/files/lib/Db/OpenLocalEditorMapper.php index 71573264c7431..00988adc9ccaf 100644 --- a/apps/files/lib/Db/OpenLocalEditorMapper.php +++ b/apps/files/lib/Db/OpenLocalEditorMapper.php @@ -32,6 +32,9 @@ use OCP\DB\Exception; use OCP\IDBConnection; +/** + * @template-extends QBMapper + */ class OpenLocalEditorMapper extends QBMapper { public function __construct(IDBConnection $db) { parent::__construct($db, 'open_local_editor', OpenLocalEditor::class); diff --git a/apps/files/lib/Db/TransferOwnershipMapper.php b/apps/files/lib/Db/TransferOwnershipMapper.php index f55f9e733f938..e195a5182a0ef 100644 --- a/apps/files/lib/Db/TransferOwnershipMapper.php +++ b/apps/files/lib/Db/TransferOwnershipMapper.php @@ -29,6 +29,9 @@ use OCP\AppFramework\Db\QBMapper; use OCP\IDBConnection; +/** + * @template-extends QBMapper + */ class TransferOwnershipMapper extends QBMapper { public function __construct(IDBConnection $db) { parent::__construct($db, 'user_transfer_owner', TransferOwnership::class); diff --git a/core/Db/LoginFlowV2Mapper.php b/core/Db/LoginFlowV2Mapper.php index 0e44418e0107e..feb1bd7b42dc2 100644 --- a/core/Db/LoginFlowV2Mapper.php +++ b/core/Db/LoginFlowV2Mapper.php @@ -30,6 +30,9 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\IDBConnection; +/** + * @template-extends QBMapper + */ class LoginFlowV2Mapper extends QBMapper { private const lifetime = 1200; diff --git a/core/Db/ProfileConfigMapper.php b/core/Db/ProfileConfigMapper.php index a8b1e35f747a5..8e3375239779f 100644 --- a/core/Db/ProfileConfigMapper.php +++ b/core/Db/ProfileConfigMapper.php @@ -29,6 +29,9 @@ use OCP\AppFramework\Db\QBMapper; use OCP\IDBConnection; +/** + * @template-extends QBMapper + */ class ProfileConfigMapper extends QBMapper { public function __construct(IDBConnection $db) { parent::__construct($db, 'profile_config', ProfileConfig::class); diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 2b320c82424b8..a269b440df62b 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1614,9 +1614,9 @@ 'OC\\Translation\\TranslationManager' => $baseDir . '/lib/private/Translation/TranslationManager.php', 'OC\\URLGenerator' => $baseDir . '/lib/private/URLGenerator.php', 'OC\\Updater' => $baseDir . '/lib/private/Updater.php', + 'OC\\Updater\\Changes' => $baseDir . '/lib/private/Updater/Changes.php', 'OC\\Updater\\ChangesCheck' => $baseDir . '/lib/private/Updater/ChangesCheck.php', 'OC\\Updater\\ChangesMapper' => $baseDir . '/lib/private/Updater/ChangesMapper.php', - 'OC\\Updater\\ChangesResult' => $baseDir . '/lib/private/Updater/ChangesResult.php', 'OC\\Updater\\VersionCheck' => $baseDir . '/lib/private/Updater/VersionCheck.php', 'OC\\UserStatus\\ISettableProvider' => $baseDir . '/lib/private/UserStatus/ISettableProvider.php', 'OC\\UserStatus\\Manager' => $baseDir . '/lib/private/UserStatus/Manager.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index a920e67a77285..bfc0f2c88ac0d 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1647,9 +1647,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Translation\\TranslationManager' => __DIR__ . '/../../..' . '/lib/private/Translation/TranslationManager.php', 'OC\\URLGenerator' => __DIR__ . '/../../..' . '/lib/private/URLGenerator.php', 'OC\\Updater' => __DIR__ . '/../../..' . '/lib/private/Updater.php', + 'OC\\Updater\\Changes' => __DIR__ . '/../../..' . '/lib/private/Updater/Changes.php', 'OC\\Updater\\ChangesCheck' => __DIR__ . '/../../..' . '/lib/private/Updater/ChangesCheck.php', 'OC\\Updater\\ChangesMapper' => __DIR__ . '/../../..' . '/lib/private/Updater/ChangesMapper.php', - 'OC\\Updater\\ChangesResult' => __DIR__ . '/../../..' . '/lib/private/Updater/ChangesResult.php', 'OC\\Updater\\VersionCheck' => __DIR__ . '/../../..' . '/lib/private/Updater/VersionCheck.php', 'OC\\UserStatus\\ISettableProvider' => __DIR__ . '/../../..' . '/lib/private/UserStatus/ISettableProvider.php', 'OC\\UserStatus\\Manager' => __DIR__ . '/../../..' . '/lib/private/UserStatus/Manager.php', diff --git a/lib/private/KnownUser/KnownUserMapper.php b/lib/private/KnownUser/KnownUserMapper.php index ce7dc9ead631e..fd8f22cd0aa59 100644 --- a/lib/private/KnownUser/KnownUserMapper.php +++ b/lib/private/KnownUser/KnownUserMapper.php @@ -30,6 +30,8 @@ /** * @method KnownUser mapRowToEntity(array $row) + * + * @template-extends QBMapper */ class KnownUserMapper extends QBMapper { /** diff --git a/lib/private/Metadata/FileMetadataMapper.php b/lib/private/Metadata/FileMetadataMapper.php index f3120e5e5153e..594ac5eafba48 100644 --- a/lib/private/Metadata/FileMetadataMapper.php +++ b/lib/private/Metadata/FileMetadataMapper.php @@ -30,6 +30,9 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; +/** + * @template-extends QBMapper + */ class FileMetadataMapper extends QBMapper { public function __construct(IDBConnection $db) { parent::__construct($db, 'file_metadata', FileMetadata::class); @@ -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"); } diff --git a/lib/private/Settings/AuthorizedGroupMapper.php b/lib/private/Settings/AuthorizedGroupMapper.php index 4313ce60580b3..c7c39cc67587e 100644 --- a/lib/private/Settings/AuthorizedGroupMapper.php +++ b/lib/private/Settings/AuthorizedGroupMapper.php @@ -32,6 +32,9 @@ use OCP\IGroupManager; use OCP\IUser; +/** + * @template-extends QBMapper + */ class AuthorizedGroupMapper extends QBMapper { public function __construct(IDBConnection $db) { parent::__construct($db, 'authorized_groups', AuthorizedGroup::class); diff --git a/lib/private/Tagging/TagMapper.php b/lib/private/Tagging/TagMapper.php index 808fce2eeaef0..1ee9c33acf7f7 100644 --- a/lib/private/Tagging/TagMapper.php +++ b/lib/private/Tagging/TagMapper.php @@ -32,6 +32,8 @@ /** * Mapper for Tag entity + * + * @template-extends QBMapper */ class TagMapper extends QBMapper { /** diff --git a/lib/private/Updater/ChangesResult.php b/lib/private/Updater/Changes.php similarity index 96% rename from lib/private/Updater/ChangesResult.php rename to lib/private/Updater/Changes.php index db2f730aa6a52..81a57c0c871e5 100644 --- a/lib/private/Updater/ChangesResult.php +++ b/lib/private/Updater/Changes.php @@ -28,7 +28,7 @@ use OCP\AppFramework\Db\Entity; /** - * Class ChangesResult + * Class Changes * * @package OC\Updater * @method string getVersion()=1 @@ -40,7 +40,7 @@ * @method string getData() * @method void setData(string $data) */ -class ChangesResult extends Entity { +class Changes extends Entity { /** @var string */ protected $version = ''; diff --git a/lib/private/Updater/ChangesCheck.php b/lib/private/Updater/ChangesCheck.php index e2b66853788eb..2c1eb321ee0ae 100644 --- a/lib/private/Updater/ChangesCheck.php +++ b/lib/private/Updater/ChangesCheck.php @@ -73,7 +73,7 @@ public function check(string $uri, string $version): array { return json_decode($changesInfo->getData(), true); } } catch (DoesNotExistException $e) { - $changesInfo = new ChangesResult(); + $changesInfo = new Changes(); } $response = $this->queryChangesServer($uri, $changesInfo); @@ -109,7 +109,7 @@ protected function evaluateResponse(IResponse $response): int { return self::RESPONSE_NO_CONTENT; } - protected function cacheResult(ChangesResult $entry, string $version) { + protected function cacheResult(Changes $entry, string $version) { if ($entry->getVersion() === $version) { $this->mapper->update($entry); } else { @@ -121,7 +121,7 @@ protected function cacheResult(ChangesResult $entry, string $version) { /** * @throws \Exception */ - protected function queryChangesServer(string $uri, ChangesResult $entry): IResponse { + protected function queryChangesServer(string $uri, Changes $entry): IResponse { $headers = []; if ($entry->getEtag() !== '') { $headers['If-None-Match'] = [$entry->getEtag()]; diff --git a/lib/private/Updater/ChangesMapper.php b/lib/private/Updater/ChangesMapper.php index 03e1ae3c2c19d..33d50f5844f87 100644 --- a/lib/private/Updater/ChangesMapper.php +++ b/lib/private/Updater/ChangesMapper.php @@ -31,6 +31,9 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; +/** + * @template-extends QBMapper + */ class ChangesMapper extends QBMapper { public const TABLE_NAME = 'whats_new'; @@ -41,7 +44,7 @@ public function __construct(IDBConnection $db) { /** * @throws DoesNotExistException */ - public function getChanges(string $version): ChangesResult { + public function getChanges(string $version): Changes { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $result = $qb->select('*') @@ -54,6 +57,6 @@ public function getChanges(string $version): ChangesResult { if ($data === false) { throw new DoesNotExistException('Changes info is not present'); } - return ChangesResult::fromRow($data); + return Changes::fromRow($data); } } diff --git a/lib/public/AppFramework/Db/QBMapper.php b/lib/public/AppFramework/Db/QBMapper.php index 57f4cba2ff51a..cbe3d39d4d741 100644 --- a/lib/public/AppFramework/Db/QBMapper.php +++ b/lib/public/AppFramework/Db/QBMapper.php @@ -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|null $entityClass the name of the entity that the sql should be + * @param class-string|null $entityClass the name of the entity that the sql should be * mapped to queries without using sql * @since 14.0.0 */ diff --git a/tests/lib/Updater/ChangesCheckTest.php b/tests/lib/Updater/ChangesCheckTest.php index 02da6d084019d..e96406622f474 100644 --- a/tests/lib/Updater/ChangesCheckTest.php +++ b/tests/lib/Updater/ChangesCheckTest.php @@ -28,7 +28,7 @@ use OC\Updater\ChangesCheck; use OC\Updater\ChangesMapper; -use OC\Updater\ChangesResult; +use OC\Updater\Changes; use OCP\AppFramework\Db\DoesNotExistException; use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; @@ -88,7 +88,7 @@ public function testEvaluateResponse(int $statusCode, int $expected) { public function testCacheResultInsert() { $version = '13.0.4'; - $entry = $this->createMock(ChangesResult::class); + $entry = $this->createMock(Changes::class); $entry->expects($this->exactly(2)) ->method('__call') ->withConsecutive(['getVersion'], ['setVersion', [$version]]) @@ -104,7 +104,7 @@ public function testCacheResultInsert() { public function testCacheResultUpdate() { $version = '13.0.4'; - $entry = $this->createMock(ChangesResult::class); + $entry = $this->createMock(Changes::class); $entry->expects($this->once()) ->method('__call') ->willReturn($version); @@ -306,7 +306,7 @@ public function etagProvider() { */ public function testQueryChangesServer(string $etag) { $uri = 'https://changes.nextcloud.server/?13.0.5'; - $entry = $this->createMock(ChangesResult::class); + $entry = $this->createMock(Changes::class); $entry->expects($this->any()) ->method('__call') ->willReturn($etag); @@ -370,7 +370,7 @@ public function testGetChangesForVersion(string $inputVersion, string $normalize $this->expectException(DoesNotExistException::class); $mocker->willThrowException(new DoesNotExistException('Changes info is not present')); } else { - $entry = $this->createMock(ChangesResult::class); + $entry = $this->createMock(Changes::class); $entry->expects($this->once()) ->method('__call') ->with('getData') @@ -386,7 +386,7 @@ public function testGetChangesForVersion(string $inputVersion, string $normalize } public function testGetChangesForVersionEmptyData() { - $entry = $this->createMock(ChangesResult::class); + $entry = $this->createMock(Changes::class); $entry->expects($this->once()) ->method('__call') ->with('getData')