Passed
Push — master ( 625fac...5ee9cd )
by Andreas
25:03 queued 06:55
created

initialize_index_article()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.004

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 12
ccs 9
cts 10
cp 0.9
crap 2.004
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package net.nemein.wiki
4
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
6
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
7
 */
8
9
/**
10
 * Handler addons
11
 *
12
 * @package net.nemein.wiki
13
 */
14
trait net_nemein_wiki_handler
15
{
16 3
    public function load_page(string $wikiword) : net_nemein_wiki_wikipage
17
    {
18 3
        $qb = net_nemein_wiki_wikipage::new_query_builder();
19 3
        $qb->add_constraint('topic', '=', $this->_topic->id);
0 ignored issues
show
Bug introduced by
The property _topic does not exist on net_nemein_wiki_handler. Did you mean topic?
Loading history...
20 3
        $qb->add_constraint('name', '=', $wikiword);
21
22 3
        if ($result = $qb->execute()) {
23 3
            return $result[0];
24
        }
25
        throw new midcom_error_notfound('The page "' . $wikiword . '" could not be found.');
26
    }
27
28 2
    public function initialize_index_article(midcom_db_topic $topic) : net_nemein_wiki_wikipage
29
    {
30 2
        $page = new net_nemein_wiki_wikipage();
31 2
        $page->topic = $topic->id;
32 2
        $page->name = 'index';
33 2
        $page->title = $topic->extra;
34 2
        $page->content = $this->_l10n->get('wiki default page content');
35 2
        $page->author = midcom_connection::get_user();
0 ignored issues
show
Bug Best Practice introduced by
The property author does not exist on net_nemein_wiki_wikipage. Since you implemented __set, consider adding a @property annotation.
Loading history...
36 2
        if (!$page->create()) {
37
            throw new midcom_error('Failed to create index article: ' . midcom_connection::get_error_string());
38
        }
39 2
        return $page;
40
    }
41
}
42