Failed Conditions
Pull Request — master (#965)
by Richard
06:10 queued 02:39
created

TemplateOutput::setUpSmarty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
c 1
b 0
f 0
dl 0
loc 51
ccs 0
cts 37
cp 0
rs 9.312
cc 1
nc 1
nop 0
crap 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 Smarty;
13
use Waca\DataObjects\User;
14
use Waca\Environment;
15
use Waca\SiteConfiguration;
16
17
trait TemplateOutput
18
{
19
    /** @var Smarty */
20
    private $smarty;
21
22
    /**
23
     * @return SiteConfiguration
24
     */
25
    protected abstract function getSiteConfiguration();
26
27
    /**
28
     * Assigns a Smarty variable
29
     *
30
     * @param  array|string $name  the template variable name(s)
31
     * @param  mixed        $value the value to assign
32
     */
33
    final protected function assign($name, $value)
34
    {
35
        $this->smarty->assign($name, $value);
36
    }
37
38
    /**
39
     * Sets up the variables used by the main Smarty base template.
40
     *
41
     * This list is getting kinda long.
42
     */
43
    final protected function setUpSmarty()
44
    {
45
        $this->smarty = new Smarty();
46
        $this->smarty->addPluginsDir($this->getSiteConfiguration()->getFilePath() . '/smarty-plugins');
47
        $this->registerPlugin('modifier', 'count', 'count');
0 ignored issues
show
Bug introduced by
It seems like registerPlugin() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        $this->/** @scrutinizer ignore-call */ 
48
               registerPlugin('modifier', 'count', 'count');
Loading history...
48
49
        $this->assign('currentUser', User::getCommunity());
50
        $this->assign('skin', 'auto');
51
        $this->assign('currentDomain', null);
52
        $this->assign('loggedIn', false);
53
        $this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl());
54
        $this->assign('resourceCacheEpoch', $this->getSiteConfiguration()->getResourceCacheEpoch());
55
56
        $this->assign('siteNoticeText', '');
57
        $this->assign('siteNoticeVersion', 0);
58
        $this->assign('siteNoticeState', 'd-none');
59
        $this->assign('toolversion', Environment::getToolVersion());
60
61
        // default these
62
        $this->assign('onlineusers', array());
63
        $this->assign('typeAheadBlock', '');
64
        $this->assign('extraJs', array());
65
66
        // nav menu access control
67
        $this->assign('nav__canRequests', false);
68
        $this->assign('nav__canLogs', false);
69
        $this->assign('nav__canUsers', false);
70
        $this->assign('nav__canSearch', false);
71
        $this->assign('nav__canStats', false);
72
        $this->assign('nav__canBan', false);
73
        $this->assign('nav__canEmailMgmt', false);
74
        $this->assign('nav__canWelcomeMgmt', false);
75
        $this->assign('nav__canSiteNoticeMgmt', false);
76
        $this->assign('nav__canUserMgmt', false);
77
        $this->assign('nav__canViewRequest', false);
78
        $this->assign('nav__canJobQueue', false);
79
        $this->assign('nav__canFlaggedComments', false);
80
        $this->assign('nav__canDomainMgmt', false);
81
        $this->assign('nav__canQueueMgmt', false);
82
        $this->assign('nav__canFormMgmt', false);
83
        $this->assign('nav__canErrorLog', false);
84
85
        // Navigation badges for concern areas.
86
        $this->assign("nav__numAdmin", 0);
87
        $this->assign("nav__numFlaggedComments", 0);
88
        $this->assign("nav__numJobQueueFailed", 0);
89
90
        // debug helpers
91
        $this->assign('showDebugCssBreakpoints', $this->getSiteConfiguration()->getDebuggingCssBreakpointsEnabled());
92
93
        $this->assign('page', $this);
94
    }
95
96
    /**
97
     * Fetches a rendered Smarty template
98
     *
99
     * @param $template string Template file path, relative to /templates/
100
     *
101
     * @return string Templated HTML
102
     */
103
    final protected function fetchTemplate($template)
104
    {
105
        return $this->smarty->fetch($template);
106
    }
107
}
108