diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-07-15 16:07:16 +0300 |
---|---|---|
committer | Vinicius Reis <vinicius.reis@nextcloud.com> | 2022-07-18 18:46:23 +0300 |
commit | f8b122502316a02581185add11bc8b9941097ba2 (patch) | |
tree | 7c14e865c769004bd43b661efb9136b13d5717c6 /lib | |
parent | c00ad0aa5a82563242d73326a0ed42946ed9a08d (diff) |
Fix some psalm issues with Entities
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/PublicSessionController.php | 1 | ||||
-rw-r--r-- | lib/Controller/SettingsController.php | 1 | ||||
-rw-r--r-- | lib/Controller/WorkspaceController.php | 1 | ||||
-rw-r--r-- | lib/Db/Document.php | 27 | ||||
-rw-r--r-- | lib/Db/Session.php | 30 | ||||
-rw-r--r-- | lib/Db/Step.php | 22 | ||||
-rw-r--r-- | lib/Db/StepMapper.php | 6 | ||||
-rw-r--r-- | lib/Service/WorkspaceService.php | 19 |
8 files changed, 66 insertions, 41 deletions
diff --git a/lib/Controller/PublicSessionController.php b/lib/Controller/PublicSessionController.php index 051bfdf8e..7ab05f68d 100644 --- a/lib/Controller/PublicSessionController.php +++ b/lib/Controller/PublicSessionController.php @@ -36,7 +36,6 @@ use OCP\IRequest; use OCP\Share\IShare; class PublicSessionController extends PublicShareController { - private ShareManager $shareManager; private ?IShare $share; private ApiService $apiService; diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index a22cd09d5..c55b37649 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -31,7 +31,6 @@ use OCP\IConfig; use OCP\IRequest; class SettingsController extends Controller { - private IConfig $config; private ?string $userId; diff --git a/lib/Controller/WorkspaceController.php b/lib/Controller/WorkspaceController.php index 9bb6d476d..31ef6ace0 100644 --- a/lib/Controller/WorkspaceController.php +++ b/lib/Controller/WorkspaceController.php @@ -69,7 +69,6 @@ use OCP\Share\IManager; use Psr\Log\LoggerInterface; class WorkspaceController extends OCSController { - private IRootFolder $rootFolder; private IManager $shareManager; private WorkspaceService $workspaceService; diff --git a/lib/Db/Document.php b/lib/Db/Document.php index 65c8e1986..92d911f63 100644 --- a/lib/Db/Document.php +++ b/lib/Db/Document.php @@ -25,14 +25,29 @@ namespace OCA\Text\Db; use OCP\AppFramework\Db\Entity; +/** + * @method getId(): int + * @method getCurrentVersion(): int + * @method setCurrentVersion(int $version): void + * @method getLastSavedVersion(): int + * @method setLastSavedVersion(int $version): void + * @method getInitialVersion(): int + * @method setInitialVersion(int $version): void + * @method getLastSavedVersionTime(): int + * @method setLastSavedVersionTime(int $time): void + * @method getLastSavedVersionEtag(): string + * @method setLastSavedVersionEtag(string $etag): void + * @method getBaseVersionEtag(): string + * @method setBaseVersionEtag(string $etag): void + */ class Document extends Entity implements \JsonSerializable { public $id; - protected $currentVersion = 0; - protected $lastSavedVersion = 0; - protected $initialVersion = 0; - protected $lastSavedVersionTime = 0; - protected $lastSavedVersionEtag = ''; - protected $baseVersionEtag = ''; + protected int $currentVersion = 0; + protected int $lastSavedVersion = 0; + protected int $initialVersion = 0; + protected int $lastSavedVersionTime = 0; + protected string $lastSavedVersionEtag = ''; + protected string $baseVersionEtag = ''; public function __construct() { $this->addType('id', 'integer'); diff --git a/lib/Db/Session.php b/lib/Db/Session.php index 34d518aed..91fffa3bd 100644 --- a/lib/Db/Session.php +++ b/lib/Db/Session.php @@ -23,23 +23,31 @@ namespace OCA\Text\Db; +use JsonSerializable; use OCP\AppFramework\Db\Entity; /** - * @method int getLastContact() - * @method setLastContact(int $getTime) - * @method getDocumentId() - * @method getUserId() + * @method string getUserId() + * @method void setUserId(?string $userId) * @method string getToken() + * @method void setToken(string $token) + * @method string getColor() + * @method void setColor(string $color) + * @method string|null getGuestName() + * @method void setGuestName(string $guestName) + * @method int getLastContact() + * @method void setLastContact(int $getTime) + * @method int getDocumentId() + * @method void setDocumentId(int $documentId) */ -class Session extends Entity implements \JsonSerializable { +class Session extends Entity implements JsonSerializable { public $id; - protected $userId; - protected $token; - protected $color; - protected $guestName; - protected $lastContact; - protected $documentId; + protected ?string $userId = null; + protected string $token = ''; + protected string $color = ''; + protected ?string $guestName = null; + protected int $lastContact = 0; + protected int $documentId = 0; public function __construct() { $this->addType('id', 'integer'); diff --git a/lib/Db/Step.php b/lib/Db/Step.php index fec0537bd..92ae39d2d 100644 --- a/lib/Db/Step.php +++ b/lib/Db/Step.php @@ -23,14 +23,24 @@ namespace OCA\Text\Db; +use JsonSerializable; use OCP\AppFramework\Db\Entity; -class Step extends Entity implements \JsonSerializable { - public $id; - protected $data; - protected $version; - protected $sessionId; - protected $documentId; +/** + * @method getData(): string + * @method setData(string $data): void + * @method getVersion(): int + * @method setVersion(int $version): void + * @method getSessionId(): int + * @method setSessionId(int $sessionId): void + * @method getDocumentId(): int + * @method setDocumentId(int $documentId): void + */ +class Step extends Entity implements JsonSerializable { + protected string $data = ''; + protected int $version = 0; + protected int $sessionId = 0; + protected int $documentId = 0; public function __construct() { $this->addType('id', 'integer'); diff --git a/lib/Db/StepMapper.php b/lib/Db/StepMapper.php index f0148efff..a977c1629 100644 --- a/lib/Db/StepMapper.php +++ b/lib/Db/StepMapper.php @@ -53,7 +53,6 @@ class StepMapper extends QBMapper { } public function deleteAll($documentId): void { - /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->delete($this->getTableName()) ->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId))) @@ -61,7 +60,6 @@ class StepMapper extends QBMapper { } public function deleteBeforeVersion($documentId, $version): void { - /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->delete($this->getTableName()) ->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId))) @@ -70,11 +68,11 @@ class StepMapper extends QBMapper { } public function deleteAfterVersion($documentId, $version): int { - /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); - return $qb->delete($this->getTableName()) + $result = $qb->delete($this->getTableName()) ->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId))) ->andWhere($qb->expr()->gt('version', $qb->createNamedParameter($version))) ->execute(); + return $result->rowCount(); } } diff --git a/lib/Service/WorkspaceService.php b/lib/Service/WorkspaceService.php index f44b1a206..e8039731f 100644 --- a/lib/Service/WorkspaceService.php +++ b/lib/Service/WorkspaceService.php @@ -3,35 +3,32 @@ namespace OCA\Text\Service; +use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\NotFoundException; -use OCP\Files\StorageNotAvailableException; use OCP\IL10N; class WorkspaceService { + private IL10N $l10n; + private const SUPPORTED_STATIC_FILENAMES = [ 'README.md', 'Readme.md', 'readme.md' ]; - /** @var IL10N */ - private $l10n; - public function __construct(IL10N $l10n) { $this->l10n = $l10n; } - /** - * @param Folder $folder - * @throws StorageNotAvailableException - * @return \OCP\Files\File - */ - public function getFile(Folder $folder) { + public function getFile(Folder $folder): ?File { foreach ($this->getSupportedFilenames() as $filename) { if ($folder->nodeExists($filename)) { try { - return $folder->get($filename); + $file = $folder->get($filename); + if ($file instanceof File) { + return $file; + } } catch (NotFoundException $e) { } } |