diff options
author | Daniel Opitz <git@copynpaste.de> | 2018-09-16 18:07:40 +0200 |
---|---|---|
committer | Daniel Opitz <git@copynpaste.de> | 2018-09-28 23:24:10 +0200 |
commit | 89f2c7cfdba7dcc953a5bff807b7b290294ee516 (patch) | |
tree | 57910dc323e0ee8dc0f654e2343d8fd058751ab0 /lib | |
parent | 2aabd8fd1f9bdee0060b685e883716287db393c5 (diff) |
add setters + getters to Folder and Item entities, fixed unit tests, rearranged methods
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Db/Feed.php | 515 | ||||
-rw-r--r-- | lib/Db/Folder.php | 158 | ||||
-rw-r--r-- | lib/Db/Item.php | 497 |
3 files changed, 742 insertions, 428 deletions
diff --git a/lib/Db/Feed.php b/lib/Db/Feed.php index 885ef5c68..898a93718 100644 --- a/lib/Db/Feed.php +++ b/lib/Db/Feed.php @@ -13,7 +13,7 @@ namespace OCA\News\Db; -use \OCP\AppFramework\Db\Entity; +use OCP\AppFramework\Db\Entity; class Feed extends Entity implements IAPI, \JsonSerializable { @@ -70,307 +70,256 @@ class Feed extends Entity implements IAPI, \JsonSerializable protected $basicAuthPassword = ''; /** - * Turns entity attributes into an array + * @return int|null */ - public function jsonSerialize(): array + public function getAdded() { - $serialized = $this->serializeFields( - [ - 'id', - 'userId', - 'urlHash', - 'url', - 'title', - 'faviconLink', - 'added', - 'folderId', - 'unreadCount', - 'link', - 'preventUpdate', - 'deletedAt', - 'articlesPerUpdate', - 'location', - 'ordering', - 'fullTextEnabled', - 'pinned', - 'updateMode', - 'updateErrorCount', - 'lastUpdateError', - 'basicAuthUser', - 'basicAuthPassword' - ] - ); - - $url = parse_url($this->link, PHP_URL_HOST); - - // strip leading www. to avoid css class confusion - if (strpos($url, 'www.') === 0) { - $url = substr($url, 4); - } - - $serialized['cssClass'] = 'custom-' . str_replace('.', '-', $url); - - return $serialized; + return $this->added; } - - public function toAPI(): array + /** + * @return int + */ + public function getArticlesPerUpdate(): int { - return $this->serializeFields( - [ - 'id', - 'url', - 'title', - 'faviconLink', - 'added', - 'folderId', - 'unreadCount', - 'ordering', - 'link', - 'pinned', - 'updateErrorCount', - 'lastUpdateError' - ] - ); + return $this->articlesPerUpdate; } /** - * @return int + * @return string|null */ - public function getId(): int + public function getBasicAuthPassword() { - return $this->id; + return $this->basicAuthPassword; } /** - * @param int $id + * @return string|null */ - public function setId(int $id) + public function getBasicAuthUser() { - if ($this->id !== $id) { - $this->id = $id; - $this->markFieldUpdated('id'); - } + return $this->basicAuthUser; } /** - * @return string + * @return int|null */ - public function getUserId(): string + public function getDeletedAt() { - return $this->userId; + return $this->deletedAt; } /** - * @param string $userId + * @return string|null */ - public function setUserId(string $userId) + public function getFaviconLink() { - if ($this->userId !== $userId) { - $this->userId = $userId; - $this->markFieldUpdated('userId'); - } + return $this->faviconLink; } /** - * @return string + * @return int */ - public function getUrlHash(): string + public function getFolderId(): int { - return $this->urlHash; + return $this->folderId; } /** - * @param string $urlHash + * @return bool */ - public function setUrlHash(string $urlHash) + public function getFullTextEnabled(): bool { - if ($this->urlHash !== $urlHash) { - $this->urlHash = $urlHash; - $this->markFieldUpdated('urlHash'); - } + return $this->fullTextEnabled; } /** - * @return string + * @return string|null */ - public function getUrl(): string + public function getHttpEtag() { - return $this->url; + return $this->httpEtag; } /** - * @param string $url + * @return string|null */ - public function setUrl(string $url) + public function getHttpLastModified() { - $url = trim($url); - if(strpos($url, 'http') === 0 && $this->url !== $url) { - $this->url = $url; - $this->setUrlHash(md5($url)); - $this->markFieldUpdated('url'); - } + return $this->httpLastModified; } /** - * @return string + * @return int */ - public function getTitle(): string + public function getId(): int { - return $this->title; + return $this->id; } /** - * @param string $title + * @return int|null */ - public function setTitle(string $title) + public function getLastModified() { - if ($this->title !== $title) { - $this->title = $title; - $this->markFieldUpdated('title'); - } + return $this->lastModified; } /** * @return string|null */ - public function getFaviconLink() + public function getLastUpdateError() { - return $this->faviconLink; + return $this->lastUpdateError; } /** - * @param string|null $faviconLink + * @return string|null */ - public function setFaviconLink(string $faviconLink = null) + public function getLink() { - if ($this->faviconLink !== $faviconLink) { - $this->faviconLink = $faviconLink; - $this->markFieldUpdated('faviconLink'); - } + return $this->link; } /** - * @return int|null + * @return string|null */ - public function getAdded() + public function getLocation() { - return $this->added; + return $this->location; } /** - * @param int|null $added + * @return int */ - public function setAdded(int $added = null) + public function getOrdering(): int { - if ($this->added !== $added) { - $this->added = $added; - $this->markFieldUpdated('added'); - } + return $this->ordering; } /** - * @return int + * @return bool */ - public function getFolderId(): int + public function getPinned(): bool { - return $this->folderId; + return $this->pinned; } /** - * @param int $folderId + * @return bool */ - public function setFolderId(int $folderId) + public function getPreventUpdate(): bool { - if ($this->folderId !== $folderId) { - $this->folderId = $folderId; - $this->markFieldUpdated('folderId'); - } + return $this->preventUpdate; } /** - * @return int + * @return string */ - public function getUnreadCount(): int + public function getTitle(): string { - return $this->unreadCount; + return $this->title; } /** - * @param int $unreadCount + * @return int */ - public function setUnreadCount(int $unreadCount) + public function getUnreadCount(): int { - if ($this->unreadCount !== $unreadCount) { - $this->unreadCount = $unreadCount; - $this->markFieldUpdated('unreadCount'); - } + return $this->unreadCount; } /** - * @return string|null + * @return int */ - public function getLink() + public function getUpdateErrorCount(): int { - return $this->link; + return $this->updateErrorCount; } /** - * @param string|null $link + * @return int */ - public function setLink(string $link = null) + public function getUpdateMode(): int { - $link = trim($link); - if(strpos($link, 'http') === 0 && $this->link !== $link) { - $this->link = $link; - $this->markFieldUpdated('link'); - } + return $this->updateMode; } /** - * @return bool + * @return string */ - public function getPreventUpdate(): bool + public function getUrl(): string { - return $this->preventUpdate; + return $this->url; } /** - * @param bool $preventUpdate + * @return string */ - public function setPreventUpdate(bool $preventUpdate) + public function getUrlHash(): string { - if ($this->preventUpdate !== $preventUpdate) { - $this->preventUpdate = $preventUpdate; - $this->markFieldUpdated('preventUpdate'); - } + return $this->urlHash; } /** - * @return int|null + * @return string */ - public function getDeletedAt() + public function getUserId(): string { - return $this->deletedAt; + return $this->userId; } /** - * @param int|null $deletedAt + * Turns entity attributes into an array */ - public function setDeletedAt(int $deletedAt = null) + public function jsonSerialize(): array { - if ($this->deletedAt !== $deletedAt) { - $this->deletedAt = $deletedAt; - $this->markFieldUpdated('deletedAt'); + $serialized = $this->serializeFields([ + 'id', + 'userId', + 'urlHash', + 'url', + 'title', + 'faviconLink', + 'added', + 'folderId', + 'unreadCount', + 'link', + 'preventUpdate', + 'deletedAt', + 'articlesPerUpdate', + 'location', + 'ordering', + 'fullTextEnabled', + 'pinned', + 'updateMode', + 'updateErrorCount', + 'lastUpdateError', + 'basicAuthUser', + 'basicAuthPassword' + ]); + + $url = parse_url($this->link, PHP_URL_HOST); + + // strip leading www. to avoid css class confusion + if (strpos($url, 'www.') === 0) { + $url = substr($url, 4); } + + $serialized['cssClass'] = 'custom-' . str_replace('.', '-', $url); + + return $serialized; } /** - * @return int + * @param int|null $added */ - public function getArticlesPerUpdate(): int + public function setAdded(int $added = null) { - return $this->articlesPerUpdate; + if ($this->added !== $added) { + $this->added = $added; + $this->markFieldUpdated('added'); + } } /** @@ -385,49 +334,69 @@ class Feed extends Entity implements IAPI, \JsonSerializable } /** - * @return string|null + * @param string|null $basicAuthPassword */ - public function getHttpLastModified() + public function setBasicAuthPassword(string $basicAuthPassword = null) { - return $this->httpLastModified; + if ($this->basicAuthPassword !== $basicAuthPassword) { + $this->basicAuthPassword = $basicAuthPassword; + $this->markFieldUpdated('basicAuthPassword'); + } } /** - * @param string|null $httpLastModified + * @param string|null $basicAuthUser */ - public function setHttpLastModified(string $httpLastModified = null) + public function setBasicAuthUser(string $basicAuthUser = null) { - if ($this->httpLastModified !== $httpLastModified) { - $this->httpLastModified = $httpLastModified; - $this->markFieldUpdated('httpLastModified'); + if ($this->basicAuthUser !== $basicAuthUser) { + $this->basicAuthUser = $basicAuthUser; + $this->markFieldUpdated('basicAuthUser'); } } /** - * @return int|null + * @param int|null $deletedAt */ - public function getLastModified() + public function setDeletedAt(int $deletedAt = null) { - return $this->lastModified; + if ($this->deletedAt !== $deletedAt) { + $this->deletedAt = $deletedAt; + $this->markFieldUpdated('deletedAt'); + } } /** - * @param int|null $lastModified + * @param string|null $faviconLink */ - public function setLastModified(int $lastModified = null) + public function setFaviconLink(string $faviconLink = null) { - if ($this->lastModified !== $lastModified) { - $this->lastModified = $lastModified; - $this->markFieldUpdated('lastModified'); + if ($this->faviconLink !== $faviconLink) { + $this->faviconLink = $faviconLink; + $this->markFieldUpdated('faviconLink'); } } /** - * @return string|null + * @param int $folderId */ - public function getHttpEtag() + public function setFolderId(int $folderId) { - return $this->httpEtag; + if ($this->folderId !== $folderId) { + $this->folderId = $folderId; + $this->markFieldUpdated('folderId'); + } + } + + /** + * @param bool $fullTextEnabled + */ + public function setFullTextEnabled(bool $fullTextEnabled) + { + if ($this->fullTextEnabled !== $fullTextEnabled) { + $this->fullTextEnabled = $fullTextEnabled; + $this->markFieldUpdated('fullTextEnabled'); + } } /** @@ -442,68 +411,81 @@ class Feed extends Entity implements IAPI, \JsonSerializable } /** - * @return string|null + * @param string|null $httpLastModified */ - public function getLocation() + public function setHttpLastModified(string $httpLastModified = null) { - return $this->location; + if ($this->httpLastModified !== $httpLastModified) { + $this->httpLastModified = $httpLastModified; + $this->markFieldUpdated('httpLastModified'); + } } /** - * @param string|null $location + * @param int $id */ - public function setLocation(string $location = null) + public function setId(int $id) { - if ($this->location !== $location) { - $this->location = $location; - $this->markFieldUpdated('location'); + if ($this->id !== $id) { + $this->id = $id; + $this->markFieldUpdated('id'); } } /** - * @return int + * @param int|null $lastModified */ - public function getOrdering(): int + public function setLastModified(int $lastModified = null) { - return $this->ordering; + if ($this->lastModified !== $lastModified) { + $this->lastModified = $lastModified; + $this->markFieldUpdated('lastModified'); + } } /** - * @param int $ordering + * @param string|null $lastUpdateError */ - public function setOrdering(int $ordering) + public function setLastUpdateError(string $lastUpdateError = null) { - if ($this->ordering !== $ordering) { - $this->ordering = $ordering; - $this->markFieldUpdated('ordering'); + if ($this->lastUpdateError !== $lastUpdateError) { + $this->lastUpdateError = $lastUpdateError; + $this->markFieldUpdated('lastUpdateError'); } } /** - * @return bool + * @param string|null $link */ - public function getFullTextEnabled(): bool + public function setLink(string $link = null) { - return $this->fullTextEnabled; + $link = trim($link); + if (strpos($link, 'http') === 0 && $this->link !== $link) { + $this->link = $link; + $this->markFieldUpdated('link'); + } } /** - * @param bool $fullTextEnabled + * @param string|null $location */ - public function setFullTextEnabled(bool $fullTextEnabled) + public function setLocation(string $location = null) { - if ($this->fullTextEnabled !== $fullTextEnabled) { - $this->fullTextEnabled = $fullTextEnabled; - $this->markFieldUpdated('fullTextEnabled'); + if ($this->location !== $location) { + $this->location = $location; + $this->markFieldUpdated('location'); } } /** - * @return bool + * @param int $ordering */ - public function getPinned(): bool + public function setOrdering(int $ordering) { - return $this->pinned; + if ($this->ordering !== $ordering) { + $this->ordering = $ordering; + $this->markFieldUpdated('ordering'); + } } /** @@ -518,30 +500,36 @@ class Feed extends Entity implements IAPI, \JsonSerializable } /** - * @return int + * @param bool $preventUpdate */ - public function getUpdateMode(): int + public function setPreventUpdate(bool $preventUpdate) { - return $this->updateMode; + if ($this->preventUpdate !== $preventUpdate) { + $this->preventUpdate = $preventUpdate; + $this->markFieldUpdated('preventUpdate'); + } } /** - * @param int $updateMode + * @param string $title */ - public function setUpdateMode(int $updateMode) + public function setTitle(string $title) { - if ($this->updateMode !== $updateMode) { - $this->updateMode = $updateMode; - $this->markFieldUpdated('updateMode'); + if ($this->title !== $title) { + $this->title = $title; + $this->markFieldUpdated('title'); } } /** - * @return int + * @param int $unreadCount */ - public function getUpdateErrorCount(): int + public function setUnreadCount(int $unreadCount) { - return $this->updateErrorCount; + if ($this->unreadCount !== $unreadCount) { + $this->unreadCount = $unreadCount; + $this->markFieldUpdated('unreadCount'); + } } /** @@ -556,59 +544,68 @@ class Feed extends Entity implements IAPI, \JsonSerializable } /** - * @return string|null - */ - public function getLastUpdateError() - { - return $this->lastUpdateError; - } - - /** - * @param string|null $lastUpdateError + * @param int $updateMode */ - public function setLastUpdateError(string $lastUpdateError = null) + public function setUpdateMode(int $updateMode) { - if ($this->lastUpdateError !== $lastUpdateError) { - $this->lastUpdateError = $lastUpdateError; - $this->markFieldUpdated('lastUpdateError'); + if ($this->updateMode !== $updateMode) { + $this->updateMode = $updateMode; + $this->markFieldUpdated('updateMode'); } } /** - * @return string|null + * @param string $url */ - public function getBasicAuthUser() + public function setUrl(string $url) { - return $this->basicAuthUser; + $url = trim($url); + if (strpos($url, 'http') === 0 && $this->url !== $url) { + $this->url = $url; + $this->setUrlHash(md5($url)); + $this->markFieldUpdated('url'); + } } /** - * @param string|null $basicAuthUser + * @param string $urlHash */ - public function setBasicAuthUser(string $basicAuthUser = null) + public function setUrlHash(string $urlHash) { - if ($this->basicAuthUser !== $basicAuthUser) { - $this->basicAuthUser = $basicAuthUser; - $this->markFieldUpdated('basicAuthUser'); + if ($this->urlHash !== $urlHash) { + $this->urlHash = $urlHash; + $this->markFieldUpdated('urlHash'); } } /** - * @return string|null + * @param string $userId */ - public function getBasicAuthPassword() + public function setUserId(string $userId) { - return $this->basicAuthPassword; + if ($this->userId !== $userId) { + $this->userId = $userId; + $this->markFieldUpdated('userId'); + } } - /** - * @param string|null $basicAuthPassword - */ - public function setBasicAuthPassword(string $basicAuthPassword = null) + public function toAPI(): array { - if ($this->basicAuthPassword !== $basicAuthPassword) { - $this->basicAuthPassword = $basicAuthPassword; - $this->markFieldUpdated('basicAuthPassword'); - } + return $this->serializeFields( + [ + 'id', + 'url', + 'title', + 'faviconLink', + 'added', + 'folderId', + 'unreadCount', + 'ordering', + 'link', + 'pinned', + 'updateErrorCount', + 'lastUpdateError' + ] + ); } } diff --git a/lib/Db/Folder.php b/lib/Db/Folder.php index 4a6ec8ba1..07fa7b369 100644 --- a/lib/Db/Folder.php +++ b/lib/Db/Folder.php @@ -13,67 +13,151 @@ namespace OCA\News\Db; -use \OCP\AppFramework\Db\Entity; +use OCP\AppFramework\Db\Entity; -/** - * @method integer getId() - * @method void setId(integer $value) - * @method string getUserId() - * @method void setUserId(string $value) - * @method string getName() - * @method void setName(string $value) - * @method integer getParentId() - * @method void setParentId(integer $value) - * @method boolean getOpened() - * @method void setOpened(boolean $value) - * @method integer getDeletedAt() - * @method void setDeletedAt(integer $value) - * @method string getLastModified() - * @method void setLastModified(string $value) - */ class Folder extends Entity implements IAPI, \JsonSerializable { use EntityJSONSerializer; + /** @var int|null */ protected $parentId; + /** @var string */ protected $name; - protected $userId; - protected $opened; - protected $deletedAt; - protected $lastModified; + /** @var string */ + protected $userId = ''; + /** @var bool */ + protected $opened = true; + /** @var int|null */ + protected $deletedAt = 0; + /** @var int|null */ + protected $lastModified = 0; + + /** + * @return int|null + */ + public function getDeletedAt() + { + return $this->deletedAt; + } + + public function getId(): int + { + return $this->id; + } + + /** + * @return int|null + */ + public function getLastModified() + { + return $this->lastModified; + } + + public function getName(): string + { + return $this->name; + } + + public function getOpened(): bool + { + return $this->opened; + } + + /** + * @return int|null + */ + public function getParentId() + { + return $this->parentId; + } - public function __construct() + public function getUserId(): string { - $this->addType('parentId', 'integer'); - $this->addType('opened', 'boolean'); - $this->addType('deletedAt', 'integer'); + return $this->userId; } /** - * Turns entitie attributes into an array + * Turns entity attributes into an array */ - public function jsonSerialize() + public function jsonSerialize(): array { return $this->serializeFields( [ - 'id', - 'parentId', - 'name', - 'userId', - 'opened', - 'deletedAt', + 'id', + 'parentId', + 'name', + 'userId', + 'opened', + 'deletedAt', ] ); } - public function toAPI() + public function setDeletedAt(int $deletedAt = null) + { + if ($this->deletedAt !== $deletedAt) { + $this->deletedAt = $deletedAt; + $this->markFieldUpdated('deletedAt'); + } + } + + public function setId(int $id) + { + if ($this->id !== $id) { + $this->id = $id; + $this->markFieldUpdated('id'); + } + } + + public function setLastModified(int $lastModified = null) + { + + if ($this->lastModified !== $lastModified) { + $this->lastModified = $lastModified; + $this->markFieldUpdated('lastModified'); + } + } + + public function setName(string $name) + { + if ($this->name !== $name) { + $this->name = $name; + $this->markFieldUpdated('name'); + } + } + + public function setOpened(bool $opened) + { + if ($this->opened !== $opened) { + $this->opened = $opened; + $this->markFieldUpdated('opened'); + } + } + + public function setParentId(int $parentId = null) + { + if ($this->parentId !== $parentId) { + $this->parentId = $parentId; + $this->markFieldUpdated('parentId'); + } + } + + public function setUserId(string $userId) + { + if ($this->userId !== $userId) { + $this->userId = $userId; + $this->markFieldUpdated('userId'); + } + } + + public function toAPI(): array { return $this->serializeFields( [ - 'id', - 'name' + 'id', + 'name' ] ); } -}
\ No newline at end of file +} diff --git a/lib/Db/Item.php b/lib/Db/Item.php index 1c31f9d70..91c79e44b 100644 --- a/lib/Db/Item.php +++ b/lib/Db/Item.php @@ -13,88 +13,240 @@ namespace OCA\News\Db; -use \OCP\AppFramework\Db\Entity; +use OCP\AppFramework\Db\Entity; -/** - * @method integer getId() - * @method void setId(integer $value) - * @method string getGuid() - * @method void setGuid(string $value) - * @method string getGuidHash() - * @method void setGuidHash(string $value) - * @method string getUrl() - * @method string getTitle() - * @method string getAuthor() - * @method string getRtl() - * @method string getFingerprint() - * @method string getContentHash() - * @method integer getPubDate() - * @method void setPubDate(integer $value) - * @method string getBody() - * @method string getEnclosureMime() - * @method void setEnclosureMime(string $value) - * @method string getEnclosureLink() - * @method void setEnclosureLink(string $value) - * @method integer getFeedId() - * @method void setFeedId(integer $value) - * @method void setRtl(boolean $value) - * @method string getLastModified() - * @method void setLastModified(string $value) - * @method void setFingerprint(string $value) - * @method void setContentHash(string $value) - * @method void setSearchIndex(string $value) - * @method void setUnread(bool $value) - * @method void setStarred(bool $value) - */ class Item extends Entity implements IAPI, \JsonSerializable { use EntityJSONSerializer; + /** @var string|null */ protected $contentHash; + /** @var string */ protected $guidHash; + /** @var string */ protected $guid; + /** @var string|null */ protected $url; + /** @var string|null */ protected $title; + /** @var string|null */ protected $author; + /** @var int|null */ protected $pubDate; + /** @var int|null */ protected $updatedDate; + /** @var string|null */ protected $body; + /** @var string|null */ protected $enclosureMime; + /** @var string|null */ protected $enclosureLink; + /** @var int */ protected $feedId; + /** @var int */ protected $status = 0; - protected $lastModified; + /** @var int|null */ + protected $lastModified = 0; + /** @var string|null */ protected $searchIndex; - protected $rtl; + /** @var bool */ + protected $rtl = false; + /** @var string|null */ protected $fingerprint; + /** @var bool */ protected $unread = false; + /** @var bool */ protected $starred = false; - public function __construct() + /** + * @return int + */ + public function cropApiLastModified(): int { - $this->addType('pubDate', 'integer'); - $this->addType('updatedDate', 'integer'); |