Passed
Push — master ( 0cff9c...dfbbd0 )
by Goffy
14:51
created

CreatePhpCode::getPhpCodeConditions()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 20
nc 6
nop 7
dl 0
loc 28
rs 8.6666
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Modulebuilder\Files;
4
5
use XoopsModules\Modulebuilder;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
/**
17
 * modulebuilder module.
18
 *
19
 * @copyright       XOOPS Project (https://xoops.org)
20
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
21
 *
22
 * @since           2.5.0
23
 *
24
 * @author          Txmod Xoops http://www.txmodxoops.org
25
 *
26
 */
27
28
/**
29
 * Class CreatePhpCode.
30
 */
31
class CreatePhpCode
32
{
33
    /**
34
     * @static function getInstance
35
     * @param null
36
     * @return CreatePhpCode
37
     */
38
    public static function getInstance()
39
    {
40
        static $instance = false;
41
        if (!$instance) {
42
            $instance = new self();
43
        }
44
45
        return $instance;
46
    }
47
48
    /**
49
     * @public function getPhpCodeCommentLine
50
     * @param        $comment
51
     * @param        $var
52
     * @param string $t
53
     * @param string $n
54
     * @return string
55
     */
56
    public function getPhpCodeCommentLine($comment = null, $var = null, $t = '', $n = "\n")
57
    {
58
        $value = !empty($var) ? ' ' . $var : '';
59
        $ret   = "{$t}// {$comment}{$value}{$n}";
60
61
        return $ret;
62
    }
63
64
    /**
65
     * @public function getPhpCodeCommentMultiLine
66
     * @param array  $multiLine
67
     *
68
     * @param string $t
69
     * @return string
70
     */
71
    public function getPhpCodeCommentMultiLine($multiLine = [], $t = '')
72
    {
73
        $values = !empty($multiLine) ? $multiLine : [];
74
        $ret    = "\n{$t}/**\n";
75
        foreach ($values as $string => $value) {
76
            if ('' === $string && '' === $value) {
77
                $ret .= "{$t} *\n";
78
            } else {
79
                $ret .= "{$t} * {$string} {$value}\n";
80
            }
81
        }
82
        $ret .= "{$t} */\n";
83
84
        return $ret;
85
    }
86
87
    /**
88
     * @public function getPhpCodeDefine
89
     * @param $left
90
     * @param $right
91
     *
92
     * @param string $t
93
     * @param bool $leftstr
94
     * @return string
95
     */
96
    public function getPhpCodeDefine($left, $right, $t = '', $leftstr = true)
97
    {
98
        $ret = "{$t}define(";
99
        if ($leftstr) {
100
            $ret .= "'{$left}'";
101
        } else {
102
            $ret .= "{$left}";
103
        }
104
        $ret .= ", {$right});\n";
105
        return $ret;
106
    }
107
108
    /**
109
     * @public function getPhpCodeDefine
110
     * @param $left
111
     * @param $right
112
     *
113
     * @return string
114
     */
115
    public function getPhpCodeDefined($left = 'XOOPS_ROOT_PATH', $right = 'Restricted access')
116
    {
117
        return "defined('{$left}') || die('{$right}');\n";
118
    }
119
120
    /**
121
     * @public function getPhpCodeGlobals
122
     * @param $var
123
     * @param $value
124
     *
125
     * @return string
126
     */
127
    public function getPhpCodeGlobals($var, $value = '')
128
    {
129
        if ('' != $value) {
130
            $ret = "\$GLOBALS['{$var}'] = \${$value};\n";
131
        } else {
132
            $ret = "\$GLOBALS['{$var}']";
133
        }
134
135
        return $ret;
136
    }
137
138
    /**
139
     * @public function getPhpCodeGlobalsVariables
140
     * @param $var
141
     * @param $type
142
     *
143
     * @return string
144
     */
145
    public function getPhpCodeGlobalsVariables($var = null, $type = 'REQUEST')
146
    {
147
        $type = mb_strtoupper($type);
148
        switch ($type) {
149
            case 'GET':
150
                $ret = "\$_GET['{$var}']";
151
                break;
152
            case 'POST':
153
                $ret = "\$_POST['{$var}']";
154
                break;
155
            case 'FILES':
156
                $ret = "\$_FILES['{$var}']";
157
                break;
158
            case 'COOKIE':
159
                $ret = "\$_COOKIE['{$var}']";
160
                break;
161
            case 'ENV':
162
                $ret = "\$_ENV['{$var}']";
163
                break;
164
            case 'SERVER':
165
                $ret = "\$_SERVER['{$var}']";
166
                break;
167
            default:
168
                $ret = "\$_REQUEST['{$var}']";
169
                break;
170
        }
171
172
        return $ret;
173
    }
174
175
    /**
176
     * @public function getPhpCodeRemoveCarriageReturn
177
     * @param        $string
178
     *
179
     * @param string $n
180
     * @param string $t
181
     * @return string
182
     */
183
    public function getPhpCodeRemoveCarriageReturn($string, $n = "\n", $t = "\r")
184
    {
185
        return str_replace([(string)$n, (string)$t], '', $string);
186
    }
187
188
    /**
189
     * @public function getPhpCodeFileExists
190
     * @param $filename
191
     *
192
     * @return string
193
     */
194
    public function getPhpCodeFileExists($filename)
195
    {
196
        return "file_exists({$filename})";
197
    }
198
199
    /**
200
     * @public function getPhpCodeIncludeDir
201
     * @param        $directory
202
     * @param        $filename
203
     * @param bool   $once
204
     * @param bool   $isPath
205
     *
206
     * @param string $type
207
     * @param string $t
208
     * @return string
209
     */
210
    public function getPhpCodeIncludeDir($directory = null, $filename = null, $once = false, $isPath = false, $type = 'include', $t = '')
211
    {
212
        if ('' === $type) {
213
            $type = 'include';
214
        }
215
        if (false === $once) {
216
            if (!$isPath) {
217
                $ret = "{$t}{$type} {$directory} . '/{$filename}.php';\n";
218
            } else {
219
                $ret = "{$t}{$type} {$directory};\n";
220
            }
221
        } else {
222
            if (!$isPath) {
223
                $ret = "{$t}{$type}_once {$directory} . '/{$filename}.php';\n";
224
            } else {
225
                $ret = "{$t}{$type}_once {$directory};\n";
226
            }
227
        }
228
229
        return $ret;
230
    }
231
232
    /**
233
     * @public function getPhpCodeTernaryOperator
234
     * @param $return
235
     * @param $condition
236
     * @param $one
237
     * @param $two
238
     * @param $t - Indentation
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
239
     *
240
     * @return string
241
     */
242
    public function getPhpCodeTernaryOperator($return, $condition, $one, $two, $t = '')
243
    {
244
        return "{$t}\${$return} = {$condition} ? {$one} : {$two};\n";
245
    }
246
247
    /**
248
     * @public function getPhpCodeClass
249
     * @param $name
250
     * @param $content
251
     * @param $extends
252
     * @param $type
253
     *
254
     * @param null $implements
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $implements is correct as it would always require null to be passed?
Loading history...
255
     * @return string
256
     */
257
    public function getPhpCodeClass($name = null, $content = null, $extends = null, $type = null, $implements = null)
258
    {
259
        $typ = (null != $type) ? "{$type} " : '';
260
        $ext = (null != $extends) ? " extends {$extends}" : '';
261
        $imp = (null != $implements) ? " implements {$implements}" : '';
0 ignored issues
show
introduced by
The condition null != $implements is always false.
Loading history...
262
        $ret = "{$typ}class {$name}{$ext}{$imp}\n";
263
        $ret .= '{';
264
        $ret .= $content;
265
        $ret .= "}\n";
266
267
        return $ret;
268
    }
269
270
    /**
271
     * @public function getPhpCodeClass
272
     * @param $type
273
     * @param $name
274
     * @param $assign
275
     * @param $t - Indentation
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
276
     *
277
     * @return string
278
     */
279
    public function getPhpCodeVariableClass($type = 'private', $name = null, $assign = 'null', $t = '')
280
    {
281
        return "{$t}{$type} \${$name} = {$assign};\n";
282
    }
283
284
    /**
285
     * @public function getPhpCodeInstance
286
     * @param $name
287
     * @param $content
288
     * @param $extends
289
     * @param $type
290
     *
291
     * @return string
292
     */
293
    public function getPhpCodeInterface($name = null, $content = null, $extends = null, $type = null)
294
    {
295
        $typ = (null != $type) ? "{$type} " : '';
296
        $ext = (null != $extends) ? " extends {$extends}" : '';
297
        $ret = "{$typ}interface {$name}{$ext}\n";
298
        $ret .= '{';
299
        $ret .= $content;
300
        $ret .= "}\n";
301
302
        return $ret;
303
    }
304
305
    /**
306
     * @public function getPhpCodeFunction
307
     * @param        $name
308
     * @param        $params
309
     * @param        $content
310
     * @param        $method
311
     * @param bool   $isRef
312
     * @param string $t - Indentation
313
     * @return string
314
     */
315
    public function getPhpCodeFunction($name = null, $params = null, $content = null, $method = null, $isRef = false, $t = '')
316
    {
317
        $inClass = (null != $method) ? $method : '';
318
        $ref     = (false !== $isRef) ? '&' : '';
319
        $ret     = "{$t}{$inClass}function {$ref}{$name}({$params})\n";
320
        $ret     .= "{$t}{\n";
321
        $ret     .= $content;
322
        $ret     .= "{$t}}\n";
323
324
        return $ret;
325
    }
326
327
    /**
328
     * @public function getPhpCodeConditions
329
     * @param string $condition
330
     * @param string $operator
331
     * @param string $type
332
     * @param string $contentIf
333
     * @param mixed $contentElse
334
     * @param string $t - Indentation
335
     *
336
     * @param string $conditionElse
337
     * @return string
338
     */
339
    public function getPhpCodeConditions($condition = null, $operator = null, $type = null, $contentIf = null, $contentElse = false, $t = '', $conditionElse = '')
340
    {
341
        if ('==' === trim($operator) || '===' === trim($operator) || '!=' === trim($operator) || '!==' === trim($operator)) {
342
            //yoda conditions
343
            $left  = $type;
344
            $right = $condition;
345
        } else {
346
            $left  = $condition;
347
            $right = $type;
348
        }
349
        if (false === $contentElse) {
350
            $ret = "{$t}if ({$left}{$operator}{$right}) {\n";
351
            $ret .= $contentIf;
352
            $ret .= "{$t}}\n";
353
        } else {
354
            $ret = "{$t}if ({$left}{$operator}{$right}) {\n";
355
            $ret .= $contentIf;
356
            if ('' !== $conditionElse) {
357
                $ret .= "{$t}} elseif ({$conditionElse}) {\n";
358
            } else {
359
                $ret .= "{$t}} else {\n";
360
            }
361
362
            $ret .= $contentElse;
363
            $ret .= "{$t}}\n";
364
        }
365
366
        return $ret;
367
    }
368
369
    /**
370
     * @public function getPhpCodeForeach
371
     * @param string      $array
372
     * @param bool|string $arrayKey
373
     * @param bool|string $key
374
     * @param bool|string $value
375
     * @param string      $content
376
     *
377
     * @param string      $t
378
     * @return string
379
     */
380
    public function getPhpCodeForeach($array, $arrayKey = false, $key = false, $value = false, $content = null, $t = '')
381
    {
382
        $vars  = '';
383
        $value = '' !== $value ? $value : 'i';
384
        if ((false === $arrayKey) && (false === $key)) {
385
            $vars = "\${$array} as \${$value}";
386
        } elseif ((false === $arrayKey) && (false !== $key)) {
387
            $vars = "\${$array} as \${$key} => \${$value}";
388
        } elseif ((false !== $arrayKey) && (false === $key)) {
389
            $vars = "array_keys(\${$array}) as \${$value}";
390
        }
391
392
        $ret = "{$t}foreach({$vars}) {\n";
393
        $ret .= "{$content}";
394
        $ret .= "{$t}}\n";
395
396
        return $ret;
397
    }
398
399
    /**
400
     * @public function getPhpCodeFor
401
     * @param        $var
402
     * @param        $content
403
     * @param        $value
404
     * @param        $initVal
405
     * @param        $operator
406
     *
407
     * @param string $t
408
     * @return string
409
     */
410
    public function getPhpCodeFor($var = null, $content = null, $value = null, $initVal = null, $operator = null, $t = '')
411
    {
412
        $ret = "{$t}for(\${$var} = {$initVal}; \${$var} {$operator} \${$value}; \${$var}++) {\n";
413
        $ret .= "{$content}";
414
        $ret .= "{$t}}\n";
415
416
        return $ret;
417
    }
418
419
    /**
420
     * @public function getPhpCodeWhile
421
     * @param $var
422
     * @param $content
423
     * @param $value
424
     * @param $operator
425
     * @param $t
426
     *
427
     * @return string
428
     */
429
    public function getPhpCodeWhile($var = null, $content = null, $value = null, $operator = null, $t = '')
430
    {
431
        $ret = "{$t}while (\${$var} {$operator} {$value}) {\n";
432
        $ret .= "{$t}{$content}";
433
        $ret .= "{$t}}\n";
434
435
        return $ret;
436
    }
437
438
    /**
439
     * @public function getPhpCodeSwitch
440
     *
441
     * @param $op
442
     * @param $content
443
     * @param $t
444
     *
445
     * @return string
446
     */
447
    public function getPhpCodeSwitch($op = null, $content = null, $t = '')
448
    {
449
        $ret = "{$t}switch(\${$op}) {\n";
450
        $ret .= $content;
451
        $ret .= "{$t}}\n";
452
453
        return $ret;
454
    }
455
456
    /**
457
     * @public function getPhpCodeCaseSwitch
458
     *
459
     * @param $cases
460
     * @param $defaultAfterCase
461
     * @param $default
462
     * @param $t
463
     *
464
     * @return string
465
     */
466
    public function getPhpCodeCaseSwitch($cases = [], $defaultAfterCase = false, $default = false, $t = '')
467
    {
468
        $ret = '';
469
        $def = "{$t}default:\n";
470
        foreach ($cases as $case => $value) {
471
            $case = is_string($case) ? "'{$case}'" : $case;
472
            if (empty($value)) {
473
                $ret .= "{$t}case {$case}:\n";
474
            } else if (!empty($case)) {
475
                $ret .= "{$t}case {$case}:\n";
476
                if (false !== $defaultAfterCase) {
477
                    $ret .= $def;
478
                }
479
                if (is_array($value)) {
480
                    foreach ($value as $content) {
481
                        $ret .= "{$content}";
482
                    }
483
                }
484
                $ret .= "{$t}break;\n";
485
                $defaultAfterCase = false;
486
            }
487
        }
488
        if (false !== $default) {
489
            $ret .= $def;
490
            $ret .= "{$t}{$default}\n";
491
            $ret .= "{$t}break;\n";
492
        }
493
494
        return $ret;
495
    }
496
497
    /**
498
     * @public function getPhpCodeIsset
499
     * @param $var
500
     * @return string
501
     */
502
    public function getPhpCodeIsset($var)
503
    {
504
        return "isset(\${$var})";
505
    }
506
507
    /**
508
     * @public function getPhpCodeUnset
509
     * @param string $var
510
     * @param string $t
511
     * @return string
512
     */
513
    public function getPhpCodeUnset($var = '', $t = '')
514
    {
515
        return "{$t}unset(\${$var});\n";
516
    }
517
518
    /**
519
     * @public function getPhpCodeIsDir
520
     * @param $var
521
     * @return string
522
     */
523
    public function getPhpCodeIsDir($var)
524
    {
525
        return "is_dir({$var})";
526
    }
527
528
    /**
529
     * @public function getPhpCodeImplode
530
     * @param $left
531
     * @param $right
532
     * @return string
533
     */
534
    public function getPhpCodeImplode($left, $right)
535
    {
536
        return "implode('{$left}', {$right})";
537
    }
538
539
    /**
540
     * @public function getPhpCodeExplode
541
     * @param $left
542
     * @param $right
543
     * @return string
544
     */
545
    public function getPhpCodeExplode($left, $right)
546
    {
547
        return "explode('{$left}', {$right})";
548
    }
549
550
    /**
551
     * @public function getPhpCodeChmod
552
     * @param        $var
553
     * @param string $perm
554
     * @param string $t
555
     * @return string
556
     */
557
    public function getPhpCodeChmod($var, $perm = '0777', $t = '')
558
    {
559
        return "{$t}chmod(\${$var}, {$perm});\n";
560
    }
561
562
    /**
563
     * @public function getPhpCodeMkdir
564
     * @param        $var
565
     * @param string $perm
566
     * @param string $t
567
     * @return string
568
     */
569
    public function getPhpCodeMkdir($var, $perm = '0777', $t = '')
570
    {
571
        return "{$t}mkdir(\${$var}, {$perm});\n";
572
    }
573
574
    /**
575
     * @public function getPhpCodeCopy
576
     * @param        $file
577
     * @param string $newfile
578
     * @param string $t
579
     * @return string
580
     */
581
    public function getPhpCodeCopy($file, $newfile = '', $t = '')
582
    {
583
        return "{$t}copy({$file}, {$newfile});\n";
584
    }
585
586
    /**
587
     * @public function getPhpCodeArray
588
     * @param        $var
589
     * @param        $array
590
     * @param bool   $isParam
591
     *
592
     * @param string $t
593
     * @return string
594
     */
595
    public function getPhpCodeArray($var, $array = null, $isParam = false, $t = "\t\t")
596
    {
597
        $retArray = [];
598
        if (is_array($array) && !empty($array)) {
599
            foreach ($array as $k => $v) {
600
                if (is_numeric($k)) {
601
                    $retArray[] = $v;
602
                } else {
603
                    $retArray[] = "{$k} => {$v}";
604
                }
605
            }
606
            $arrayContent = implode(', ', $retArray);
607
        } else {
608
            $arrayContent = '';
609
        }
610
        unset($retArray);
611
612
        if (!$isParam) {
613
            $ret = "{$t}\${$var} = [{$arrayContent}];\n";
614
        } else {
615
            $ret = "[{$array}]";
616
        }
617
618
        return $ret;
619
    }
620
621
    /**
622
     * @public function getPhpCodeArrayType
623
     * @param        $var
624
     * @param        $type
625
     * @param        $left
626
     * @param        $right
627
     * @param bool   $isParam
628
     *
629
     * @param string $t
630
     * @return string
631
     */
632
    public function getPhpCodeArrayType($var, $type, $left, $right = null, $isParam = false, $t = "\t\t")
633
    {
634
        $vars = (null != $right) ? "\${$left}, {$right}" : "\${$left}";
635
        if (!$isParam) {
636
            $ret = "{$t}\${$var}[] = array_{$type}({$vars});\n";
637
        } else {
638
            $ret = "array_{$type}({$vars})";
639
        }
640
641
        return $ret;
642
    }
643
644
    /**
645
     * @public function getPhpCodeArrayType
646
     * @param        $var
647
     * @param string $t
648
     * @return string
649
     */
650
    public function getPhpCodeArrayShift($var, $t = '')
651
    {
652
        return "{$t}array_shift({$var});\n";
653
    }
654
655
    /**
656
     * @public function getPhpCodeSprintf
657
     * @param $left
658
     * @param $right
659
     * @return string
660
     */
661
    public function getPhpCodeSprintf($left, $right)
662
    {
663
        return "sprintf({$left}, {$right})";
664
    }
665
666
    /**
667
     * @public function getPhpCodeEmpty
668
     * @param $var
669
     * @return string
670
     */
671
    public function getPhpCodeEmpty($var)
672
    {
673
        return "empty({$var})";
674
    }
675
676
    /**
677
     * @public function getPhpCodeHeader
678
     * @param $var
679
     * @return string
680
     */
681
    public function getPhpCodeHeader($var)
682
    {
683
        return "header({$var})";
684
    }
685
686
    /**
687
     * @public function getPhpCodeRawurlencode
688
     * @param $var
689
     * @return string
690
     */
691
    public function getPhpCodeRawurlencode($var)
692
    {
693
        return "rawurlencode({$var})";
694
    }
695
696
    /**
697
     * @public function getPhpCodePregFunzions
698
     * @param        $var
699
     * @param        $exp
700
     * @param        $str
701
     * @param        $val
702
     * @param string $type
703
     * @param bool   $isParam
704
     *
705
     * @param string $t
706
     * @return string
707
     */
708
    public function getPhpCodePregFunzions($var, $exp, $str, $val, $type = 'match', $isParam = false, $t = "\t")
709
    {
710
        $pregFunz = "preg_{$type}('";
711
        if (!$isParam) {
712
            $ret = "{$t}\${$var} = {$pregFunz}{$exp}', '{$str}', {$val});\n";
713
        } else {
714
            $ret = "{$pregFunz}{$exp}', '{$str}', {$val})";
715
        }
716
717
        return $ret;
718
    }
719
720
    /**
721
     * @public function getPhpCodeStrType
722
     * @param        $left
723
     * @param        $var
724
     * @param        $str
725
     * @param        $value
726
     * @param string $type
727
     * @param bool   $isParam
728
     *
729
     * @param string $t
730
     * @return string
731
     */
732
    public function getPhpCodeStrType($left, $var, $str, $value, $type = 'replace', $isParam = false, $t = "\t")
733
    {
734
        $strType = "str_{$type}('";
735
        if (!$isParam) {
736
            $ret = "{$t}\${$left} = {$strType}{$var}', '{$str}', {$value});\n";
737
        } else {
738
            $ret = "{$strType}{$var}', '{$str}', {$value})";
739
        }
740
741
        return $ret;
742
    }
743
744
    /**
745
     * @public function getPhpCodeStripTags
746
     * @param        $left
747
     * @param        $value
748
     * @param bool   $isParam
749
     *
750
     * @param string $t
751
     * @return string
752
     */
753
    public function getPhpCodeStripTags($left, $value, $isParam = false, $t = '')
754
    {
755
        if (!$isParam) {
756
            $ret = "{$t}\${$left} = strip_tags({$value});\n";
757
        } else {
758
            $ret = "strip_tags({$value})";
759
        }
760
761
        return $ret;
762
    }
763
764
    /**
765
     * @public function getPhpCodeHtmlentities
766
     * @param $entitiesVar
767
     * @param $entitiesQuote
768
     * @return string
769
     */
770
    public function getPhpCodeHtmlentities($entitiesVar, $entitiesQuote = false)
771
    {
772
        $entitiesVar = (false !== $entitiesQuote) ? $entitiesVar . ', ' . $entitiesQuote : $entitiesVar;
773
        $entities    = "htmlentities({$entitiesVar})";
774
775
        return $entities;
776
    }
777
778
    /**
779
     * @public function getPhpCodeHtmlspecialchars
780
     * @param $specialVar
781
     * @param $specialQuote
782
     * @return string
783
     */
784
    public function getPhpCodeHtmlspecialchars($specialVar, $specialQuote = false)
785
    {
786
        $specialVar   = (false !== $specialQuote) ? $specialVar . ', ' . $specialQuote : $specialVar;
787
        $specialchars = "htmlspecialchars({$specialVar})";
788
789
        return $specialchars;
790
    }
791
792
    /**
793
     * @public function getPhpCodeNamespace
794
     * @param $dimensions
795
     * @param string $t
796
     * @param string $n
797
     * @return string
798
     */
799
    public function getPhpCodeNamespace($dimensions, $t = '', $n = "\n\n")
800
    {
801
        $ret  = "\n{$t}namespace ";
802
        foreach ($dimensions as $key => $dim) {
803
            if ($key > 0) {
804
                $ucfDim = ucfirst($dim);
805
                $ret .= "\\{$ucfDim}";
806
            } else {
807
                $ret .= "{$dim}";
808
            }
809
        }
810
        $ret .= ";" . $n;
811
812
        return $ret;
813
    }
814
815
    /**
816
     * @public function getPhpCodeUseNamespace
817
     * @param $dimensions
818
     * @param string $t
819
     * @param string $n
820
     * @return string
821
     */
822
    public function getPhpCodeUseNamespace($dimensions, $t = '', $n = "\n\n")
823
    {
824
        $ret  = "\n{$t}use ";
825
        foreach ($dimensions as $key => $dim) {
826
            if ($key > 0) {
827
                $ucfDim = ucfirst($dim);
828
                $ret .= "\\{$ucfDim}";
829
            } else {
830
                $ret .= "{$dim}";
831
            }
832
        }
833
        $ret .= ";" . $n;
834
835
        return $ret;
836
    }
837
    /**
838
     * @public function getPhpCodeBlankLine
839
     *
840
     * @return string
841
     */
842
    public function getPhpCodeBlankLine()
843
    {
844
        return "\n";
845
    }
846
847
    /**
848
     * @public function getPhpCodeConstant
849
     *
850
     * @param $const
851
     * @param $value
852
     * @param string $t
853
     * @param string $type
854
     * @return string
855
     */
856
    public function getPhpCodeConstant($const, $value, $t = '', $type = 'const')
857
    {
858
        return  "{$t}{$type} {$const} = {$value};\n";
859
    }
860
861
    /**
862
     * @public function getPhpCodeTriggerError
863
     *
864
     * @param $msg
865
     * @param $type
866
     * @param string $t
867
     * @return string
868
     */
869
    public function getPhpCodeTriggerError($msg, $type, $t ='')
870
    {
871
        $ret = "{$t}trigger_error($msg, {$type});\n";
872
        return $ret;
873
    }
874
}
875