Passed
Push — master ( 2acd76...c4e965 )
by Simon
03:34
created

PrivacyStatement::main()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 20
rs 9.9
cc 4
nc 3
nop 0
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 * ACC Development Team. Please see team.json for a list of contributors.     *
5
 *                                                                            *
6
 * This is free and unencumbered software released into the public domain.    *
7
 * Please see LICENSE.md for the full licencing statement.                    *
8
 ******************************************************************************/
9
10
namespace Waca\Fragments;
11
12
use Waca\Helpers\MarkdownRenderingHelper;
13
14
trait PrivacyStatement
15
{
16
    protected abstract function assign($name, $value);
17
    protected abstract function templatePath();
18
    protected abstract function setTemplate($name);
19
    protected abstract function skipAlerts();
20
    protected abstract function getSiteConfiguration();
21
22
    protected function main()
23
    {
24
        $path = $this->getSiteConfiguration()->getPrivacyStatementPath();
25
26
        if ($path == null || !file_exists($path)) {
27
            if (!headers_sent()) {
28
                header('HTTP/1.1 404 Not Found');
29
            }
30
31
            $this->skipAlerts();
32
            $this->setTemplate('404.tpl');
33
            return;
34
        }
35
36
        $markdown = file_get_contents($path);
37
38
        $renderer = new MarkdownRenderingHelper();
39
        $this->assign('content', $renderer->doRender($markdown));
40
41
        $this->setTemplate($this->templatePath());
42
    }
43
}