Passed
Push — master ( 11479c...895137 )
by Andreas
25:55
created

initialize_index_article()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.0054

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 11
ccs 8
cts 9
cp 0.8889
crap 2.0054
rs 10
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
        if (!$page->create()) {
36
            throw new midcom_error('Failed to create index article: ' . midcom_connection::get_error_string());
37
        }
38 2
        return $page;
39
    }
40
}
41