Skip to content

Commit 647babf

Browse files
committed
updated creation code to generate module with no errors from copilot
1 parent e01e7b1 commit 647babf

134 files changed

Lines changed: 2041 additions & 2162 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: 3 additions & 5 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()
@@ -52,7 +50,7 @@ public static function getInstance()
5250
*
5351
* @return \XoopsThemeForm
5452
*/
55-
public function getForm($action = false)
53+
public function getForm(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: 3 additions & 3 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,7 +99,7 @@ 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

@@ -113,7 +113,7 @@ public static function createDirectory($target, $mode = 0777)
113113
*
114114
* @return bool
115115
*/
116-
public static function setDirectoryPermissions($target, $mode = 0777)
116+
public static function setDirectoryPermissions($target, int $mode = 0777)
117117
{
118118
$target = \str_replace('..', '', $target);
119119

class/Common/FileChecker.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
class FileChecker
3838
{
3939
/**
40-
* @param string $file_path
40+
* @param string $file_path
4141
* @param string|null $original_file_path
42-
* @param string $redirectFile
42+
* @param string $redirectFile
4343
* @return bool|string
4444
*/
45-
public static function getFileStatus($file_path, $original_file_path = null, $redirectFile)
45+
public static function getFileStatus(string $file_path, string $original_file_path = null, string $redirectFile)
4646
{
4747
$pathIcon16 = \Xmf\Module\Admin::iconUrl('', '16');
4848

@@ -135,7 +135,7 @@ public static function fileExists($file_path)
135135
*
136136
* @return bool
137137
*/
138-
public static function setFilePermissions($target, $mode = 0777)
138+
public static function setFilePermissions($target, int $mode = 0777)
139139
{
140140
$target = \str_replace('..', '', $target);
141141

@@ -144,18 +144,16 @@ public static function setFilePermissions($target, $mode = 0777)
144144
}
145145

146146
$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'];
157-
}
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;
147+
if ($op == 'copyfile') {
148+
if (\Xmf\Request::hasVar('original_file_path', 'POST')) {
149+
$original_file_path = $_POST['original_file_path'];
150+
}
151+
if (\Xmf\Request::hasVar('file_path', 'POST')) {
152+
$file_path = $_POST['file_path'];
153+
}
154+
if (\Xmf\Request::hasVar('redirect', 'POST')) {
155+
$redirect = $_POST['redirect'];
156+
}
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+
private 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: 9 additions & 11 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,7 +71,7 @@ public function processSQL()
7271
if ($numRows) {
7372
//table exist
7473
$this->result[] = 'Table exist:' . $table;
75-
$ret = $this->checkTableFields($table, $tabledef['fields']);
74+
//$ret = $this->checkTableFields($table, $tabledef['fields']);
7675
} else {
7776
if ($this::CHECKTYPE_UPDATE == $this->checktype || $this::CHECKTYPE_UPDATE_REPORT == $this->checktype) {
7877
// create new table
@@ -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)