Completed
Push — master ( 060b04...657701 )
by
unknown
04:35
created

Feed   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 38.03%

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 122
ccs 27
cts 71
cp 0.3803
rs 10
c 4
b 1
f 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
B jsonSerialize() 0 37 2
A toAPI() 0 16 1
A setUrl() 0 7 2
A setLink() 0 6 2
1
<?php
2
/**
3
 * ownCloud - News
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Alessandro Cosentino <[email protected]>
9
 * @author Bernhard Posselt <[email protected]>
10
 * @copyright Alessandro Cosentino 2012
11
 * @copyright Bernhard Posselt 2012, 2014
12
 */
13
14
namespace OCA\News\Db;
15
16
use \OCP\AppFramework\Db\Entity;
17
18
/**
19
 * @method integer getId()
20
 * @method void setId(integer $value)
21
 * @method string getUserId()
22
 * @method void setUserId(string $value)
23
 * @method int getOrdering()
24
 * @method void setOrdering(integer $value)
25
 * @method string getUrlHash()
26
 * @method void setUrlHash(string $value)
27
 * @method string getLocation()
28
 * @method void setLocation(string $value)
29
 * @method string getUrl()
30
 * @method string getTitle()
31
 * @method void setTitle(string $value)
32
 * @method string getLastModified()
33
 * @method void setLastModified(integer $value)
34
 * @method string getHttpLastModified()
35
 * @method void setHttpLastModified(string $value)
36
 * @method string getHttpEtag()
37
 * @method void setHttpEtag(string $value)
38
 * @method string getFaviconLink()
39
 * @method void setFaviconLink(string $value)
40
 * @method integer getAdded()
41
 * @method void setAdded(integer $value)
42
 * @method boolean getPinned()
43
 * @method void setPinned(boolean $value)
44
 * @method integer getFolderId()
45
 * @method void setFolderId(integer $value)
46
 * @method integer getFullTextEnabled()
47
 * @method void setFullTextEnabled(bool $value)
48
 * @method integer getUnreadCount()
49
 * @method void setUnreadCount(integer $value)
50
 * @method string getLink()
51
 * @method boolean getPreventUpdate()
52
 * @method void setPreventUpdate(boolean $value)
53
 * @method integer getDeletedAt()
54
 * @method void setDeletedAt(integer $value)
55
 * @method integer getArticlesPerUpdate()
56
 * @method void setArticlesPerUpdate(integer $value)
57
 * @method integer getUpdateErrorCount()
58
 * @method void setUpdateErrorCount(integer $value)
59
 * @method string getLastUpdateError()
60
 * @method void setLastUpdateError(string $value)
61
 * @method string getBasicAuthUser()
62
 * @method void setBasicAuthUser(string $value)
63
 * @method string getBasicAuthPassword()
64
 * @method void setBasicAuthPassword(string $value)
65
 */
66
class Feed extends Entity implements IAPI, \JsonSerializable {
67
68
    use EntityJSONSerializer;
69
70
    protected $userId;
71
    protected $urlHash;
72
    protected $url;
73
    protected $title;
74
    protected $faviconLink;
75
    protected $added;
76
    protected $folderId;
77
    protected $unreadCount;
78
    protected $link;
79
    protected $preventUpdate;
80
    protected $deletedAt;
81
    protected $articlesPerUpdate;
82
    protected $httpLastModified;
83
    protected $httpEtag;
84
    protected $location;
85
    protected $ordering;
86
    protected $fullTextEnabled;
87
    protected $pinned;
88
    protected $updateMode;
89
    protected $updateErrorCount;
90
    protected $lastUpdateError;
91
    protected $basicAuthUser;
92
    protected $basicAuthPassword;
93
94 14
    public function __construct(){
95 14
        $this->addType('parentId', 'integer');
96 14
        $this->addType('added', 'integer');
97 14
        $this->addType('folderId', 'integer');
98 14
        $this->addType('unreadCount', 'integer');
99 14
        $this->addType('preventUpdate', 'boolean');
100 14
        $this->addType('pinned', 'boolean');
101 14
        $this->addType('deletedAt', 'integer');
102 14
        $this->addType('articlesPerUpdate', 'integer');
103 14
        $this->addType('ordering', 'integer');
104 14
        $this->addType('fullTextEnabled', 'boolean');
105 14
        $this->addType('updateMode', 'integer');
106 14
        $this->addType('updateErrorCount', 'integer');
107 14
    }
108
109
110
    /**
111
     * Turns entitie attributes into an array
112
     */
113
    public function jsonSerialize() {
114
        $serialized = $this->serializeFields([
115
            'id',
116
            'userId',
117
            'urlHash',
118
            'url',
119
            'title',
120
            'faviconLink',
121
            'added',
122
            'folderId',
123
            'unreadCount',
124
            'link',
125
            'preventUpdate',
126
            'deletedAt',
127
            'articlesPerUpdate',
128
            'location',
129
            'ordering',
130
            'fullTextEnabled',
131
            'pinned',
132
            'updateMode',
133
            'updateErrorCount',
134
            'lastUpdateError',
135
            'basicAuthUser',
136
            'basicAuthPassword'
137
        ]);
138
139
        $url = parse_url($this->link)['host'];
140
141
        // strip leading www. to avoid css class confusion
142
        if (strpos($url, 'www.') === 0) {
143
            $url = substr($url, 4);
144
        }
145
146
        $serialized['cssClass'] = 'custom-' . str_replace('.', '-', $url);
147
148
        return $serialized;
149
    }
150
151
152
    public function toAPI() {
153
        return $this->serializeFields([
154
            'id',
155
            'url',
156
            'title',
157
            'faviconLink',
158
            'added',
159
            'folderId',
160
            'unreadCount',
161
            'ordering',
162
            'link',
163
            'pinned',
164
            'updateErrorCount',
165
            'lastUpdateError'
166
        ]);
167
    }
168
169
170 14
    public function setUrl($url) {
171 14
        $url = trim($url);
172 14
        if(strpos($url, 'http') === 0) {
173 14
            parent::setUrl($url);
174 14
            $this->setUrlHash(md5($url));
175 14
        }
176 14
    }
177
178
179 14
    public function setLink($url) {
180 14
        $url = trim($url);
181 14
        if(strpos($url, 'http') === 0) {
182 14
            parent::setLink($url);
183 14
        }
184 14
    }
185
186
187
}
188