IncludeComments   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 90
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A renderCommentsIncludes() 0 11 1
A renderCommentsNew() 0 26 3
A getInstance() 0 8 2
A write() 0 4 1
1
<?php namespace XoopsModules\Tdmcreate\Files\Includes;
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: IncludeComments.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class IncludeComments.
30
 */
31
class IncludeComments 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 IncludeComments
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 $table
61
     */
62
    public function write($module, $table)
63
    {
64
        $this->setModule($module);
65
        $this->setTable($table);
66
    }
67
68
    /**
69
     *  @public function getCommentsIncludes
70
     *  @param string $module
71
     *  @param string $filename
72
     *
73
     * @return bool|string
74
     */
75
    public function renderCommentsIncludes($module, $filename)
76
    {
77
        $moduleDirname = $module->getVar('mod_dirname');
78
        $content = $this->getHeaderFilesComments($module, $filename . '.php');
79
        $content .= <<<EOT
80
include_once __DIR__ . '/../../../mainfile.php';
81
include_once XOOPS_ROOT_PATH.'/include/{$filename}.php';
82
EOT;
83
        $this->create($moduleDirname, 'include', $filename . '.php', $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
84
85
        return $this->render();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->render() targeting XoopsModules\Tdmcreate\F...AbstractClass::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
86
    }
87
88
    /**
89
     *  @public function getCommentsNew
90
     *  @param string $module
91
     *  @param string $filename
92
     *
93
     * @return bool|string
94
     */
95
    public function renderCommentsNew($module, $filename)
96
    {
97
        $table = $this->getTable();
98
        $moduleDirname = mb_strtolower($module->getVar('mod_dirname'));
99
        $tableName = $table->getVar('table_name');
100
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
101
        foreach (array_keys($fields) as $f) {
102
            if (1 == $fields[$f]->getVar('field_main')) {
103
                $fpmf = $fields[$f]->getVar('field_name');
104
            }
105
        }
106
        $content = $this->getHeaderFilesComments($module, $filename . '.php');
107
        $content .= <<<EOT
108
include __DIR__ . '/../../../mainfile.php';
109
include_once XOOPS_ROOT_PATH.'/modules/{$moduleDirname}/class/{$tableName}.php';
110
\$com_itemid = isset(\$_REQUEST['com_itemid']) ? (int)\$_REQUEST['com_itemid'] : 0;
111
if (\$com_itemid > 0) {
112
    \${$tableName}Handler = xoops_getModuleHandler('{$tableName}', '{$moduleDirname}');
113
    \${$tableName} = \${$tableName}handler->get(\$com_itemid);
114
    \$com_replytitle = \${$tableName}->getVar('{$fpmf}');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fpmf does not seem to be defined for all execution paths leading up to this point.
Loading history...
115
    include XOOPS_ROOT_PATH.'/include/{$filename}.php';
116
}
117
EOT;
118
        $this->create($moduleDirname, 'include', $filename . '.php', $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
119
120
        return $this->renderFile();
121
    }
122
123
    /**
124
    *  @public function render
125
    *  @param null
126
    */
127
    /*public function render() {
128
        $module = $this->getModule();
129
        $table = $this->getTable();
130
        $filename = $this->getFileName();
131
        $moduleDirname = $module->getVar('mod_dirname');
132
133
        $content = $this->getHeaderFilesComments($module, $filename);
134
        switch($filename) {
135
            case 'comment_edit.php':
136
                $content .= $this->getCommentsIncludes('comment_edit');
137
                $this->create($moduleDirname, 'include', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
138
                return $this->render();
139
            break;
140
            case 'comment_delete.php':
141
                $content .= $this->getCommentsIncludes('comment_delete');
142
                $this->create($moduleDirname, 'include', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
143
                return $this->render();
144
            break;
145
            case 'comment_post.php':
146
                $content .= $this->getCommentsIncludes('comment_post');
147
                $this->create($moduleDirname, 'include', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
148
                return $this->render();
149
            break;
150
            case 'comment_reply.php':
151
                $content .= $this->getCommentsIncludes('comment_reply');
152
                $this->create($moduleDirname, 'include', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
153
                return $this->render();
154
            break;
155
            case 'comment_new.php':
156
                $content .= $this->getCommentsNew($moduleDirname, 'comment_new');
157
                $this->create($moduleDirname, 'include', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
158
                return $this->render();
159
            break;
160
        }
161
    }*/
162
}
163