Passed
Push — master ( 0f0f99...fb91d6 )
by Michael
17s
created

TemplatesUserSubmit::renderFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 11
nc 1
nop 1
1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: TemplatesUserSubmit.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TemplatesUserSubmit.
27
 */
28
class TemplatesUserSubmit extends TDMCreateFile
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
29
{
30
    /*
31
    * @var string
32
    */
33
    private $tdmcfile = null;
34
35
    /*
36
    *  @public function constructor
37
    *  @param null
38
    */
39
    /**
40
     *
41
     */
42
    public function __construct()
43
    {
44
        parent::__construct();
45
        $this->tdmcfile = TDMCreateFile::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateFile::getInstance() of type object<TDMCreateFile> is incompatible with the declared type string of property $tdmcfile.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
        $this->htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateHtmlSmartyCodes::getInstance() of type object<TDMCreateHtmlSmartyCodes> is incompatible with the declared type string of property $htmlcode.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
47
    }
48
49
    /*
50
    *  @static function &getInstance
51
    *  @param null
52
    */
53
    /**
54
     * @return TemplatesUserSubmit
55
     */
56
    public static function &getInstance()
57
    {
58
        static $instance = false;
59
        if (!$instance) {
60
            $instance = new self();
61
        }
62
63
        return $instance;
64
    }
65
66
    /*
67
    *  @public function write
68
    *  @param string $module
69
    *  @param string $table
70
    *  @param string $filename
71
    */
72
    /**
73
     * @param $module
74
     * @param $table
75
     */
76
    public function write($module, $table)
77
    {
78
        $this->setModule($module);
79
        $this->setTable($table);
80
    }
81
82
    /*
83
    *  @private function getTemplatesUserSubmitHeader
84
    *  @param string $moduleDirname
85
    *  @param string $table
86
    *  @param string $language
87
    */
88
    /**
89
     * @param $moduleDirname
90
     * @param $table
91
     * @param $language
92
     *
93
     * @return string
94
     */
95
    private function getTemplatesUserSubmitHeader($moduleDirname)
96
    {
97
        return $this->htmlcode->getSmartyIncludeFile($moduleDirname, 'header').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getSmartyIncludeFile cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
98
    }
99
100
    /*
101
    *  @private function getTemplatesUserSubmit
102
    *  @param string $moduleDirname
103
    *  @param string $language
104
    */
105
    /**
106
     * @param $moduleDirname
107
     * @param $language
108
     *
109
     * @return string
110
     */
111
    private function getTemplatesUserSubmit($moduleDirname, $language)
112
    {
113
        $const = $this->htmlcode->getSmartyConst($language, 'SUBMIT_SUBMITONCE');
0 ignored issues
show
Bug introduced by
The method getSmartyConst cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
114
        $li = $this->htmlcode->getHtmlLi($const).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlLi cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
115
        $const = $this->htmlcode->getSmartyConst($language, 'SUBMIT_ALLPENDING');
0 ignored issues
show
Bug introduced by
The method getSmartyConst cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
116
        $li    .= $this->htmlcode->getHtmlLi($const).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlLi cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
117
        $const = $this->htmlcode->getSmartyConst($language, 'SUBMIT_DONTABUSE');
0 ignored issues
show
Bug introduced by
The method getSmartyConst cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
118
        $li    .= $this->htmlcode->getHtmlLi($const).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlLi cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
119
        $const = $this->htmlcode->getSmartyConst($language, 'SUBMIT_TAKEDAYS');
0 ignored issues
show
Bug introduced by
The method getSmartyConst cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
120
        $li    .= $this->htmlcode->getHtmlLi($const).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlLi cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
121
        $ul = $this->htmlcode->getHtmlUl($li).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlUl cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
122
        $ret = $this->htmlcode->getHtmlDiv($ul, $moduleDirname.'-tips').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlDiv cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
123
124
        $single = $this->htmlcode->getSmartySingleVar('message_error').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getSmartySingleVar cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
125
        $divError = $this->htmlcode->getHtmlDiv($single, 'errorMsg').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlDiv cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
126
        $ret   .= $this->htmlcode->getSmartyConditions('message_error', ' != ', '\'\'', $divError).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getSmartyConditions cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
127
        $single = $this->htmlcode->getSmartySingleVar('form').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getSmartySingleVar cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
128
        $ret   .= $this->htmlcode->getHtmlDiv($single, $moduleDirname.'-submitform').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlDiv cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
129
130
        return $ret;
131
    }
132
133
    /*
134
    *  @private function getTemplatesUserSubmitFooter
135
    *  @param string $moduleDirname
136
    */
137
    /**
138
     * @param $moduleDirname
139
     *
140
     * @return string
141
     */
142
    private function getTemplatesUserSubmitFooter($moduleDirname)
143
    {
144
        return $this->htmlcode->getSmartyIncludeFile($moduleDirname, 'footer');
0 ignored issues
show
Bug introduced by
The method getSmartyIncludeFile cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
145
    }
146
147
    /*
148
    *  @public function renderFile
149
    *  @param string $filename
150
    */
151
    /**
152
     * @param $filename
153
     *
154
     * @return bool|string
155
     */
156
    public function renderFile($filename)
157
    {
158
        $module = $this->getModule();
159
        $table = $this->getTable();
160
        $moduleDirname = $module->getVar('mod_dirname');
161
        $tableFieldname = $table->getVar('table_fieldname');
0 ignored issues
show
Unused Code introduced by
$tableFieldname is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
162
        $language = $this->getLanguage($moduleDirname, 'MA');
163
        $content = $this->getTemplatesUserSubmitHeader($moduleDirname);
164
        $content       .= $this->getTemplatesUserSubmit($moduleDirname, $language);
165
        $content       .= $this->getTemplatesUserSubmitFooter($moduleDirname);
166
        //
167
        $this->tdmcfile->create($moduleDirname, 'templates', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
0 ignored issues
show
Bug introduced by
The method create cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
168
169
        return $this->tdmcfile->renderFile();
0 ignored issues
show
Bug introduced by
The method renderFile cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
170
    }
171
}
172