]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add type hints for mappers 37511/head
authorjld3103 <jld3103yt@gmail.com>
Fri, 31 Mar 2023 07:28:22 +0000 (09:28 +0200)
committerjld3103 <jld3103yt@gmail.com>
Fri, 7 Apr 2023 07:49:42 +0000 (09:49 +0200)
Signed-off-by: jld3103 <jld3103yt@gmail.com>
17 files changed:
apps/dav/lib/CalDAV/Proxy/ProxyMapper.php
apps/files/lib/Db/OpenLocalEditorMapper.php
apps/files/lib/Db/TransferOwnershipMapper.php
core/Db/LoginFlowV2Mapper.php
core/Db/ProfileConfigMapper.php
lib/composer/composer/autoload_classmap.php
lib/composer/composer/autoload_static.php
lib/private/KnownUser/KnownUserMapper.php
lib/private/Metadata/FileMetadataMapper.php
lib/private/Settings/AuthorizedGroupMapper.php
lib/private/Tagging/TagMapper.php
lib/private/Updater/Changes.php [new file with mode: 0644]
lib/private/Updater/ChangesCheck.php
lib/private/Updater/ChangesMapper.php
lib/private/Updater/ChangesResult.php [deleted file]
lib/public/AppFramework/Db/QBMapper.php
tests/lib/Updater/ChangesCheckTest.php

index 19c72ffa0e9679ca6c7925ea151dae32337c5c83..e48e283484c4cc46cc99b59ea1bbe43ad5ebaa83 100644 (file)
@@ -34,6 +34,8 @@ use OCP\IDBConnection;
  * Class ProxyMapper
  *
  * @package OCA\DAV\CalDAV\Proxy
+ *
+ * @template-extends QBMapper<Proxy>
  */
 class ProxyMapper extends QBMapper {
        public const PERMISSION_READ = 1;
index 71573264c74316cbceea9f93374e9ef127f1e671..00988adc9ccaf1fc56157dd293c6c22ffd771d18 100644 (file)
@@ -32,6 +32,9 @@ use OCP\AppFramework\Db\QBMapper;
 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);
index f55f9e733f9385bc39d928b2092a32895a0beda6..e195a5182a0efcb6080a73456185414becb2143b 100644 (file)
@@ -29,6 +29,9 @@ namespace OCA\Files\Db;
 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);
index 0e44418e0107ede1e0a0a2455540445b08231e84..feb1bd7b42dc269fce748ad80791a9ccae9cc84b 100644 (file)
@@ -30,6 +30,9 @@ use OCP\AppFramework\Db\QBMapper;
 use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\IDBConnection;
 
+/**
+ * @template-extends QBMapper<LoginFlowV2>
+ */
 class LoginFlowV2Mapper extends QBMapper {
        private const lifetime = 1200;
 
index a8b1e35f747a532abe31cae94379e941a8cbad14..8e3375239779fdccaceb64eb3900b3a5405c649e 100644 (file)
@@ -29,6 +29,9 @@ namespace OC\Core\Db;
 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);
