Failed Conditions
Push — rbac ( be68b4...52c28b )
by Michael
03:11
created

TemplateOutput   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 31
c 2
b 0
f 0
dl 0
loc 85
ccs 0
cts 39
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpSmarty() 0 33 1
A assign() 0 3 1
A fetchTemplate() 0 5 1
A setTailScript() 0 3 1
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Fragments;
10
11
use Smarty;
12
use Waca\DataObjects\User;
13
use Waca\Environment;
14
use Waca\SiteConfiguration;
0 ignored issues
show
Bug introduced by
The type Waca\SiteConfiguration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
trait TemplateOutput
17
{
18
    /** @var Smarty */
19
    private $smarty;
20
    /** @var string Extra JavaScript to include at the end of the page's execution */
21
    private $tailScript;
22
23
    /**
24
     * @return SiteConfiguration
25
     */
26
    protected abstract function getSiteConfiguration();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
27
28
    /**
29
     * Include extra JavaScript at the end of the page's execution
30
     *
31
     * @param $script string JavaScript to include at the end of the page
32
     */
33
    final protected function setTailScript($script)
34
    {
35
        $this->tailScript = $script;
36
    }
0 ignored issues
show
Coding Style introduced by
Expected //end setTailScript()
Loading history...
37
38
    /**
39
     * Assigns a Smarty variable
40
     *
41
     * @param  array|string $name  the template variable name(s)
42
     * @param  mixed        $value the value to assign
43
     */
44
    final protected function assign($name, $value)
45
    {
46
        $this->smarty->assign($name, $value);
47
    }
0 ignored issues
show
Coding Style introduced by
Expected //end assign()
Loading history...
48
49
    /**
50
     * Sets up the variables used by the main Smarty base template.
51
     *
52
     * This list is getting kinda long.
53
     */
54
    final protected function setUpSmarty()
55
    {
56
        $this->smarty = new Smarty();
57
        $this->smarty->addPluginsDir($this->getSiteConfiguration()->getFilePath() . '/smarty-plugins');
58
59
        $this->assign('currentUser', User::getCommunity());
60
        $this->assign('loggedIn', false);
61
        $this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl());
62
        $this->assign('mediawikiScriptPath', $this->getSiteConfiguration()->getMediawikiScriptPath());
63
64
        $this->assign('siteNoticeText', '');
65
        $this->assign('toolversion', Environment::getToolVersion());
66
67
        // default these
68
        $this->assign('onlineusers', array());
69
        $this->assign('typeAheadBlock', '');
70
        $this->assign('extraJs', array());
71
        $this->assign('extraCss', array());
72
73
        // nav menu access control
74
        $this->assign('nav__canRequests', false);
75
        $this->assign('nav__canLogs', false);
76
        $this->assign('nav__canUsers', false);
77
        $this->assign('nav__canSearch', false);
78
        $this->assign('nav__canStats', false);
79
        $this->assign('nav__canBan', false);
80
        $this->assign('nav__canEmailMgmt', false);
81
        $this->assign('nav__canWelcomeMgmt', false);
82
        $this->assign('nav__canSiteNoticeMgmt', false);
83
        $this->assign('nav__canUserMgmt', false);
84
        $this->assign('nav__canViewRequest', false);
85
86
        $this->assign('page', $this);
87
    }
0 ignored issues
show
Coding Style introduced by
Expected //end setUpSmarty()
Loading history...
88
89
    /**
90
     * Fetches a rendered Smarty template
91
     *
92
     * @param $template string Template file path, relative to /templates/
93
     *
94
     * @return string Templated HTML
95
     */
96
    final protected function fetchTemplate($template)
97
    {
98
        $this->assign("tailScript", $this->tailScript);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal tailScript does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
99
100
        return $this->smarty->fetch($template);
101
    }
0 ignored issues
show
Coding Style introduced by
Expected //end fetchTemplate()
Loading history...
102
}
103