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

TemplatesBlocks::renderFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 1
eloc 13
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: TemplatesBlocks.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TemplatesBlocks.
27
 */
28
class TemplatesBlocks 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 TemplatesBlocks
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
    */
71
    /**
72
     * @param $module
73
     * @param $table
74
     */
75
    public function write($module, $table)
76
    {
77
        $this->setModule($module);
78
        $this->setTable($table);
79
    }
80
81
    /*
82
    *  @private function getTemplatesBlocksTableThead
83
    *  @param string $moduleDirname
84
    *  @param string $table
85
    *  @param string $language
86
    */
87
    /**
88
     * @param $moduleDirname
89
     * @param $table
90
     * @param $language
91
     *
92
     * @return string
93
     */
94
    private function getTemplatesBlocksTableThead($tableId, $tableMid, $language)
95
    {
96
        $th = '';
97
        $fields = $this->getTableFields($tableMid, $tableId);
98
        foreach (array_keys($fields) as $f) {
99
            $fieldName = $fields[$f]->getVar('field_name');
100
            $stuFieldName = strtoupper($fieldName);
101
            $lang = $this->htmlcode->getSmartyConst($language, $stuFieldName);
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...
102
            $th    .= $this->htmlcode->getHtmlTableHead($lang, 'center').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTableHead 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...
103
        }
104
        $tr = $this->htmlcode->getHtmlTableRow($th, 'head').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTableRow 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...
105
106
        return $this->htmlcode->getHtmlTableThead($tr).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTableThead 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...
107
    }
108
109
    /*
110
    *  @private function getTemplatesBlocksTableTbody
111
    *  @param string $moduleDirname
112
    *  @param string $table
113
    *  @param string $language
114
    */
115
    /**
116
     * @param $moduleDirname
117
     * @param $table
118
     * @param $language
119
     *
120
     * @return string
121
     */
122
    private function getTemplatesBlocksTableTbody($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $tableAutoincrement, $language)
0 ignored issues
show
Unused Code introduced by
The parameter $language is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
123
    {
124
        $td = '';
125
        if (1 == $tableAutoincrement) {
126
            $double = $this->htmlcode->getSmartyDoubleVar($tableSoleName, 'id');
0 ignored issues
show
Bug introduced by
The method getSmartyDoubleVar 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
            $td    .= $this->htmlcode->getHtmlTag('td', array('class' => 'center'), $double).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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
        }
129
        $fields = $this->getTableFields($tableMid, $tableId);
130
        foreach (array_keys($fields) as $f) {
131
            $fieldName = $fields[$f]->getVar('field_name');
132
            $fieldElement = $fields[$f]->getVar('field_element');
133
            $rpFieldName = $this->tdmcfile->getRightString($fieldName);
0 ignored issues
show
Bug introduced by
The method getRightString 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...
134
            if (0 == $f) {
135
                $fieldId = $fieldName;
136
            }
137
            if (1 == $fields[$f]->getVar('field_inlist')) {
138
                switch ($fieldElement) {
139
                    case 9:
140
                        // This is to be reviewed, as it was initially to style = "backgroung-color: #"
141
                        // Now with HTML5 is not supported inline style in the parameters of the HTML tag
142
                        // Old code was <span style="background-color: #<{\$list.{$rpFieldName}}>;">...
143
                        $double = $this->htmlcode->getSmartyDoubleVar($tableSoleName, $rpFieldName);
0 ignored issues
show
Bug introduced by
The method getSmartyDoubleVar 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...
144
                        $span = $this->htmlcode->getHtmlTag('span', array(), $double);
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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
                        $td .= $this->htmlcode->getHtmlTag('td', array('class' => 'center'), $span).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
146
                        /*$ret .= <<<EOT
147
                    <td class="center"><span style="background-color: #<{\$list.{$rpFieldName}}>;">&nbsp;&nbsp;&nbsp;&nbsp;</span></td>\n
148
EOT;*/
149
                        break;
150
                    case 10:
151
                        $src = $this->htmlcode->getSmartyNoSimbol('xoModuleIcons32');
0 ignored issues
show
Bug introduced by
The method getSmartyNoSimbol 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...
152
                        $src .= $this->htmlcode->getSmartyDoubleVar($tableSoleName, $rpFieldName);
0 ignored issues
show
Bug introduced by
The method getSmartyDoubleVar 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...
153
                        $img = $this->htmlcode->getHtmlTag('img', array('src' => $src, 'alt' => $tableName), '', false);
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
154
                        $td  .= $this->htmlcode->getHtmlTag('td', array('class' => 'center'), $img).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
155
                        break;
156
                    case 13:
157
                        $single = $this->htmlcode->getSmartySingleVar($moduleDirname.'_upload_url');
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...
158
                        $double = $this->htmlcode->getSmartyDoubleVar($tableSoleName, $rpFieldName);
0 ignored issues
show
Bug introduced by
The method getSmartyDoubleVar 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...
159
                        $img = $this->htmlcode->getHtmlTag('img', array('src' => $single."/images/{$tableName}/".$double, 'alt' => $tableName), '', false);
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
160
                        $td    .= $this->htmlcode->getHtmlTag('td', array('class' => 'center'), $img).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
161
                        break;
162
                    default:
163
                        if (0 != $f) {
164
                            $double = $this->htmlcode->getSmartyDoubleVar($tableSoleName, $rpFieldName);
0 ignored issues
show
Bug introduced by
The method getSmartyDoubleVar 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...
165
                            $td    .= $this->htmlcode->getHtmlTag('td', array('class' => 'center'), $double).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
166
                        }
167
                        break;
168
                }
169
            }
170
        }
171
        $lang = $this->htmlcode->getSmartyConst('', '_EDIT');
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...
172
        $double = $this->htmlcode->getSmartyDoubleVar($tableSoleName, 'id');
0 ignored issues
show
Bug introduced by
The method getSmartyDoubleVar 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...
173
        $src = $this->htmlcode->getSmartyNoSimbol('xoModuleIcons32 edit.png');
0 ignored issues
show
Bug introduced by
The method getSmartyNoSimbol 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...
174
        $img = $this->htmlcode->getHtmlTag('img', array('src' => $src, 'alt' => $tableName), '', false);
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
175
        $anchor = $this->htmlcode->getHtmlTag('a', array('href' => $tableName.".php?op=edit&amp;{$fieldId}=".$double, 'title' => $lang), $img).PHP_EOL;
0 ignored issues
show
Bug introduced by
The variable $fieldId does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The method getHtmlTag 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...
176
        $lang = $this->htmlcode->getSmartyConst('', '_DELETE');
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...
177
        $double = $this->htmlcode->getSmartyDoubleVar($tableSoleName, 'id');
0 ignored issues
show
Bug introduced by
The method getSmartyDoubleVar 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...
178
        $src = $this->htmlcode->getSmartyNoSimbol('xoModuleIcons32 delete.png');
0 ignored issues
show
Bug introduced by
The method getSmartyNoSimbol 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...
179
        $img = $this->htmlcode->getHtmlTag('img', array('src' => $src.$double, 'alt' => $tableName), '', false);
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
180
        $anchor .= $this->htmlcode->getHtmlTag('a', array('href' => $tableName.".php?op=delete&amp;{$fieldId}=".$double, 'title' => $lang), $img).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
181
        $td     .= $this->htmlcode->getHtmlTag('td', array('class' => 'center'), "\n".$anchor).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
182
        $cycle = $this->htmlcode->getSmartyNoSimbol('cycle values="odd, even"');
0 ignored issues
show
Bug introduced by
The method getSmartyNoSimbol 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...
183
        $tr = $this->htmlcode->getHtmlTag('tr', array('class' => $cycle), $td).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
184
        $foreach = $this->htmlcode->getSmartyForeach($tableSoleName, $tableName.'_list', $tr).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getSmartyForeach 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...
185
        $tbody = $this->htmlcode->getHtmlTag('tbody', array(), $foreach).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
186
187
        return $this->htmlcode->getSmartyConditions($tableName.'_count', '', '', $tbody).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...
188
    }
