PreloadsCore   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 8 2
A __construct() 0 4 1
A render() 0 31 1
A write() 0 4 1
1
<?php
2
3
namespace XoopsModules\Tdmcreate\Files\Preloads;
4
5
use XoopsModules\Tdmcreate;
6
use XoopsModules\Tdmcreate\Files;
7
8
/*
9
 You may not change or alter any portion of this comment or credits
10
 of supporting developers from this source code or any supporting source code
11
 which is considered copyrighted (c) material of the original comment or credit authors.
12
13
 This program is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
/**
18
 * tdmcreate module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.0
24
 *
25
 * @author          Txmod Xoops http://www.txmodxoops.org
26
 *
27
 */
28
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
29
30
/**
31
 * Class PreloadsCore.
32
 */
33
class PreloadsCore extends Files\CreateFile
34
{
35
    /**
36
     * @public function constructor
37
     * @param null
38
     */
39
    public function __construct()
40
    {
41
        parent::__construct();
42
        $this->tdmcfile = Tdmcreate\Files\CreateFile::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property tdmcfile does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
43
    }
44
45
    /**
46
     * @static function getInstance
47
     * @param null
48
     * @return PreloadsCore
49
     */
50
    public static function getInstance()
51
    {
52
        static $instance = false;
53
        if (!$instance) {
54
            $instance = new self();
55
        }
56
57
        return $instance;
58
    }
59
60
    /**
61
     * @public function write
62
     * @param $module
63
     * @param $filename
64
     */
65
    public function write($module, $filename)
66
    {
67
        $this->setModule($module);
68
        $this->setFileName($filename);
69
    }
70
71
    /**
72
     * @public function render
73
     * @param null
74
     * @return bool|string
75
     */
76
    public function render()
77
    {
78
        $module           = $this->getModule();
79
        $filename         = $this->getFileName();
80
        $moduleDirname    = $module->getVar('mod_dirname');
81
        $ucfModuleDirname = ucfirst($moduleDirname);
82
        $content          = $this->getHeaderFilesComments($module, $filename);
83
84
        $content .= <<<EOT
85
/**
86
 * {$ucfModuleDirname} core preloads
87
 *
88
 */
89
class {$ucfModuleDirname}CorePreload extends \XoopsPreloadItem
90
{
91
	// Here your functions method
92
	// Example:
93
	/**
94
     * @param \$args
95
     */
96
    function eventCoreYourNameStart(\$args)
97
    {
98
        // Here your event
99
        exit();
100
    }
101
}
102
EOT;
103
104
        $this->tdmcfile->create($moduleDirname, 'preloads', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
105
106
        return $this->tdmcfile->renderFile();
107
    }
108
}
109