Completed
Push — master ( 4e5fd8...358131 )
by Gino
08:01 queued 03:42
created

TDMCreateMoreFiles::getMoreFilesFileText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 28 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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: TDMCreateMoreFiles.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') || die('Restricted access');
25
/**
26
 * Class TDMCreateMoreFiles.
27
 */
28
class TDMCreateMoreFiles 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
    private $folder;
32
    //
33
    private $extension;
34
    /*
35
    *  @public function constructor
36
    *  @param null
37
    */
38
    /**
39
     *
40
     */
41
    public function __construct()
42
    {
43
        parent::__construct();
44
    }
45
46
    /*
47
    *  @static function &getInstance
48
    *  @param null
49
    */
50
    /**
51
     * @return TDMCreateMoreFiles
52
     */
53
    public static function &getInstance()
54
    {
55
        static $instance = false;
56
        if (!$instance) {
57
            $instance = new self();
58
        }
59
60
        return $instance;
61
    }
62
63
    /*
64
    *  @public function write
65
    *  @param string $module
66
    *  @param string $filename
67
    */
68
    /**
69
     * @param $module
70
     * @param $filename
71
     *
72
     * @return string
73
     */
74 View Code Duplication
    public function write($module, $filename, $folder, $extension)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $this->setModule($module);
77
        $this->extension = $extension;
78
        $this->setFileName($filename.'.'.$extension);
79
        if (strstr($folder, 'user')) {
80
            $this->folder = '/';
81
        } else {
82
            $this->folder = $folder;
83
        }
84
    }
85
86
    /*
87
    *  @private function getMoreFilesPhp
88
    *  @param $header
89
    */
90
    /**
91
     * @param $header
92
     *
93
     * @return string
94
     */
95
    private function getMoreFilesPhp($header)
96
    {
97
        $ret = <<<EOT
98
<?php
99
{$header}\n
100
EOT;
101
        $ret .= $this->getInclude();
102
        $ret .= $this->getInclude('footer');
103
104
        return $ret;
105
    }
106
107
    /*
108
    *  @private function getMoreFilesTpl
109
    *  @param $header
110
    */
111
    /**
112
     * @param $header
113
     *
114
     * @return string
115
     */
116
    private function getMoreFilesTpl()
117
    {
118
        $ret = <<<EOT
119
<div class="panel">
120
	Pleace! put your template code here
121
</div>\n
122
EOT;
123
124
        return $ret;
125
    }
126
127
    /*
128
    *  @private function getMoreFilesHtml
129
    *  @param $header
130
    */
131
    /**
132
     * @param $header
133
     *
134
     * @return string
135
     */
136
    private function getMoreFilesHtml()
137
    {
138
        $ret = <<<EOT
139
<div class="panel">
140
	Pleace! put your Html code here
141
</div>\n
142
EOT;
143
144
        return $ret;
145
    }
146
147
    /*
148
    *  @private function getMoreFilesText
149
    *  @param null
150
    */
151
    /**
152
     * @param null
153
     *
154
     * @return string
155
     */
156
    private function getMoreFilesText()
157
    {
158
        $ret = <<<EOT
159
# Pleace! put your text code here\n
160
EOT;
161
162
        return $ret;
163
    }
164
165
    /*
166
    *  @private function getMoreFilesSql
167
    *  @param null
168
    */
169
    /**
170
     * @param null
171
     *
172
     * @return string
173
     */
174
    private function getMoreFilesSql()
175
    {
176
        $ret = <<<EOT
177
# Pleace! put your sql code here\n
178
EOT;
179
180
        return $ret;
181
    }
182
183
    /*
184
    *  @private function getMoreFilesCss
185
    *  @param $header
186
    */
187
    /**
188
     * @param $header
189
     *
190
     * @return string
191
     */
192
    private function getMoreFilesCss($header)
193
    {
194
        $ret = <<<EOT
195
@charset "UTF-8";
196
{$header}\n\nPleace! put your sql code here\n
197
EOT;
198
199
        return $ret;
200
    }
201
202
    /*
203
    *  @private function getMoreFilesDefault
204
    *  @param null
205
    */
206
    /**
207
     * @param null
208
     *
209
     * @return string
210
     */
211
    private function getMoreFilesDefault()
212
    {
213
        $ret = <<<EOT
214
\n
215
EOT;
216
217
        return $ret;
218
    }
219
220
    /*
221
    *  @public function render
222
    *  @param string $filename
223
    */
224
    /**
225
     * @param $filename
226
     *
227
     * @return bool|string
228
     */
229
    public function render()
230
    {
231
        $module = $this->getModule();
232
        $filename = $this->getFileName();
233
        $moduleDirname = $module->getVar('mod_dirname');
234
        $header = $this->getHeaderFilesComments($module, $filename, 0);
235
        switch ($this->extension) {
236
            case 'php':
237
                $content = $this->getMoreFilesPhp($header);
238
                break;
239
            case 'tpl':
240
                $content = $this->getMoreFilesTpl();
241
                break;
242
            case 'html':
243
                $content = $this->getMoreFilesHtml();
244
                break;
245
            case 'text':
246
                $content = $this->getMoreFilesText();
247
                break;
248
            case 'sql':
249
                $content = $this->getMoreFilesSql();
250
                break;
251
            case 'css':
252
                $content = $this->getMoreFilesCss($header);
253
                break;
254
            default:
255
                $content = $this->getMoreFilesDefault();
256
                break;
257
        }
258
259
        $this->create($moduleDirname, $this->folder, $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
260
261
        return $this->renderFile();
262
    }
263
}
264