index 2b320c82424b8f4817b2c87f1bb25236e64511dd..a269b440df62b6574209c3f41974076be87fec72 100644 (file)
@@ -1614,9 +1614,9 @@ return array(
     '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',
index a920e67a77285be06d511e5cd50421a92b538d90..bfc0f2c88ac0dee230906338ab5adf4ace6751db 100644 (file)
@@ -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',
index ce7dc9ead631e013d7f0a7849c061b11d6a2ff66..fd8f22cd0aa59131ec9d546083e9526e4c3b4ae9 100644 (file)
@@ -30,6 +30,8 @@ use OCP\IDBConnection;
 
 /**
  * @method KnownUser mapRowToEntity(array $row)
+ *
+ * @template-extends QBMapper<KnownUser>
  */
 class KnownUserMapper extends QBMapper {
        /**
index f3120e5e5153e83bbd39682c1dc01a40eedfd51e..594ac5eafba4824f97b0233ceca1f2659d8c2a4b 100644 (file)
@@ -30,6 +30,9 @@ use OCP\DB\Exception;
 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);
@@ -109,11 +112,11 @@ class FileMetadataMapper extends QBMapper {
         * 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");
                }
index 4313ce60580b38efaf8ee8b7413e59a2e14ecea9..c7c39cc67587edcd674089fb8d99c8199d26927e 100644 (file)
@@ -32,6 +32,9 @@ use OCP\IGroup;
 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);
index 808fce2eeaef06ab868670dd4534d2b73ef59ba0..1ee9c33acf7f7880cfaa6db7877db7db5e248ba2 100644 (file)
@@ -32,6 +32,8 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
 
 /**
  * Mapper for Tag entity
+ *
+ * @template-extends QBMapper<Tag>
  */
 class TagMapper extends QBMapper {
        /**
diff --git a/lib/private/Updater/Changes.php b/lib/private/Updater/Changes.php
new file mode 100644 (file)
index 0000000..81a57c0
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OC\Updater;
+
+use OCP\AppFramework\Db\Entity;
+
+/**
+ * Class Changes
+ *
+ * @package OC\Updater
+ * @method string getVersion()=1
+ * @method void setVersion(string $version)
+ * @method string getEtag()
+ * @method void setEtag(string $etag)
+ * @method int getLastCheck()
+ * @method void setLastCheck(int $lastCheck)
+ * @method string getData()
+ * @method void setData(string $data)
+ */
+class Changes extends Entity {
+       /** @var string */
+       protected $version = '';
+
+       /** @var string */
+       protected $etag = '';
+
+       /** @var int */
+       protected $lastCheck = 0;
+
+       /** @var string */
+       protected $data = '';
+
+       public function __construct() {
+               $this->addType('version', 'string');
+               $this->addType('etag', 'string');
+               $this->addType('lastCheck', 'int');
+               $this->addType('data', 'string');
+       }
+}
index e2b66853788eb4cda7d36817c6093bfbb3591e16..2c1eb321ee0ae216d6e6371d9de6380355003537 100644 (file)
@@ -73,7 +73,7 @@ class ChangesCheck {
                                return json_decode($changesInfo->getData(), true);
                        }
                } catch (DoesNotExistException $e) {
-                       $changesInfo = new ChangesResult();
+                       $changesInfo = new Changes();
                }
 
                $response = $this->queryChangesServer($uri, $changesInfo);
@@ -109,7 +109,7 @@ class ChangesCheck {
                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 @@ class ChangesCheck {
        /**
         * @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()];
index 03e1ae3c2c19d502de8fca121848c8358f212596..33d50f5844f87eb61c0332ca59f11c32f08abe6b 100644 (file)
@@ -31,6 +31,9 @@ use OCP\AppFramework\Db\QBMapper;
 use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCP\IDBConnection;
 
+/**
+ * @template-extends QBMapper<Changes>
+ */
 class ChangesMapper extends QBMapper {
        public const TABLE_NAME = 'whats_new';
 
@@ -41,7 +44,7 @@ class ChangesMapper extends QBMapper {
        /**
         * @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 @@ class ChangesMapper extends QBMapper {
                if ($data === false) {
                        throw new DoesNotExistException('Changes info is not present');
                }
-               return ChangesResult::fromRow($data);
+               return Changes::fromRow($data);
        }
 }
diff --git a/lib/private/Updater/ChangesResult.php b/lib/private/Updater/ChangesResult.php
deleted file mode 100644 (file)
index db2f730..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-namespace OC\Updater;
-
-use OCP\AppFramework\Db\Entity;
-
-/**
- * Class ChangesResult
- *
- * @package OC\Updater
- * @method string getVersion()=1
- * @method void setVersion(string $version)
- * @method string getEtag()
- * @method void setEtag(string $etag)
- * @method int getLastCheck()
- * @method void setLastCheck(int $lastCheck)
- * @method string getData()
- * @method void setData(string $data)
- */
-class ChangesResult extends Entity {
-       /** @var string */
-       protected $version = '';
-
-       /** @var string */
-       protected $etag = '';
-
-       /** @var int */
-       protected $lastCheck = 0;
-
-       /** @var string */
-       protected $data = '';
-
-       public function __construct() {
-               $this->addType('version', 'string');
-               $this->addType('etag', 'string');
-               $this->addType('lastCheck', 'int');
-               $this->addType('data', 'string');
-       }
-}
index 57f4cba2ff51a8dc41fd75136ca34af47675bb63..cbe3d39d4d741377f2b684c7b12922e1886a0d0b 100644 (file)
@@ -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
         */
index 02da6d084019d558b58829f04b27abce3463ae9c..e96406622f474789bed68ca4c152cd05578f594d 100644 (file)
@@ -28,7 +28,7 @@ namespace Test\Updater;
 
 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 @@ class ChangesCheckTest extends TestCase {
 
        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 @@ class ChangesCheckTest extends TestCase {
 
        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 @@ class ChangesCheckTest extends TestCase {
         */
        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 @@ class ChangesCheckTest extends TestCase {
                        $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 @@ class ChangesCheckTest extends TestCase {
        }
 
        public function testGetChangesForVersionEmptyData() {
-               $entry = $this->createMock(ChangesResult::class);
+               $entry = $this->createMock(Changes::class);
                $entry->expects($this->once())
                        ->method('__call')
                        ->with('getData')