Completed
Pull Request — master (#248)
by
unknown
04:04
created

Note   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 86.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 31
ccs 13
cts 15
cp 0.8667
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromFile() 0 13 3
1
<?php
2
/**
3
 * ownCloud - Notes
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Bernhard Posselt <[email protected]>
9
 * @copyright Bernhard Posselt 2012, 2014
10
 */
11
12
namespace OCA\Notes\Db;
13
14
use OCP\Files\File;
15
use OCP\AppFramework\Db\Entity;
16
17
/**
18
 * Class Note
19
 * @method integer getId()
20
 * @method void setId(integer $value)
21
 * @method integer getModified()
22
 * @method void setModified(integer $value)
23
 * @method string getTitle()
24
 * @method void setTitle(string $value)
25
 * @method string getContent()
26
 * @method void setContent(string $value)
27
 * @method boolean getFavorite()
28
 * @method void setFavorite(boolean $value)
29
 * @package OCA\Notes\Db
30
 */
31
class Note extends Entity {
32
33
    public $modified;
34
    public $title;
35
    public $content;
36
    public $favorite = false;
37
38 13
    public function __construct() {
39 13
        $this->addType('modified', 'integer');
40 13
        $this->addType('favorite', 'boolean');
41 13
    }
42
43
    /**
44
     * @param File $file
45
     * @return static
46
     */
47 7
    public static function fromFile(File $file, $tags=[]){
48 7
        $note = new static();
49 7
        $note->setId($file->getId());
50 7
        $note->setContent($file->getContent());
51 7
        $note->setModified($file->getMTime());
52 7
        $note->setTitle(pathinfo($file->getName(),PATHINFO_FILENAME)); // remove extension
53 7
        if(is_array($tags) && in_array(\OC\Tags::TAG_FAVORITE, $tags)) {
54
            $note->setFavorite(true);
55
            //unset($tags[array_search(\OC\Tags::TAG_FAVORITE, $tags)]);
56
        }
57 7
        $note->resetUpdatedFields();
58 7
        return $note;
59
    }
60
61
}
62