Skip to content

Commit 3ae8275

Browse files
authored
Merge pull request #173 from ggoffy/master
updated creation code to generate module with no errors from copilot
2 parents e01e7b1 + da685c4 commit 3ae8275

132 files changed

Lines changed: 2190 additions & 2327 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

class/Building.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class Building
3333
/**
3434
* @static function getInstance
3535
*
36-
* @param null
37-
*
3836
* @return Building
3937
*/
4038
public static function getInstance()
@@ -48,11 +46,11 @@ public static function getInstance()
4846
}
4947

5048
/**
51-
* @param bool $action
49+
* @param string|bool $action
5250
*
5351
* @return \XoopsThemeForm
5452
*/
55-
public function getForm($action = false)
53+
public function getForm(string|bool $action = false)
5654
{
5755
$helper = Modulebuilder\Helper::getInstance();
5856
if (false === $action) {
@@ -85,7 +83,7 @@ public function getForm($action = false)
8583
* @param string $dir
8684
* @param string $pattern
8785
*/
88-
public function clearDir($dir, $pattern = '*'): void
86+
public function clearDir(string $dir, string $pattern = '*'): void
8987
{
9088
// Find all files and folders matching pattern
9189
$files = glob($dir . "/$pattern");
@@ -121,7 +119,7 @@ public function clearDir($dir, $pattern = '*'): void
121119
* @param string $src
122120
* @param string $dst
123121
*/
124-
public function copyDir($src, $dst): void
122+
public function copyDir(string $src, string $dst): void
125123
{
126124
$dir = \opendir($src);
127125
if (!\mkdir($dst) && !\is_dir($dst)) {

class/Common/Breadcrumb.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct()
5252
* @param string $title
5353
* @param string $link
5454
*/
55-
public function addLink($title = '', $link = ''): void
55+
public function addLink(string $title = '', string $link = ''): void
5656
{
5757
$this->bread[] = [
5858
'link' => $link,

class/Common/Confirm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Confirm
5353
* @param string $title
5454
* @param string $label
5555
*/
56-
public function __construct($hiddens, $action, $object, $title = '', $label = '')
56+
public function __construct($hiddens, $action, $object, string $title = '', string $label = '')
5757
{
5858
$this->hiddens = $hiddens;
5959
$this->action = $action;

class/Common/DirectoryChecker.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class DirectoryChecker
4141
*
4242
* @return bool|string
4343
*/
44-
public static function getDirectoryStatus($path, $mode = 0777, $redirectFile = null)
44+
public static function getDirectoryStatus($path, int $mode = 0777, $redirectFile = null)
4545
{
4646
$pathIcon16 = \Xmf\Module\Admin::iconUrl('', '16');
4747

@@ -99,12 +99,16 @@ public static function getDirectoryStatus($path, $mode = 0777, $redirectFile = n
9999
*
100100
* @return bool
101101
*/
102-
public static function createDirectory($target, $mode = 0777)
102+
public static function createDirectory($target, int $mode = 0777)
103103
{
104104
$target = \str_replace('..', '', $target);
105105

106106
// https://www.php.net/manual/en/function.mkdir.php
107-
return \is_dir($target) || (self::createDirectory(\dirname($target), $mode) && !\mkdir($target, $mode) && !\is_dir($target));
107+
return \is_dir($target)
108+
|| (
109+
self::createDirectory(\dirname($target), $mode)
110+
&& (\mkdir($target, $mode) || \is_dir($target))
111+
);
108112
}
109113

110114
/**
@@ -113,7 +117,7 @@ public static function createDirectory($target, $mode = 0777)
113117
*
114118
* @return bool
115119
*/
116-
public static function setDirectoryPermissions($target, $mode = 0777)
120+
public static function setDirectoryPermissions($target, int $mode = 0777)
117121
{
118122
$target = \str_replace('..', '', $target);
119123

@@ -134,26 +138,23 @@ public static function dirExists($dir_path)
134138
$op = Request::getString('op', '', 'POST');
135139
switch ($op) {
136140
case 'createdir':
137-
if (\Xmf\Request::hasVar('path', 'POST')) {
138-
$path = $_POST['path'];
139-
}
140-
if (\Xmf\Request::hasVar('redirect', 'POST')) {
141-
$redirect = $_POST['redirect'];
141+
if (!\Xmf\Request::hasVar('path', 'POST') || !\Xmf\Request::hasVar('redirect', 'POST')) {
142+
break;
142143
}
144+
$path = \Xmf\Request::getString('path','', 'POST');
145+
$redirect = \Xmf\Request::getString('redirect','', 'POST');
143146
$msg = DirectoryChecker::createDirectory($path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRCREATED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRNOTCREATED');
144147
\redirect_header($redirect, 2, $msg . ': ' . $path);
145148
break;
146149
case 'setdirperm':
147-
if (\Xmf\Request::hasVar('path', 'POST')) {
148-
$path = $_POST['path'];
149-
}
150-
if (\Xmf\Request::hasVar('redirect', 'POST')) {
151-
$redirect = $_POST['redirect'];
152-
}
153-
if (\Xmf\Request::hasVar('mode', 'POST')) {
154-
$mode = $_POST['mode'];
150+
if (!\Xmf\Request::hasVar('path', 'POST') || !\Xmf\Request::hasVar('redirect', 'POST') || !\Xmf\Request::hasVar('mode', 'POST')) {
151+
break;
155152
}
153+
$path = \Xmf\Request::getString('path','', 'POST');
154+
$redirect = \Xmf\Request::getString('redirect','', 'POST');
155+
$mode = \Xmf\Request::getInt('mode',0 , 'POST');
156156
$msg = DirectoryChecker::setDirectoryPermissions($path, $mode) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMSET') : \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMNOTSET');
157+
157158
\redirect_header($redirect, 2, $msg . ': ' . $path);
158159
break;
159160
}

class/Common/FileChecker.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737
class FileChecker
3838
{
3939
/**
40-
* @param string $file_path
40+
* @param string $file_path
41+
* @param string $redirectFile
4142
* @param string|null $original_file_path
42-
* @param string $redirectFile
43+
*
4344
* @return bool|string
4445
*/
45-
public static function getFileStatus($file_path, $original_file_path = null, $redirectFile)
46+
public static function getFileStatus(string $file_path, string $redirectFile, string $original_file_path = null)
4647
{
4748
$pathIcon16 = \Xmf\Module\Admin::iconUrl('', '16');
4849

@@ -135,7 +136,7 @@ public static function fileExists($file_path)
135136
*
136137
* @return bool
137138
*/
138-
public static function setFilePermissions($target, $mode = 0777)
139+
public static function setFilePermissions($target, int $mode = 0777)
139140
{
140141
$target = \str_replace('..', '', $target);
141142

@@ -144,18 +145,15 @@ public static function setFilePermissions($target, $mode = 0777)
144145
}
145146

146147
$op = Request::getString('op', '', 'POST');
147-
switch ($op) {
148-
case 'copyfile':
149-
if (\Xmf\Request::hasVar('original_file_path', 'POST')) {
150-
$original_file_path = $_POST['original_file_path'];
151-
}
152-
if (\Xmf\Request::hasVar('file_path', 'POST')) {
153-
$file_path = $_POST['file_path'];
154-
}
155-
if (\Xmf\Request::hasVar('redirect', 'POST')) {
156-
$redirect = $_POST['redirect'];
148+
if ($op == 'copyfile') {
149+
if (!\Xmf\Request::hasVar('original_file_path', 'POST')
150+
|| !\Xmf\Request::hasVar('file_path', 'POST')
151+
|| !\Xmf\Request::hasVar('redirect', 'POST')) {
152+
return;
157153
}
158-
$msg = FileChecker::copyFile($original_file_path, $file_path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILECOPIED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILENOTCOPIED');
159-
\redirect_header($redirect, 2, $msg . ': ' . $file_path);
160-
break;
154+
$original_file_path = $_POST['original_file_path'];
155+
$file_path = $_POST['file_path'];
156+
$redirect = $_POST['redirect'];
157+
$msg = FileChecker::copyFile($original_file_path, $file_path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILECOPIED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILENOTCOPIED');
158+
\redirect_header($redirect, 2, $msg . ': ' . $file_path);
161159
}

class/Common/Migrate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private function changePrefix(): void
5858
* @param string $tableName table to convert
5959
* @param string $columnName column with IP address
6060
*/
61-
private function convertIPAddresses($tableName, $columnName): void
61+
protected function convertIPAddresses(string $tableName, string $columnName): void
6262
{
6363
if ($this->tableHandler->useTable($tableName)) {
6464
$attributes = $this->tableHandler->getColumnAttributes($tableName, $columnName);

class/Common/ModuleFeedback.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,13 @@ class ModuleFeedback extends \XoopsObject
3636

3737
/**
3838
* Constructor
39-
*
40-
* @param null
4139
*/
4240
public function __construct()
4341
{
4442
}
4543

4644
/**
4745
* @static function &getInstance
48-
*
49-
* @param null
5046
*/
5147
public static function getInstance(): void
5248
{
@@ -70,7 +66,9 @@ public function getFormFeedback()
7066
$form = new \XoopsThemeForm(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_FORM_TITLE'), 'formfeedback', 'feedback.php', 'post', true);
7167
$form->setExtra('enctype="multipart/form-data"');
7268

73-
$recipient = new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_RECIPIENT'), 'recipient', 50, 255, $GLOBALS['xoopsModule']->getInfo('author_mail'));
69+
$xoopsModule = $GLOBALS['xoopsModule'] ?? null;
70+
$authorMail = $xoopsModule ? (string)$xoopsModule->getInfo('author_mail') : '';
71+
$recipient = new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_RECIPIENT'), 'recipient', 50, 255, $authorMail);
7472
$recipient->setExtra('disabled="disabled"');
7573
$form->addElement($recipient);
7674
$your_name = new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME'), 'your_name', 50, 255, $this->name);

class/Common/ModuleStats.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ trait ModuleStats
2323
{
2424
/**
2525
* @param \XoopsModules\Modulebuilder\Common\Configurator $configurator
26-
* @param array $moduleStats
26+
* @param array $moduleStats
2727
* @return array
2828
*/
29-
public static function getModuleStats($configurator, $moduleStats)
29+
public static function getModuleStats(Configurator $configurator, array $moduleStats)
3030
{
3131
if (\count($configurator->moduleStats) > 0) {
3232
foreach (\array_keys($configurator->moduleStats) as $i) {

class/Common/SysUtility.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ public static function getInstance()
6262
* www.cakephp.org
6363
*
6464
* @param string $text String to truncate.
65-
* @param int $length Length of returned string, including ellipsis.
65+
* @param int $length Length of returned string, including ellipsis.
6666
* @param string $ending Ending to be appended to the trimmed string.
67-
* @param bool $exact If false, $text will not be cut mid-word
68-
* @param bool $considerHtml If true, HTML tags would be handled correctly
67+
* @param bool $exact If false, $text will not be cut mid-word
68+
* @param bool $considerHtml If true, HTML tags would be handled correctly
6969
*
7070
* @return string Trimmed string.
7171
*/
72-
public static function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true)
72+
public static function truncateHtml(string $text, int $length = 100, string $ending = '...', bool $exact = false, bool $considerHtml = true)
7373
{
7474
if ($considerHtml) {
7575
// if the plain text is shorter than the maximum length, return the whole text
@@ -161,11 +161,11 @@ public static function truncateHtml($text, $length = 100, $ending = '...', $exac
161161
}
162162

163163
/**
164-
* @param \Xmf\Module\Helper $helper
165-
* @param array|null $options
164+
* @param \Xmf\Module\Helper|null $helper
165+
* @param array|null $options
166166
* @return \XoopsFormDhtmlTextArea|\XoopsFormEditor
167167
*/
168-
public static function getEditor($helper = null, $options = null)
168+
public static function getEditor(\Xmf\Module\Helper $helper = null, array $options = null)
169169
{
170170
/** @var Helper $helper */
171171
if (null === $options) {

class/Common/TableChecker.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class TableChecker extends \XoopsObject
4646
public const CHECKTYPE_UPDATE_REPORT = 2; //update and report
4747

4848
/**
49-
* @param \XoopsModules\Modulebuilder\Common\TableChecker|null
5049
* @param mixed $mydirname
5150
* @param mixed $checktype
5251
*/
@@ -72,12 +71,12 @@ public function processSQL()
7271
if ($numRows) {
7372
//table exist
7473
$this->result[] = 'Table exist:' . $table;
75-
$ret = $this->checkTableFields($table, $tabledef['fields']);
74+
$this->checkTableFields($table, $tabledef['fields']);
7675
} else {
7776
if ($this::CHECKTYPE_UPDATE == $this->checktype || $this::CHECKTYPE_UPDATE_REPORT == $this->checktype) {
7877
// create new table
7978
$sql = $tabledef['sql'];
80-
if ($this->result = $GLOBALS['xoopsDB']->queryF($sql)) {
79+
if ($GLOBALS['xoopsDB']->queryF($sql)) {
8180
$this->result[] = 'Table created:' . $table;
8281
} else {
8382
\xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
@@ -92,6 +91,8 @@ public function processSQL()
9291
if (self::CHECKTYPE_REPORT == $this->checktype || self::CHECKTYPE_UPDATE_REPORT == $this->checktype) {
9392
return $this->result;
9493
}
94+
95+
return [];
9596
}
9697

9798
private function readSQLFile()
@@ -156,11 +157,9 @@ private function extractKey($line)
156157
{
157158
//todo: split string into single keys
158159
$needle = '(';
159-
$key_text = \substr($line, \strpos($line, $needle, 0) + 1);
160+
$key_text = \substr($line, \strpos($line, $needle) + 1);
160161
$needle = ')';
161-
$key_text = \substr($key_text, 0, \strpos($key_text, $needle, 0));
162-
163-
return $key_text;
162+
return \substr($key_text, 0, \strpos($key_text, $needle));
164163
}
165164

166165
private function extractField($line)
@@ -191,7 +190,7 @@ private function extractField($line)
191190
if (\count($params) > $counter) {
192191
if ('default' == \mb_strtolower($params[$counter])) {
193192
$field['default'] = $params[$counter] . ' ' . $params[$counter + 1];
194-
$counter = $counter + 2;
193+
//$counter = $counter + 2;
195194
}
196195
}
197196

@@ -211,15 +210,15 @@ private function checkTableFields($table, $fields)
211210
$numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
212211
if ($numRows) {
213212
//field exist
214-
$this->checkField($table, $field);
213+
$this->checkField($field);
215214
} else {
216215
if (self::CHECKTYPE_UPDATE == $this->checktype || self::CHECKTYPE_UPDATE_REPORT == $this->checktype) {
217216
// create new field
218217
$sql = "ALTER TABLE `$table` ADD " . $field['sql'];
219218
if ('' !== (string)$field['after']) {
220219
$sql .= ' AFTER `' . $field['after'] . '`;';
221220
}
222-
if ($result = $GLOBALS['xoopsDB']->queryF($sql)) {
221+
if ($GLOBALS['xoopsDB']->queryF($sql)) {
223222
$this->result[] = 'Field added:' . $fieldname;
224223
} else {
225224
\xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
@@ -234,11 +233,10 @@ private function checkTableFields($table, $fields)
234233
return true;
235234
}
236235

237-
private function checkField($table, $field)
236+
private function checkField($field): void
238237
{
239238
//to be created
240239
$this->result[] = 'Field exist:' . $field['name'] . ' - no changes';
241240

242-
return true;
243241
}
244242
}

0 commit comments

Comments
 (0)