AdminIndex::getAdminIndex()   B
last analyzed

Complexity

Conditions 8
Paths 16

Size

Total Lines 57
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 46
nc 16
nop 1
dl 0
loc 57
rs 7.9337
c 0
b 0
f 0

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 namespace XoopsModules\Tdmcreate\Files\Admin;
2
3
use XoopsModules\Tdmcreate;
4
use XoopsModules\Tdmcreate\Files;
5
6
/*
7
 You may not change or alter any portion of this comment or credits
8
 of supporting developers from this source code or any supporting source code
9
 which is considered copyrighted (c) material of the original comment or credit authors.
10
11
 This program is distributed in the hope that it will be useful,
12
 but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 */
15
/**
16
 * tdmcreate module.
17
 *
18
 * @copyright       XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
20
 *
21
 * @since           2.5.0
22
 *
23
 * @author          Txmod Xoops http://www.txmodxoops.org
24
 *
25
 * @version         $Id: AdminIndex.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class AdminIndex.
30
 */
31
class AdminIndex extends Files\CreateFile
32
{
33
    /**
34
     *  @public function constructor
35
     *  @param null
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
    }
41
42
    /**
43
     *  @static function getInstance
44
     *  @param null
45
     * @return AdminIndex
46
     */
47
    public static function getInstance()
48
    {
49
        static $instance = false;
50
        if (!$instance) {
51
            $instance = new self();
52
        }
53
54
        return $instance;
55
    }
56
57
    /**
58
     *  @public function write
59
     *  @param string $module
60
     *  @param mixed $tables
61
     *  @param string $filename
62
     */
63
    public function write($module, $tables, $filename)
64
    {
65
        $this->setModule($module);
66
        $this->setTables($tables);
67
        $this->setFileName($filename);
68
    }
69
70
    /**
71
     * @private function render
72
     * @param $module
73
     *
74
     * @return string
75
     */
76
    private function getAdminIndex($module)
77
    {
78
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
79
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
80
        $axc = Tdmcreate\Files\Admin\AdminXoopsCode::getInstance();
81
        $moduleDirname = $module->getVar('mod_dirname');
82
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
83
        $language = $this->getLanguage($moduleDirname, 'AM');
84
        $languageThereAre = $this->getLanguage($moduleDirname, 'AM', 'THEREARE_');
85
        $ret = $this->getInclude();
86
        $ret .= $pc->getPhpCodeCommentLine('Count elements');
87
        $tableName = null;
88
        foreach (array_keys($tables) as $i) {
89
            $tableName = $tables[$i]->getVar('table_name');
90
            $ucfTableName = ucfirst($tableName);
91
            $ret .= $xc->getXcEqualsOperator("\$count{$ucfTableName}", "\${$tableName}Handler->getCount()");
92
        }
93
        $ret .= $pc->getPhpCodeCommentLine('Template Index');
94
        $ret .= $axc->getAdminTemplateMain((string)$moduleDirname, 'index');
95
        $ret .= $pc->getPhpCodeCommentLine('InfoBox Statistics');
96
        $ret .= $axc->getAxcAddInfoBox($language . 'STATISTICS');
97
        $ret .= $pc->getPhpCodeCommentLine('Info elements');
98
        foreach (array_keys($tables) as $i) {
99
            $tableName = $tables[$i]->getVar('table_name');
100
            $tableInstall[] = $tables[$i]->getVar('table_install');
101
            $stuTableName = $languageThereAre . mb_strtoupper($tableName);
102
            $ucfTableName = ucfirst($tableName);
103
            $ret .= $axc->getAxcAddInfoBoxLine($language . 'STATISTICS', $stuTableName, "\$count{$ucfTableName}");
104
        }
105
106
        if (null === $tableName) {
107
            $ret .= $axc->getAxcAddInfoBoxLine($language . 'STATISTICS', 'No statistics', '0');
108
        }
109
        if (is_array($tables) && in_array(1, $tableInstall)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tableInstall seems to be defined by a foreach iteration on line 98. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
110
            $ret .= $pc->getPhpCodeCommentLine('Upload Folders');
111
            $ret .= $this->getSimpleString('$folder = array(');
112
            $stuModuleDirname = mb_strtoupper($moduleDirname);
113
            $ret .= $this->getSimpleString("\t{$stuModuleDirname}_UPLOAD_PATH,");
114
            foreach (array_keys($tables) as $i) {
115
                $tableName = $tables[$i]->getVar('table_name');
116
                if (1 == $tables[$i]->getVar('table_install')) {
117
                    $ret .= $this->getSimpleString("\t{$stuModuleDirname}_UPLOAD_PATH . '/{$tableName}/',");
118
                }
119
            }
120
            $ret .= $this->getSimpleString(');');
121
            $ret .= $pc->getPhpCodeCommentLine('Uploads Folders Created');
122
            $boxLine = $axc->getAxcAddConfigBoxLine('$folder[$i]', 'folder', '', "\t");
123
            $boxLine .= $axc->getAxcAddConfigBoxLine("array(\$folder[\$i], '777')", 'chmod', '', "\t");
124
            $ret .= $pc->getPhpCodeForeach('folder', true, false, 'i', $boxLine, '') . PHP_EOL;
125
        }
126
        $ret .= $pc->getPhpCodeCommentLine('Render Index');
127
        $ret .= $xc->getXcTplAssign('navigation', "\$adminObject->displayNavigation('index.php')");
128
        $ret .= $xc->getXcTplAssign('index', '$adminObject->displayIndex()');
129
130
        $ret .= $this->getInclude('footer');
131
132
        return $ret;
133
    }
134
135
    /**
136
     *  @public function render
137
     *  @param null
138
     * @return bool|string
139
     */
140
    public function render()
141
    {
142
        $module = $this->getModule();
143
        $moduleDirname = $module->getVar('mod_dirname');
144
        $filename = $this->getFileName();
145
        $content = $this->getHeaderFilesComments($module, $filename);
146
        $content .= $this->getAdminIndex($module);
147
148
        $this->create($moduleDirname, 'admin', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
149
150
        return $this->renderFile();
151
    }
152
}
153