189
190
    /*
191
    *  @private function getTemplatesBlocksTfoot
192
    *  @param string $moduleDirname
193
    *  @param string $table
194
    *  @param string $language
195
    */
196
    /**
197
     * @param $moduleDirname
198
     * @param $table
199
     * @param $language
200
     *
201
     * @return string
202
     */
203
    private function getTemplatesBlocksTableTfoot()
204
    {
205
        $td = $this->htmlcode->getHtmlTag('td', array(), '&nbsp;').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
206
        $tr = $this->htmlcode->getHtmlTag('tr', array(), $td).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
207
208
        return $this->htmlcode->getHtmlTag('tfoot', array(), $tr).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag 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...
209
    }
210
211
    /*
212
    *  @private function getTemplatesBlocksTable
213
    *  @param string $moduleDirname
214
    *  @param string $tableName
215
    *  @param string $fields
0 ignored issues
show
Bug introduced by
There is no parameter named $fields. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
216
    *  @param string $language
217
    *  @return string
218
    */
219
    private function getTemplatesBlocksTable($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $tableAutoincrement, $language)
220
    {
221
        $tbody = $this->getTemplatesBlocksTableThead($tableId, $tableMid, $language);
222
        $tbody .= $this->getTemplatesBlocksTableTbody($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $tableAutoincrement, $language);
223
        $tbody .= $this->getTemplatesBlocksTableTfoot();
224
        $single = $this->htmlcode->getSmartySingleVar('table_type');
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...
225
226
        return $this->htmlcode->getHtmlTable($tbody, 'table table-'.$single).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTable 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...
227
    }
228
229
    /*
230
    *  @public function renderFile
231
    *  @param string $filename
232
    */
233
    /**
234
     * @param $filename
235
     *
236
     * @return bool|string
237
     */
238
    public function renderFile($filename)
239
    {
240
        $module = $this->getModule();
241
        $table = $this->getTable();
242
        $moduleDirname = $module->getVar('mod_dirname');
243
        $tableId = $table->getVar('table_id');
244
        $tableMid = $table->getVar('table_mid');
245
        $tableName = $table->getVar('table_name');
246
        $tableSoleName = $table->getVar('table_solename');
247
        $tableAutoincrement = $table->getVar('table_autoincrement');
248
        $language = $this->getLanguage($moduleDirname, 'MB');
249
        $content = $this->getTemplatesBlocksTable($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $tableAutoincrement, $language);
250
        //
251
        $this->tdmcfile->create($moduleDirname, 'templates/blocks', $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...
252
253
        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...
254
    }
255
}
256