psalm lvl 2

This commit is contained in:
Michel Roux 2023-06-16 21:20:03 +02:00
parent 2baaae1453
commit 3abce1dd99
23 changed files with 218 additions and 437 deletions

View File

@ -23,10 +23,6 @@ return ['routes' => [
['name' => 'bookmark#set', 'url' => '/bookmark', 'verb' => 'POST'], ['name' => 'bookmark#set', 'url' => '/bookmark', 'verb' => 'POST'],
['name' => 'bookmark#delete', 'url' => '/bookmark/{fileId}/{name}', 'verb' => 'DELETE'], ['name' => 'bookmark#delete', 'url' => '/bookmark/{fileId}/{name}', 'verb' => 'DELETE'],
// Metadata
['name' => 'metadata#get', 'url' => '/metadata/{fileId}/{name}', 'verb' => 'GET', 'defaults' => ['name' => '']],
['name' => 'metadata#set', 'url' => '/metadata/{fileId}/{name}/{value}', 'verb' => 'POST'],
// Preferences // Preferences
['name' => 'preference#get_default', 'url' => '/preference/default/{scope}/{name}', 'verb' => 'GET', 'defaults' => ['name' => '']], ['name' => 'preference#get_default', 'url' => '/preference/default/{scope}/{name}', 'verb' => 'GET', 'defaults' => ['name' => '']],
['name' => 'preference#set_default', 'url' => '/preference/default', 'verb' => 'POST'], ['name' => 'preference#set_default', 'url' => '/preference/default', 'verb' => 'POST'],

View File

@ -12,23 +12,23 @@ namespace OCA\Epubreader\Controller;
use OCA\Epubreader\Service\BookmarkService; use OCA\Epubreader\Service\BookmarkService;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest; use OCP\IRequest;
class BookmarkController extends Controller { class BookmarkController extends Controller {
private $bookmarkService; private BookmarkService $bookmarkService;
/** /**
* @param string $AppName * @param string $AppName
* @param IRequest $request * @param IRequest $request
* @param BookmarkService $bookmarkService * @param BookmarkService $bookmarkService
*/ */
public function __construct($AppName, public function __construct(
string $AppName,
IRequest $request, IRequest $request,
BookmarkService $bookmarkService) { BookmarkService $bookmarkService
) {
parent::__construct($AppName, $request); parent::__construct($AppName, $request);
$this->bookmarkService = $bookmarkService; $this->bookmarkService = $bookmarkService;
} }
@ -40,12 +40,11 @@ class BookmarkController extends Controller {
* @NoCSRFRequired * @NoCSRFRequired
* *
* @param int $fileId * @param int $fileId
* @param string $name * @param ?string $name
* * @param ?string $type
* @return array|\OCP\AppFramework\Http\JSONResponse
*/ */
public function get($fileId, $name, $type = null) { public function get(int $fileId, ?string $name = null, ?string $type = null): JSONResponse {
return $this->bookmarkService->get($fileId, $name, $type); return new JSONResponse($this->bookmarkService->get($fileId, $name, $type));
} }
/** /**
@ -57,14 +56,13 @@ class BookmarkController extends Controller {
* @param int $fileId * @param int $fileId
* @param string $name * @param string $name
* @param string $value * @param string $value
* * @param ?string $type
* @return array|\OCP\AppFramework\Http\JSONResponse * @param ?string $content
*/ */
public function set($fileId, $name, $value, $type = null, $content = null) { public function set(int $fileId, string $name, string $value, ?string $type = null, ?string $content = null): JSONResponse {
return $this->bookmarkService->set($fileId, $name, $value, $type, $content); return new JSONResponse($this->bookmarkService->set($fileId, $name, $value, $type, $content));
} }
/** /**
* @brief return cursor for $fileId * @brief return cursor for $fileId
* *
@ -72,11 +70,9 @@ class BookmarkController extends Controller {
* @NoCSRFRequired * @NoCSRFRequired
* *
* @param int $fileId * @param int $fileId
*
* @return array|\OCP\AppFramework\Http\JSONResponse
*/ */
public function getCursor($fileId) { public function getCursor(int $fileId): JSONResponse {
return $this->bookmarkService->getCursor($fileId); return new JSONResponse($this->bookmarkService->getCursor($fileId));
} }
/** /**
@ -87,11 +83,9 @@ class BookmarkController extends Controller {
* *
* @param int $fileId * @param int $fileId
* @param string $value * @param string $value
*
* @return array|\OCP\AppFramework\Http\JSONResponse
*/ */
public function setCursor($fileId, $value) { public function setCursor(int $fileId, string $value): JSONResponse {
return $this->bookmarkService->setCursor($fileId, $value); return new JSONResponse($this->bookmarkService->setCursor($fileId, $value));
} }
/** /**
@ -102,10 +96,9 @@ class BookmarkController extends Controller {
* *
* @param int $fileId * @param int $fileId
* @param string name * @param string name
*
*/ */
public function delete($fileId, $name) { public function delete(int $fileId, string $name): void {
return $this->bookmarkService->delete($fileId, $name); $this->bookmarkService->delete($fileId, $name);
} }
/** /**
@ -115,9 +108,8 @@ class BookmarkController extends Controller {
* @NoCSRFRequired * @NoCSRFRequired
* *
* @param int $fileId * @param int $fileId
*
*/ */
public function deleteCursor($fileId) { public function deleteCursor(int $fileId): void {
return $this->bookmarkService->deleteCursor($fileId); $this->bookmarkService->deleteCursor($fileId);
} }
} }

View File

@ -1,80 +0,0 @@
<?php
/**
* @author Frank de Lange
* @copyright 2017 Frank de Lange
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Epubreader\Controller;
use OCA\Epubreader\Service\MetadataService;
use OCP\AppFramework\Controller;
use OCP\IRequest;
class MetadataController extends Controller {
private $metadataService;
/**
* @param string $AppName
* @param IRequest $request
* @param MetadataService $metadataService
*/
public function __construct($AppName,
IRequest $request,
MetadataService $metadataService) {
parent::__construct($AppName, $request);
$this->metadataService = $metadataService;
}
/**
* @brief write metadata
*
* @NoAdminRequired
*
* @param int $fileId
* @param string $value
*
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
public function setAll($fileId, $value) {
return $this->metadataService->setAll($fileId, $value);
}
/**
* @brief return metadata item
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @param int $fileId
* @param string $name
*
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
public function get($fileId, $name) {
return $this->metadataService->get($fileId, $name);
}
/**
* @brief write metadata item
*
* @NoAdminRequired
*
* @param int $fileId
* @param string $name
* @param string $value
*
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
public function set($fileId, $name, $value) {
return $this->metadataService->set($fileId, $name, $value);
}
}

View File

@ -11,29 +11,26 @@
namespace OCA\Epubreader\Controller; namespace OCA\Epubreader\Controller;
use OCA\Epubreader\Service\BookmarkService; use OCA\Epubreader\Service\BookmarkService;
use OCA\Epubreader\Service\MetadataService;
use OCA\Epubreader\Service\PreferenceService; use OCA\Epubreader\Service\PreferenceService;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\Files\FileInfo;
use OCP\Files\Folder;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\IRequest; use OCP\IRequest;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\Share\IManager; use OCP\Share\IManager;
class PageController extends Controller { class PageController extends Controller {
/** @var IURLGenerator */ private IURLGenerator $urlGenerator;
private $urlGenerator; private IRootFolder $rootFolder;
/** @var IRootFolder */ private IManager $shareManager;
private $rootFolder; private string $userId;
private $shareManager; private BookmarkService $bookmarkService;
private $userId; private PreferenceService $preferenceService;
private $bookmarkService;
private $metadataService;
private $preferenceService;
/** /**
* @param string $AppName * @param string $AppName
@ -44,25 +41,23 @@ class PageController extends Controller {
* @param string $UserId * @param string $UserId
* @param BookmarkService $bookmarkService * @param BookmarkService $bookmarkService
* @param PreferenceService $preferenceService * @param PreferenceService $preferenceService
* @param MetadataService $metadataService
*/ */
public function __construct( public function __construct(
$AppName, string $AppName,
IRequest $request, IRequest $request,
IURLGenerator $urlGenerator, IURLGenerator $urlGenerator,
IRootFolder $rootFolder, IRootFolder $rootFolder,
IManager $shareManager, IManager $shareManager,
$UserId, string $UserId,
BookmarkService $bookmarkService, BookmarkService $bookmarkService,
PreferenceService $preferenceService, PreferenceService $preferenceService,
MetadataService $metadataService) { ) {
parent::__construct($AppName, $request); parent::__construct($AppName, $request);
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->shareManager = $shareManager; $this->shareManager = $shareManager;
$this->userId = $UserId; $this->userId = $UserId;
$this->bookmarkService = $bookmarkService; $this->bookmarkService = $bookmarkService;
$this->metadataService = $metadataService;
$this->preferenceService = $preferenceService; $this->preferenceService = $preferenceService;
} }
@ -72,7 +67,7 @@ class PageController extends Controller {
* *
* @return TemplateResponse * @return TemplateResponse
*/ */
public function showReader() { public function showReader(): TemplateResponse {
$templates = [ $templates = [
'application/epub+zip' => 'epubreader', 'application/epub+zip' => 'epubreader',
'application/x-cbr' => 'cbreader', 'application/x-cbr' => 'cbreader',
@ -101,7 +96,7 @@ class PageController extends Controller {
'cursor' => $this->toJson($this->bookmarkService->getCursor($fileId)), 'cursor' => $this->toJson($this->bookmarkService->getCursor($fileId)),
'defaults' => $this->toJson($this->preferenceService->getDefault($scope)), 'defaults' => $this->toJson($this->preferenceService->getDefault($scope)),
'preferences' => $this->toJson($this->preferenceService->get($scope, $fileId)), 'preferences' => $this->toJson($this->preferenceService->get($scope, $fileId)),
'metadata' => $this->toJson($this->metadataService->get($fileId)), 'metadata' => $this->toJson([]),
'annotations' => $this->toJson($this->bookmarkService->get($fileId)) 'annotations' => $this->toJson($this->bookmarkService->get($fileId))
]; ];
@ -110,7 +105,6 @@ class PageController extends Controller {
$policy->addAllowedStyleDomain('blob:'); $policy->addAllowedStyleDomain('blob:');
$policy->addAllowedScriptDomain('\'self\''); $policy->addAllowedScriptDomain('\'self\'');
$policy->addAllowedFrameDomain('\'self\''); $policy->addAllowedFrameDomain('\'self\'');
$policy->addAllowedChildSrcDomain('\'self\'');
$policy->addAllowedFontDomain('\'self\''); $policy->addAllowedFontDomain('\'self\'');
$policy->addAllowedFontDomain('data:'); $policy->addAllowedFontDomain('data:');
$policy->addAllowedFontDomain('blob:'); $policy->addAllowedFontDomain('blob:');
@ -132,22 +126,21 @@ class PageController extends Controller {
* @return array * @return array
* @throws NotFoundException * @throws NotFoundException
*/ */
private function getFileInfo($path) { private function getFileInfo(string $path): array {
$count = 0; $count = 0;
$shareToken = preg_replace("/(?:\/index\.php)?\/s\/([A-Za-z0-9]{15,32})\/download.*/", "$1", $path, 1, $count); $shareToken = preg_replace("/(?:\/index\.php)?\/s\/([A-Za-z0-9]{15,32})\/download.*/", "$1", $path, 1, $count);
if ($count === 1) { if ($count === 1) {
/* shared file or directory */ /* shared file or directory */
$node = $this->shareManager->getShareByToken($shareToken)->getNode(); $node = $this->shareManager->getShareByToken($shareToken)->getNode();
$type = $node->getType(); $type = $node->getType();
/* shared directory, need file path to continue, */ /* shared directory, need file path to continue, */
if ($type == \OCP\Files\FileInfo::TYPE_FOLDER) { if ($type == FileInfo::TYPE_FOLDER && $node instanceof Folder) {
$query = []; $query = [];
parse_str(parse_url($path, PHP_URL_QUERY), $query); parse_str(parse_url($path, PHP_URL_QUERY), $query);
if (isset($query['path']) && isset($query['files'])) { if (isset($query['path'])) {
$node = $node->get($query['path'])->get($query['files']); $node = $node->get($query['path']);
} else { } else {
throw new NotFoundException('Shared file path or name not set'); throw new NotFoundException('Shared file path or name not set');
} }
@ -171,7 +164,10 @@ class PageController extends Controller {
]; ];
} }
private function toJson($value) { /**
* @param mixed $value
*/
private function toJson($value): string {
return htmlspecialchars(json_encode($value), ENT_QUOTES, 'UTF-8'); return htmlspecialchars(json_encode($value), ENT_QUOTES, 'UTF-8');
} }
} }

View File

@ -12,28 +12,24 @@ namespace OCA\Epubreader\Controller;
use OCA\Epubreader\Service\PreferenceService; use OCA\Epubreader\Service\PreferenceService;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest; use OCP\IRequest;
use OCP\IURLGenerator;
class PreferenceController extends Controller { class PreferenceController extends Controller {
private $urlGenerator; private PreferenceService $preferenceService;
private $preferenceService;
/** /**
* @param string $AppName * @param string $AppName
* @param IRequest $request * @param IRequest $request
* @param IURLGenerator $urlGenerator
* @param PreferenceService $preferenceService * @param PreferenceService $preferenceService
*/ */
public function __construct($AppName, public function __construct(
string $AppName,
IRequest $request, IRequest $request,
IURLGenerator $urlGenerator, PreferenceService $preferenceService
PreferenceService $preferenceService) { ) {
parent::__construct($AppName, $request); parent::__construct($AppName, $request);
$this->urlGenerator = $urlGenerator;
$this->preferenceService = $preferenceService; $this->preferenceService = $preferenceService;
} }
@ -45,12 +41,10 @@ class PreferenceController extends Controller {
* *
* @param string $scope * @param string $scope
* @param int $fileId * @param int $fileId
* @param string $name if null, return all preferences for $scope + $fileId * @param ?string $name if null, return all preferences for $scope + $fileId
*
* @return array|\OCP\AppFramework\Http\JSONResponse
*/ */
public function get($scope, $fileId, $name) { public function get(string $scope, int $fileId, ?string $name = null): JSONResponse {
return $this->preferenceService->get($scope, $fileId, $name); return new JSONResponse($this->preferenceService->get($scope, $fileId, $name));
} }
/** /**
@ -66,8 +60,8 @@ class PreferenceController extends Controller {
* *
* @return array|\OCP\AppFramework\Http\JSONResponse * @return array|\OCP\AppFramework\Http\JSONResponse
*/ */
public function set($scope, $fileId, $name, $value) { public function set(string $scope, int $fileId, string $name, string $value) {
return $this->preferenceService->set($scope, $fileId, $name, $value); return new JSONResponse($this->preferenceService->set($scope, $fileId, $name, $value));
} }
@ -79,11 +73,9 @@ class PreferenceController extends Controller {
* *
* @param string $scope * @param string $scope
* @param string $name if null, return all default preferences for scope * @param string $name if null, return all default preferences for scope
*
* @return array|\OCP\AppFramework\Http\JSONResponse
*/ */
public function getDefault($scope, $name) { public function getDefault(string $scope, string $name): JSONResponse {
return $this->preferenceService->getDefault($scope, $name); return new JSONResponse($this->preferenceService->getDefault($scope, $name));
} }
/** /**
@ -95,11 +87,9 @@ class PreferenceController extends Controller {
* @param string $scope * @param string $scope
* @param string $name * @param string $name
* @param string $value * @param string $value
*
* @return array|\OCP\AppFramework\Http\JSONResponse
*/ */
public function setDefault($scope, $name, $value) { public function setDefault(string $scope, string $name, string $value): JSONResponse {
return $this->preferenceService->setDefault($scope, $name, $value); return new JSONResponse($this->preferenceService->setDefault($scope, $name, $value));
} }
/** /**
@ -108,20 +98,18 @@ class PreferenceController extends Controller {
* @param string $scope * @param string $scope
* @param int $fileId * @param int $fileId
* @param string $name * @param string $name
*
*/ */
public function delete($scope, $fileId, $name) { public function delete(string $scope, int $fileId, string $name): void {
return $this->preferenceService->delete($scope, $fileId, $name); $this->preferenceService->delete($scope, $fileId, $name);
} }
/** /**
* @brief delete default preference * @brief delete default preference
* *
* @param $scope * @param string $scope
* @param $name * @param string $name
*
*/ */
public function deleteDefault($scope, $name) { public function deleteDefault(string $scope, string $name): void {
return $this->preferenceService->deleteDefault($scope, $name); $this->preferenceService->deleteDefault($scope, $name);
} }
} }

View File

@ -13,33 +13,11 @@
namespace OCA\Epubreader\Controller; namespace OCA\Epubreader\Controller;
use OCA\Epubreader\Config; use OCA\Epubreader\Config;
use OCA\Epubreader\Service\PreferenceService;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\IURLGenerator;
class SettingsController extends Controller { class SettingsController extends Controller {
private $urlGenerator;
private $preferenceService;
/**
* @param string $AppName
* @param IRequest $request
* @param IURLGenerator $urlGenerator
* @param PreferenceService $preferenceService
*/
public function __construct($AppName,
IRequest $request,
IURLGenerator $urlGenerator,
PreferenceService $preferenceService) {
parent::__construct($AppName, $request);
$this->urlGenerator = $urlGenerator;
$this->preferenceService = $preferenceService;
}
/** /**
* @brief set preference for file type association * @brief set preference for file type association
* *
@ -48,11 +26,8 @@ class SettingsController extends Controller {
* @param int $EpubEnable * @param int $EpubEnable
* @param int $PdfEnable * @param int $PdfEnable
* @param int $CbxEnable * @param int $CbxEnable
*
* @return array|\OCP\AppFramework\Http\JSONResponse
*/ */
public function setPreference(int $EpubEnable, int $PdfEnable, int $CbxEnable) { public function setPreference(int $EpubEnable, int $PdfEnable, int $CbxEnable): JSONResponse {
$l = \OC::$server->getL10N('epubreader'); $l = \OC::$server->getL10N('epubreader');
Config::set('epub_enable', $EpubEnable); Config::set('epub_enable', $EpubEnable);

View File

@ -12,13 +12,12 @@ namespace OCA\Epubreader\Db;
class Bookmark extends ReaderEntity implements \JsonSerializable { class Bookmark extends ReaderEntity implements \JsonSerializable {
protected $userId; // user protected string $userId; // user
protected $fileId; // book (identified by fileId) for which this mark is valid protected int $fileId; // book (identified by fileId) for which this mark is valid
protected $type; // type, defaults to "bookmark" protected string $type; // type, defaults to "bookmark"
protected $name; // name, defaults to $location protected string $name; // name, defaults to $location
protected $value; // bookmark value (format-specific, eg. page number for PDF, CFI for epub, etc) protected string $value; // bookmark value (format-specific, eg. page number for PDF, CFI for epub, etc)
protected $content; // bookmark content (annotations etc), can be empty protected string $content; // bookmark content (annotations etc), can be empty
protected $lastModified; // modification timestamp
public function jsonSerialize(): array { public function jsonSerialize(): array {
return [ return [
@ -33,7 +32,7 @@ class Bookmark extends ReaderEntity implements \JsonSerializable {
]; ];
} }
public function toService() { public function toService(): array {
return [ return [
'name' => $this->getName(), 'name' => $this->getName(),
'type' => $this->getType(), 'type' => $this->getType(),
@ -43,59 +42,51 @@ class Bookmark extends ReaderEntity implements \JsonSerializable {
]; ];
} }
public function getUserId() { public function getUserId(): string {
return $this->userId; return $this->userId;
} }
public function setUserId($userId) { public function setUserId(string $userId): void {
$this->userId = $userId; $this->userId = $userId;
} }
public function getFileId() { public function getFileId(): int {
return $this->fileId; return $this->fileId;
} }
public function setFileId(int $fileId) { public function setFileId(int $fileId): void {
$this->fileId = $fileId; $this->fileId = $fileId;
} }
public function getType() { public function getType(): string {
return $this->type; return $this->type;
} }
public function setType($type) { public function setType(string $type): void {
$this->type = $type; $this->type = $type;
} }
public function getName() { public function getName(): string {
return $this->name; return $this->name;
} }
public function setName(string $name) { public function setName(string $name): void {
$this->name = $name; $this->name = $name;
} }
public function getValue() { public function getValue(): string {
return $this->value; return $this->value;
} }
public function setValue(string $value) { public function setValue(string $value): void {
$this->value = $value; $this->value = $value;
} }
public function getContent() { public function getContent(): string {
return $this->content; return $this->content;
} }
public function setContent($content) { public function setContent(string $content): void {
$this->content = $content; $this->content = $content;
} }
public function getLastModified() {
return $this->lastModified;
}
public function setLastModified($lastModified) {
$this->lastModified = $lastModified;
}
} }

View File

@ -11,31 +11,31 @@
namespace OCA\Epubreader\Db; namespace OCA\Epubreader\Db;
use OCA\Epubreader\Utility\Time; use OCA\Epubreader\Utility\Time;
use OCP\AppFramework\Db\Entity;
use OCP\IDBConnection; use OCP\IDBConnection;
class BookmarkMapper extends ReaderMapper { class BookmarkMapper extends ReaderMapper {
private $userId; private string $userId;
/** /**
* @param IDbConnection $db * @param IDbConnection $db
* @param $UserId * @param string $UserId
* @param Time $time * @param Time $time
*/ */
public function __construct(IDBConnection $db, $UserId, Time $time) { public function __construct(IDBConnection $db, string $UserId, Time $time) {
parent::__construct($db, 'reader_bookmarks', Bookmark::class, $time); parent::__construct($db, 'reader_bookmarks', Bookmark::class, $time);
/** @var int $UserId */
$this->userId = $UserId; $this->userId = $UserId;
} }
/** /**
* @brief get bookmarks for $fileId+$userId(+$name) * @brief get bookmarks for $fileId+$userId(+$name)
* @param $fileId * @param int $fileId
* @param string $name * @param ?string $name
* @return array * @param ?string $type
*
* @return ReaderEntity[]
*/ */
public function get(int $fileId, $name, $type = null) { public function get(int $fileId, ?string $name = null, ?string $type = null): array {
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$query->select('*') $query->select('*')
->from($this->getTableName()) ->from($this->getTableName())
@ -57,17 +57,18 @@ class BookmarkMapper extends ReaderMapper {
* @brief write bookmark to database * @brief write bookmark to database
* *
* @param int $fileId * @param int $fileId
* @param string $name * @param ?string $name
* @param string $value * @param string $value
* @param ?string $type
* @param ?string $content
* *
* @return Entity the newly created or updated bookmark * @return ReaderEntity the newly created or updated bookmark
*/ */
public function set($fileId, $name, $value, $type, $content = null) { public function set(int $fileId, ?string $name = null, string $value, ?string $type = null, ?string $content = null): ReaderEntity {
/** @var Bookmark[] $result */
$result = $this->get($fileId, $name); $result = $this->get($fileId, $name);
if(empty($result)) { if(empty($result)) {
// anonymous bookmarks are named after their contents // anonymous bookmarks are named after their contents
if (null === $name) { if (null === $name) {
$name = $value; $name = $value;
@ -84,13 +85,13 @@ class BookmarkMapper extends ReaderMapper {
$bookmark->setType($type); $bookmark->setType($type);
$bookmark->setName($name); $bookmark->setName($name);
$bookmark->setValue($value); $bookmark->setValue($value);
$bookmark->setContent($content); $bookmark->setContent($content ?? '');
$this->insert($bookmark); $this->insert($bookmark);
} else { } else {
$bookmark = $result[0]; $bookmark = $result[0];
$bookmark->setValue($value); $bookmark->setValue($value);
$bookmark->setContent($content); $bookmark->setContent($content ?? '');
$this->update($bookmark); $this->update($bookmark);
} }

View File

@ -12,12 +12,11 @@ namespace OCA\Epubreader\Db;
class Preference extends ReaderEntity implements \JsonSerializable { class Preference extends ReaderEntity implements \JsonSerializable {
protected $userId; // user for whom this preference is valid protected string $userId; // user for whom this preference is valid
protected $scope; // scope (default or specific renderer) protected string $scope; // scope (default or specific renderer)
protected $fileId; // file for which this preference is set protected int $fileId; // file for which this preference is set
protected $name; // preference name protected string $name; // preference name
protected $value; // preference value protected string $value; // preference value
protected $lastModified; // modification timestamp
public function jsonSerialize(): array { public function jsonSerialize(): array {
return [ return [
@ -30,58 +29,50 @@ class Preference extends ReaderEntity implements \JsonSerializable {
]; ];
} }
public function toService() { public function toService(): array {
return [ return [
'name' => $this->getName(), 'name' => $this->getName(),
'value' => $this->conditional_json_decode($this->getValue()), 'value' => $this->conditional_json_decode($this->getValue()),
]; ];
} }
public function getUserId() { public function getUserId(): string {
return $this->userId; return $this->userId;
} }
public function setUserId($userId) { public function setUserId(string $userId): void {
$this->userId = $userId; $this->userId = $userId;
} }
public function getScope() { public function getScope(): string {
return $this->scope; return $this->scope;
} }
public function setScope(string $scope) { public function setScope(string $scope): void {
$this->scope = $scope; $this->scope = $scope;
} }
public function getFileId() { public function getFileId(): int {
return $this->fileId; return $this->fileId;
} }
public function setFileId(int $fileId) { public function setFileId(int $fileId): void {
$this->fileId = $fileId; $this->fileId = $fileId;
} }
public function getName() { public function getName(): string {
return $this->name; return $this->name;
} }
public function setName(string $name) { public function setName(string $name): void {
$this->name = $name; $this->name = $name;
} }
public function getValue() { public function getValue(): string {
return $this->value; return $this->value;
} }
public function setValue(string $value) { public function setValue(string $value): void {
$this->value = $value; $this->value = $value;
} }
public function getLastModified() {
return $this->lastModified;
}
public function setLastModified($lastModified) {
$this->lastModified = $lastModified;
}
} }

View File

@ -11,14 +11,13 @@
namespace OCA\Epubreader\Db; namespace OCA\Epubreader\Db;
use OCA\Epubreader\Utility\Time; use OCA\Epubreader\Utility\Time;
use OCP\AppFramework\Db\Entity;
use OCP\IDBConnection; use OCP\IDBConnection;
class PreferenceMapper extends ReaderMapper { class PreferenceMapper extends ReaderMapper {
private $userId; private string $userId;
public function __construct(IDBConnection $db, $UserId, Time $time) { public function __construct(IDBConnection $db, string $UserId, Time $time) {
parent::__construct($db, 'reader_prefs', Preference::class, $time); parent::__construct($db, 'reader_prefs', Preference::class, $time);
$this->userId = $UserId; $this->userId = $UserId;
} }
@ -28,10 +27,11 @@ class PreferenceMapper extends ReaderMapper {
* *
* @param string $scope * @param string $scope
* @param int $fileId * @param int $fileId
* @param string $name * @param ?string $name
* @return array *
* @return ReaderEntity[]
*/ */
public function get($scope, $fileId, $name = null) { public function get(string $scope, int $fileId, ?string $name = null): array {
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$query->select('*') $query->select('*')
->from($this->getTableName()) ->from($this->getTableName())
@ -54,14 +54,13 @@ class PreferenceMapper extends ReaderMapper {
* @param string $name * @param string $name
* @param string $value * @param string $value
* *
* @return Entity the newly created or updated preference * @return ReaderEntity the newly created or updated preference
*/ */
public function set($scope, $fileId, $name, $value) { public function set(string $scope, int $fileId, string $name, string $value): ReaderEntity {
/** @var Preference[] $result */
$result = $this->get($scope, $fileId, $name); $result = $this->get($scope, $fileId, $name);
if(empty($result)) { if(empty($result)) {
$preference = new Preference(); $preference = new Preference();
$preference->setScope($scope); $preference->setScope($scope);
$preference->setFileId($fileId); $preference->setFileId($fileId);

View File

@ -12,12 +12,12 @@ namespace OCA\Epubreader\Db;
use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\Entity;
class ReaderEntity extends Entity { abstract class ReaderEntity extends Entity {
private $lastModified; protected int $lastModified; // modification timestamp
/* returns decoded json if input is json, otherwise returns input */ /* returns decoded json if input is json, otherwise returns input */
public static function conditional_json_decode($el) { public static function conditional_json_decode(string $el): mixed {
$result = json_decode($el); $result = json_decode($el);
if (json_last_error() === JSON_ERROR_NONE) { if (json_last_error() === JSON_ERROR_NONE) {
return $result; return $result;
@ -26,12 +26,13 @@ class ReaderEntity extends Entity {
} }
} }
public function getLastModified() { public function getLastModified(): int {
return $this->lastModified; return $this->lastModified;
} }
public function setLastModified(string $lastModified) { public function setLastModified(int $lastModified): void {
$this->lastModified = $lastModified; $this->lastModified = $lastModified;
} }
abstract public function toService(): array;
} }

View File

@ -13,7 +13,6 @@ namespace OCA\Epubreader\Db;
use OCA\Epubreader\Utility\Time; use OCA\Epubreader\Utility\Time;
use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper; use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection; use OCP\IDBConnection;
/** /**
@ -21,12 +20,15 @@ use OCP\IDBConnection;
*/ */
abstract class ReaderMapper extends QBMapper { abstract class ReaderMapper extends QBMapper {
/** private Time $time;
* @var Time
*/
private $time;
public function __construct(IDBConnection $db, $table, $entity, Time $time) { /**
* @param IDBConnection $db Instance of the Db abstraction layer
* @param string $table the name of the table. set this to allow entity
* @param class-string<ReaderEntity>|null $entity the name of the entity that the sql should be mapped to queries without using sql
* @param Time $time
*/
public function __construct(IDBConnection $db, string $table, ?string $entity = null, Time $time) {
parent::__construct($db, $table, $entity); parent::__construct($db, $table, $entity);
$this->time = $time; $this->time = $time;
} }

View File

@ -17,7 +17,7 @@ use OCP\Util;
class Hooks { class Hooks {
public static function register() { public static function register(): void {
Util::connectHook('\OCP\Config', 'js', 'OCA\Epubreader\Hooks', 'announce_settings'); Util::connectHook('\OCP\Config', 'js', 'OCA\Epubreader\Hooks', 'announce_settings');
\OC::$server->getRootFolder()->listen('\OC\Files', 'preDelete', function (Node $node) { \OC::$server->getRootFolder()->listen('\OC\Files', 'preDelete', function (Node $node) {
@ -32,7 +32,7 @@ class Hooks {
}); });
} }
public static function announce_settings(array $settings) { public static function announce_settings(array $settings): void {
// Nextcloud encodes this as JSON, Owncloud does not (yet) (#75) // Nextcloud encodes this as JSON, Owncloud does not (yet) (#75)
// TODO: rmeove this when Owncloud starts encoding oc_appconfig as JSON just like it already encodes most other properties // TODO: rmeove this when Owncloud starts encoding oc_appconfig as JSON just like it already encodes most other properties
$isJson = self::isJson($settings['array']['oc_appconfig']); $isJson = self::isJson($settings['array']['oc_appconfig']);
@ -43,27 +43,27 @@ class Hooks {
$settings['array']['oc_appconfig'] = ($isJson) ? json_encode($array) : $array; $settings['array']['oc_appconfig'] = ($isJson) ? json_encode($array) : $array;
} }
protected static function deleteFile(IDBConnection $connection, $fileId) { protected static function deleteFile(IDBConnection $connection, int $fileId): void {
$queryBuilder = $connection->getQueryBuilder(); $queryBuilder = $connection->getQueryBuilder();
$queryBuilder->delete('reader_bookmarks')->where('file_id = file_id')->setParameter('file_id', $fileId); $queryBuilder->delete('reader_bookmarks')->where('file_id = file_id')->setParameter('file_id', $fileId);
$queryBuilder->execute(); $queryBuilder->executeStatement();
$queryBuilder = $connection->getQueryBuilder(); $queryBuilder = $connection->getQueryBuilder();
$queryBuilder->delete('reader_prefs')->where('file_id = file_id')->setParameter('file_id', $fileId); $queryBuilder->delete('reader_prefs')->where('file_id = file_id')->setParameter('file_id', $fileId);
$queryBuilder->execute(); $queryBuilder->executeStatement();
} }
protected static function deleteUser(IDBConnection $connection, $userId) { protected static function deleteUser(IDBConnection $connection, string $userId): void {
$queryBuilder = $connection->getQueryBuilder(); $queryBuilder = $connection->getQueryBuilder();
$queryBuilder->delete('reader_bookmarks')->where('user_id = user_id')->setParameter('user_id', $userId); $queryBuilder->delete('reader_bookmarks')->where('user_id = user_id')->setParameter('user_id', $userId);
$queryBuilder->execute(); $queryBuilder->executeStatement();
$queryBuilder = $connection->getQueryBuilder(); $queryBuilder = $connection->getQueryBuilder();
$queryBuilder->delete('reader_prefs')->where('user_id = user_id')->setParameter('user_id', $userId); $queryBuilder->delete('reader_prefs')->where('user_id = user_id')->setParameter('user_id', $userId);
$queryBuilder->execute(); $queryBuilder->executeStatement();
} }
private static function isJson($string) { private static function isJson(mixed $string): bool {
return is_string($string) && is_array(json_decode($string, true)) && (json_last_error() == JSON_ERROR_NONE) ? true : false; return is_string($string) && is_array(json_decode($string, true)) && (json_last_error() == JSON_ERROR_NONE) ? true : false;
} }
} }

View File

@ -19,16 +19,15 @@ class Version010404Date20201030180941 extends SimpleMigrationStep {
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options * @param array $options
*/ */
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
} }
/** /**
* @param IOutput $output * @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options * @param array $options
* @return null|ISchemaWrapper
*/ */
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */ /** @var ISchemaWrapper $schema */
$schema = $schemaClosure(); $schema = $schemaClosure();
@ -138,6 +137,6 @@ class Version010404Date20201030180941 extends SimpleMigrationStep {
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options * @param array $options
*/ */
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
} }
} }

View File

@ -11,6 +11,7 @@
namespace OCA\Epubreader\Service; namespace OCA\Epubreader\Service;
use OCA\Epubreader\Db\BookmarkMapper; use OCA\Epubreader\Db\BookmarkMapper;
use OCA\Epubreader\Db\ReaderEntity;
class BookmarkService extends Service { class BookmarkService extends Service {
@ -18,13 +19,11 @@ class BookmarkService extends Service {
public const CURSOR = '__CURSOR__'; public const CURSOR = '__CURSOR__';
public const bookmark_type = 'bookmark'; public const bookmark_type = 'bookmark';
private $bookmarkMapper; private BookmarkMapper $bookmarkMapper;
private $userId;
public function __construct(BookmarkMapper $bookmarkMapper, $UserId) { public function __construct(BookmarkMapper $bookmarkMapper) {
parent::__construct($bookmarkMapper); parent::__construct($bookmarkMapper);
$this->bookmarkMapper = $bookmarkMapper; $this->bookmarkMapper = $bookmarkMapper;
$this->userId = $UserId;
} }
/** /**
@ -33,14 +32,13 @@ class BookmarkService extends Service {
* bookmark type is format-dependent, eg CFI for epub, page number for CBR/CBZ, etc * bookmark type is format-dependent, eg CFI for epub, page number for CBR/CBZ, etc
* *
* @param int $fileId * @param int $fileId
* @param string $name * @param ?string $name
* * @param ?string $type
* @return array
*/ */
public function get($fileId, $name = null, $type = null) { public function get($fileId, ?string $name = null, ?string $type = null): array {
$result = $this->bookmarkMapper->get($fileId, $name, $type); $result = $this->bookmarkMapper->get($fileId, $name, $type);
return array_map( return array_map(
function ($entity) { function (ReaderEntity $entity) {
return $entity->toService(); return $entity->toService();
}, $result); }, $result);
} }
@ -51,12 +49,12 @@ class BookmarkService extends Service {
* position type is format-dependent, eg CFI for epub, page number for CBR/CBZ, etc * position type is format-dependent, eg CFI for epub, page number for CBR/CBZ, etc
* *
* @param int $fileId * @param int $fileId
* @param string $name * @param ?string $name
* @param string $value * @param string $value
* * @param ?string $type
* @return array * @param ?string $content
*/ */
public function set($fileId, $name, $value, $type = null, $content = null) { public function set(int $fileId, ?string $name = null, string $value, ?string $type = null, ?string $content = null): ReaderEntity {
return $this->bookmarkMapper->set($fileId, $name, $value, $type, $content); return $this->bookmarkMapper->set($fileId, $name, $value, $type, $content);
} }
@ -64,14 +62,13 @@ class BookmarkService extends Service {
* @brief get cursor (current position in book) * @brief get cursor (current position in book)
* *
* @param int $fileId * @param int $fileId
*
* @return array
*/ */
public function getCursor($fileId) { public function getCursor(int $fileId): array {
$result = $this->get($fileId, static::CURSOR); $result = $this->get($fileId, static::CURSOR);
if (count($result) === 1) { if (count($result) === 1) {
return $result[0]; return $result[0];
} }
return [];
} }
/** /**
@ -79,10 +76,8 @@ class BookmarkService extends Service {
* *
* @param int $fileId * @param int $fileId
* @param string $value * @param string $value
*
* @return array
*/ */
public function setCursor($fileId, $value) { public function setCursor(int $fileId, string $value): ReaderEntity {
return $this->bookmarkMapper->set($fileId, static::CURSOR, $value, static::bookmark_type); return $this->bookmarkMapper->set($fileId, static::CURSOR, $value, static::bookmark_type);
} }
@ -90,10 +85,10 @@ class BookmarkService extends Service {
* @brief delete bookmark * @brief delete bookmark
* *
* @param int $fileId * @param int $fileId
* @param string $name * @param ?string $name
* * @param ?string $type
*/ */
public function delete($fileId, $name, $type = null) { public function delete($fileId, ?string $name = null, ?string $type = null): void {
foreach ($this->bookmarkMapper->get($fileId, $name, $type) as $bookmark) { foreach ($this->bookmarkMapper->get($fileId, $name, $type) as $bookmark) {
$this->bookmarkMapper->delete($bookmark); $this->bookmarkMapper->delete($bookmark);
} }
@ -103,9 +98,8 @@ class BookmarkService extends Service {
* @brief delete cursor * @brief delete cursor
* *
* @param int $fileId * @param int $fileId
*
*/ */
public function deleteCursor($fileId) { public function deleteCursor(int $fileId): void {
$this->delete($fileId, static::CURSOR, static::bookmark_type); $this->delete($fileId, static::CURSOR, static::bookmark_type);
} }
} }

View File

@ -1,64 +0,0 @@
<?php
/**
* @author Frank de Lange
* @copyright 2017 Frank de Lange
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Epubreader\Service;
use OCP\App\IAppManager;
class MetadataService {
private $appManager;
/**
* @param IAppManager $appManager
*/
public function __construct(IAppManager $appManager) {
$this->appManager = $appManager;
}
/**
* @brief get metadata item(s)
*
* @param int $fileId
* @param string $name
*
* @return array
*/
public function get($fileId, $name = null) {
return [];
}
/**
* @brief write metadata to database
*
* @param int $fileId
* @param array $value
*
* @return array
*/
public function setAll($fileId, $value) {
// no-op for now
return [];
}
/**
* @brief write metadata item to database
*
* @param int $fileId
* @param string $name
* @param array $value
*
* @return array
*/
public function set($fileId, $name, $value) {
// no-op for now
return [];
}
}

View File

@ -11,6 +11,7 @@
namespace OCA\Epubreader\Service; namespace OCA\Epubreader\Service;
use OCA\Epubreader\Db\PreferenceMapper; use OCA\Epubreader\Db\PreferenceMapper;
use OCA\Epubreader\Db\ReaderEntity;
class PreferenceService extends Service { class PreferenceService extends Service {
@ -18,7 +19,7 @@ class PreferenceService extends Service {
// value 0 to indicate a default preference // value 0 to indicate a default preference
public const DEFAULTS = 0; public const DEFAULTS = 0;
private $preferenceMapper; private PreferenceMapper $preferenceMapper;
/** /**
* @param PreferenceMapper $preferenceMapper * @param PreferenceMapper $preferenceMapper
@ -36,11 +37,11 @@ class PreferenceService extends Service {
* *
* @param string $scope * @param string $scope
* @param int $fileId * @param int $fileId
* @param string $name * @param ?string $name
* *
* @return array * @return array
*/ */
public function get($scope, $fileId, $name = null) { public function get(string $scope, int $fileId, ?string $name = null): array {
$result = $this->preferenceMapper->get($scope, $fileId, $name); $result = $this->preferenceMapper->get($scope, $fileId, $name);
return array_map( return array_map(
function ($entity) { function ($entity) {
@ -58,10 +59,8 @@ class PreferenceService extends Service {
* @param int $fileId * @param int $fileId
* @param string $name * @param string $name
* @param string $value * @param string $value
*
* @return array
*/ */
public function set($scope, $fileId, $name, $value) { public function set(string $scope, int $fileId, string $name, string $value): ReaderEntity {
return $this->preferenceMapper->set($scope, $fileId, $name, $value); return $this->preferenceMapper->set($scope, $fileId, $name, $value);
} }
@ -69,11 +68,9 @@ class PreferenceService extends Service {
* @brief get default preference * @brief get default preference
* *
* @param string $scope * @param string $scope
* @param string $name * @param ?string $name
*
* @return array
*/ */
public function getDefault($scope, $name = null) { public function getDefault(string $scope, ?string $name = null): array {
return $this->get($scope, static::DEFAULTS, $name); return $this->get($scope, static::DEFAULTS, $name);
} }
@ -83,10 +80,8 @@ class PreferenceService extends Service {
* @param string $scope * @param string $scope
* @param string $name * @param string $name
* @param string $value * @param string $value
*
* @return array
*/ */
public function setDefault($scope, $name, $value) { public function setDefault($scope, $name, $value): ReaderEntity {
return $this->preferenceMapper->set($scope, static::DEFAULTS, $name, $value); return $this->preferenceMapper->set($scope, static::DEFAULTS, $name, $value);
} }
@ -95,10 +90,10 @@ class PreferenceService extends Service {
* *
* @param string $scope * @param string $scope
* @param int $fileId * @param int $fileId
* @param string $name * @param ?string $name
* *
*/ */
public function delete($scope, $fileId, $name) { public function delete(string $scope, int $fileId, ?string $name = null): void {
foreach($this->preferenceMapper->get($scope, $fileId, $name) as $preference) { foreach($this->preferenceMapper->get($scope, $fileId, $name) as $preference) {
$this->preferenceMapper->delete($preference); $this->preferenceMapper->delete($preference);
} }
@ -108,10 +103,10 @@ class PreferenceService extends Service {
* @brief delete default * @brief delete default
* *
* @param string $scope * @param string $scope
* @param string $name * @param ?string $name
* *
*/ */
public function deleteDefault($scope, $name) { public function deleteDefault(string $scope, ?string $name = null): void {
$this->delete($scope, static::DEFAULTS, $name); $this->delete($scope, static::DEFAULTS, $name);
} }
} }

View File

@ -13,8 +13,7 @@ namespace OCA\Epubreader\Service;
use OCA\Epubreader\Db\ReaderMapper; use OCA\Epubreader\Db\ReaderMapper;
abstract class Service { abstract class Service {
protected ReaderMapper $mapper;
protected $mapper;
public function __construct(ReaderMapper $mapper) { public function __construct(ReaderMapper $mapper) {
$this->mapper = $mapper; $this->mapper = $mapper;

View File

@ -17,11 +17,11 @@ use OCP\Settings\ISettings;
class Personal implements ISettings { class Personal implements ISettings {
private $userId; private string $userId;
private $configManager; private IConfig $configManager;
public function __construct( public function __construct(
$userId, string $userId,
IConfig $configManager IConfig $configManager
) { ) {
$this->userId = $userId; $this->userId = $userId;
@ -32,13 +32,13 @@ class Personal implements ISettings {
* @return TemplateResponse returns the instance with all parameters set, ready to be rendered * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
* @since 9.1 * @since 9.1
*/ */
public function getForm() { public function getForm(): TemplateResponse {
$parameters = [ $parameters = [
'EpubEnable' => $this->configManager->getUserValue($this->userId, 'epubreader', 'epub_enable'), 'EpubEnable' => $this->configManager->getUserValue($this->userId, 'epubreader', 'epub_enable'),
'PdfEnable' => $this->configManager->getUserValue($this->userId, 'epubreader', 'pdf_enable'), 'PdfEnable' => $this->configManager->getUserValue($this->userId, 'epubreader', 'pdf_enable'),
'CbxEnable' => $this->configManager->getUserValue($this->userId, 'epubreader', 'cbx_enable'), 'CbxEnable' => $this->configManager->getUserValue($this->userId, 'epubreader', 'cbx_enable'),
]; ];
return new TemplateResponse('epubreader', 'settings-personal', $parameters, ''); return new TemplateResponse('epubreader', 'settings-personal', $parameters, '');
} }
@ -47,7 +47,7 @@ class Personal implements ISettings {
* *
* @return TemplateResponse * @return TemplateResponse
*/ */
public function getPanel() { public function getPanel(): TemplateResponse {
return $this->getForm(); return $this->getForm();
} }
@ -55,7 +55,7 @@ class Personal implements ISettings {
* @return string the section ID, e.g. 'sharing' * @return string the section ID, e.g. 'sharing'
* @since 9.1 * @since 9.1
*/ */
public function getSection() { public function getSection(): string {
return 'epubreader'; return 'epubreader';
} }
@ -64,7 +64,7 @@ class Personal implements ISettings {
* *
* @return string * @return string
*/ */
public function getSectionID() { public function getSectionID(): string {
return 'epubreader'; return 'epubreader';
} }
@ -76,7 +76,7 @@ class Personal implements ISettings {
* E.g.: 70 * E.g.: 70
* @since 9.1 * @since 9.1
*/ */
public function getPriority() { public function getPriority(): int {
return 10; return 10;
} }
} }

View File

@ -16,10 +16,9 @@ use OCP\IURLGenerator;
use OCP\Settings\IIconSection; use OCP\Settings\IIconSection;
class PersonalSection implements IIconSection { class PersonalSection implements IIconSection {
/** @var IURLGenerator */
private $urlGenerator; private IURLGenerator $urlGenerator;
/** @var IL10N */ private IL10N $l;
private $l;
public function __construct(IURLGenerator $urlGenerator, IL10N $l) { public function __construct(IURLGenerator $urlGenerator, IL10N $l) {
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
@ -29,18 +28,18 @@ class PersonalSection implements IIconSection {
/** /**
* returns the relative path to an 16*16 icon describing the section. * returns the relative path to an 16*16 icon describing the section.
* *
* @returns string * @return string
*/ */
public function getIcon() { public function getIcon(): string {
return $this->urlGenerator->imagePath('epubreader', 'app.svg'); return $this->urlGenerator->imagePath('epubreader', 'app.svg');
} }
/** /**
* returns the ID of the section. It is supposed to be a lower case string, * returns the ID of the section. It is supposed to be a lower case string,
* *
* @returns string * @return string
*/ */
public function getID() { public function getID(): string {
return 'epubreader'; return 'epubreader';
} }
@ -49,7 +48,7 @@ class PersonalSection implements IIconSection {
* *
* @return string * @return string
*/ */
public function getName() { public function getName(): string {
return $this->l->t('EPUB/CBZ/PDF ebook reader'); return $this->l->t('EPUB/CBZ/PDF ebook reader');
} }
@ -58,7 +57,7 @@ class PersonalSection implements IIconSection {
* *
* @return int * @return int
*/ */
public function getPriority() { public function getPriority(): int {
return 20; return 20;
} }
} }

View File

@ -11,16 +11,16 @@
namespace OCA\Epubreader\Utility; namespace OCA\Epubreader\Utility;
class Time { class Time {
public function getTime() {
public function getTime(): int {
return time(); return time();
} }
/** /**
* @return string the current unix time in miliseconds * @return int the current unix time in miliseconds
*/ */
public function getMicroTime(): string { public function getMicroTime(): int {
list($millisecs, $secs) = explode(" ", microtime()); list($millisecs, $secs) = explode(" ", microtime());
return $secs . substr($millisecs, 2, 6); return (int) ($secs . substr($millisecs, 2, 6));
} }
} }

View File

@ -16,6 +16,7 @@ namespace OCA\Epubreader;
* Config class for Reader * Config class for Reader
*/ */
class Config { class Config {
/** /**
* @brief get user config value * @brief get user config value
* *
@ -23,7 +24,7 @@ class Config {
* @param string $default default value to use * @param string $default default value to use
* @return string retrieved value or default * @return string retrieved value or default
*/ */
public static function get($key, $default) { public static function get(string $key, string $default): string {
return \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'epubreader', $key, $default); return \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'epubreader', $key, $default);
} }
@ -34,7 +35,7 @@ class Config {
* @param string $value value to use * @param string $value value to use
* @return bool success * @return bool success
*/ */
public static function set($key, $value) { public static function set(string $key, string $value): bool {
return \OC::$server->getConfig()->setUserValue(\OC_User::getUser(), 'epubreader', $key, $value); return \OC::$server->getConfig()->setUserValue(\OC_User::getUser(), 'epubreader', $key, $value);
} }
@ -45,7 +46,7 @@ class Config {
* @param string $default default value to use * @param string $default default value to use
* @return string retrieved value or default * @return string retrieved value or default
*/ */
public static function getApp($key, $default) { public static function getApp(string $key, string $default): string {
return \OC::$server->getConfig()->getAppValue('epubreader', $key, $default); return \OC::$server->getConfig()->getAppValue('epubreader', $key, $default);
} }
@ -56,7 +57,7 @@ class Config {
* @param string $value value to use * @param string $value value to use
* @return bool success * @return bool success
*/ */
public static function setApp($key, $value) { public static function setApp(string $key, string $value): bool {
return \OC::$server->getConfig()->setAppValue('epubreader', $key, $value); return \OC::$server->getConfig()->setAppValue('epubreader', $key, $value);
} }
} }

View File

@ -34,5 +34,11 @@
<referencedClass name="OC" /> <referencedClass name="OC" />
</errorLevel> </errorLevel>
</UndefinedClass> </UndefinedClass>
<DeprecatedMethod>
<errorLevel type="info">
<referencedMethod name="OCP\Util::connectHook" />
</errorLevel>
</DeprecatedMethod>
<PropertyNotSetInConstructor errorLevel="suppress" />
</issueHandlers> </issueHandlers>
</psalm> </psalm>