Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions class/Building.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class Building
/**
* @static function getInstance
*
* @param null
*
* @return Building
*/
public static function getInstance()
Expand All @@ -52,7 +50,7 @@ public static function getInstance()
*
* @return \XoopsThemeForm
*/
public function getForm($action = false)
public function getForm(bool $action = false)
{
$helper = Modulebuilder\Helper::getInstance();
if (false === $action) {
Expand Down Expand Up @@ -85,7 +83,7 @@ public function getForm($action = false)
* @param string $dir
* @param string $pattern
*/
public function clearDir($dir, $pattern = '*'): void
public function clearDir(string $dir, string $pattern = '*'): void
{
// Find all files and folders matching pattern
$files = glob($dir . "/$pattern");
Expand Down Expand Up @@ -121,7 +119,7 @@ public function clearDir($dir, $pattern = '*'): void
* @param string $src
* @param string $dst
*/
public function copyDir($src, $dst): void
public function copyDir(string $src, string $dst): void
{
$dir = \opendir($src);
if (!\mkdir($dst) && !\is_dir($dst)) {
Expand Down
2 changes: 1 addition & 1 deletion class/Common/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct()
* @param string $title
* @param string $link
*/
public function addLink($title = '', $link = ''): void
public function addLink(string $title = '', string $link = ''): void
{
$this->bread[] = [
'link' => $link,
Expand Down
2 changes: 1 addition & 1 deletion class/Common/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Confirm
* @param string $title
* @param string $label
*/
public function __construct($hiddens, $action, $object, $title = '', $label = '')
public function __construct($hiddens, $action, $object, string $title = '', string $label = '')
{
$this->hiddens = $hiddens;
$this->action = $action;
Expand Down
6 changes: 3 additions & 3 deletions class/Common/DirectoryChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DirectoryChecker
*
* @return bool|string
*/
public static function getDirectoryStatus($path, $mode = 0777, $redirectFile = null)
public static function getDirectoryStatus($path, int $mode = 0777, $redirectFile = null)
{
$pathIcon16 = \Xmf\Module\Admin::iconUrl('', '16');

Expand Down Expand Up @@ -99,7 +99,7 @@ public static function getDirectoryStatus($path, $mode = 0777, $redirectFile = n
*
* @return bool
*/
public static function createDirectory($target, $mode = 0777)
public static function createDirectory($target, int $mode = 0777)
{
$target = \str_replace('..', '', $target);

Expand All @@ -113,7 +113,7 @@ public static function createDirectory($target, $mode = 0777)
*
* @return bool
*/
public static function setDirectoryPermissions($target, $mode = 0777)
public static function setDirectoryPermissions($target, int $mode = 0777)
{
$target = \str_replace('..', '', $target);

Expand Down
34 changes: 16 additions & 18 deletions class/Common/FileChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
class FileChecker
{
/**
* @param string $file_path
* @param string $file_path
* @param string|null $original_file_path
* @param string $redirectFile
* @param string $redirectFile
* @return bool|string
*/
public static function getFileStatus($file_path, $original_file_path = null, $redirectFile)
public static function getFileStatus(string $file_path, string $original_file_path = null, string $redirectFile)
{
$pathIcon16 = \Xmf\Module\Admin::iconUrl('', '16');

Expand Down Expand Up @@ -135,7 +135,7 @@ public static function fileExists($file_path)
*
* @return bool
*/
public static function setFilePermissions($target, $mode = 0777)
public static function setFilePermissions($target, int $mode = 0777)
{
$target = \str_replace('..', '', $target);

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

$op = Request::getString('op', '', 'POST');
switch ($op) {
case 'copyfile':
if (\Xmf\Request::hasVar('original_file_path', 'POST')) {
$original_file_path = $_POST['original_file_path'];
}
if (\Xmf\Request::hasVar('file_path', 'POST')) {
$file_path = $_POST['file_path'];
}
if (\Xmf\Request::hasVar('redirect', 'POST')) {
$redirect = $_POST['redirect'];
}
$msg = FileChecker::copyFile($original_file_path, $file_path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILECOPIED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILENOTCOPIED');
\redirect_header($redirect, 2, $msg . ': ' . $file_path);
break;
if ($op == 'copyfile') {
if (\Xmf\Request::hasVar('original_file_path', 'POST')) {
$original_file_path = $_POST['original_file_path'];
}
if (\Xmf\Request::hasVar('file_path', 'POST')) {
$file_path = $_POST['file_path'];
}
if (\Xmf\Request::hasVar('redirect', 'POST')) {
$redirect = $_POST['redirect'];
}
$msg = FileChecker::copyFile($original_file_path, $file_path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILECOPIED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILENOTCOPIED');
\redirect_header($redirect, 2, $msg . ': ' . $file_path);
}
2 changes: 1 addition & 1 deletion class/Common/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function changePrefix(): void
* @param string $tableName table to convert
* @param string $columnName column with IP address
*/
private function convertIPAddresses($tableName, $columnName): void
private function convertIPAddresses(string $tableName, string $columnName): void
{
if ($this->tableHandler->useTable($tableName)) {
$attributes = $this->tableHandler->getColumnAttributes($tableName, $columnName);
Expand Down
8 changes: 3 additions & 5 deletions class/Common/ModuleFeedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,13 @@ class ModuleFeedback extends \XoopsObject

/**
* Constructor
*
* @param null
*/
public function __construct()
{
}

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

$recipient = new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_RECIPIENT'), 'recipient', 50, 255, $GLOBALS['xoopsModule']->getInfo('author_mail'));
$xoopsModule = $GLOBALS['xoopsModule'] ?? null;
$authorMail = $xoopsModule ? (string)$xoopsModule->getInfo('author_mail') : '';
$recipient = new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_RECIPIENT'), 'recipient', 50, 255, $authorMail);
$recipient->setExtra('disabled="disabled"');
$form->addElement($recipient);
$your_name = new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME'), 'your_name', 50, 255, $this->name);
Expand Down
4 changes: 2 additions & 2 deletions class/Common/ModuleStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ trait ModuleStats
{
/**
* @param \XoopsModules\Modulebuilder\Common\Configurator $configurator
* @param array $moduleStats
* @param array $moduleStats
* @return array
*/
public static function getModuleStats($configurator, $moduleStats)
public static function getModuleStats(Configurator $configurator, array $moduleStats)
{
if (\count($configurator->moduleStats) > 0) {
foreach (\array_keys($configurator->moduleStats) as $i) {
Expand Down
14 changes: 7 additions & 7 deletions class/Common/SysUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ public static function getInstance()
* www.cakephp.org
*
* @param string $text String to truncate.
* @param int $length Length of returned string, including ellipsis.
* @param int $length Length of returned string, including ellipsis.
* @param string $ending Ending to be appended to the trimmed string.
* @param bool $exact If false, $text will not be cut mid-word
* @param bool $considerHtml If true, HTML tags would be handled correctly
* @param bool $exact If false, $text will not be cut mid-word
* @param bool $considerHtml If true, HTML tags would be handled correctly
*
* @return string Trimmed string.
*/
public static function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true)
public static function truncateHtml(string $text, int $length = 100, string $ending = '...', bool $exact = false, bool $considerHtml = true)
{
if ($considerHtml) {
// if the plain text is shorter than the maximum length, return the whole text
Expand Down Expand Up @@ -161,11 +161,11 @@ public static function truncateHtml($text, $length = 100, $ending = '...', $exac
}

/**
* @param \Xmf\Module\Helper $helper
* @param array|null $options
* @param \Xmf\Module\Helper|null $helper
* @param array|null $options
* @return \XoopsFormDhtmlTextArea|\XoopsFormEditor
*/
public static function getEditor($helper = null, $options = null)
public static function getEditor(\Xmf\Module\Helper $helper = null, array $options = null)
{
/** @var Helper $helper */
if (null === $options) {
Expand Down
20 changes: 9 additions & 11 deletions class/Common/TableChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
public const CHECKTYPE_UPDATE_REPORT = 2; //update and report

/**
* @param \XoopsModules\Modulebuilder\Common\TableChecker|null
* @param mixed $mydirname
* @param mixed $checktype
*/
Expand All @@ -72,7 +71,7 @@
if ($numRows) {
//table exist
$this->result[] = 'Table exist:' . $table;
$ret = $this->checkTableFields($table, $tabledef['fields']);
//$ret = $this->checkTableFields($table, $tabledef['fields']);
} else {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if ($this::CHECKTYPE_UPDATE == $this->checktype || $this::CHECKTYPE_UPDATE_REPORT == $this->checktype) {
// create new table
Expand All @@ -92,6 +91,8 @@
if (self::CHECKTYPE_REPORT == $this->checktype || self::CHECKTYPE_UPDATE_REPORT == $this->checktype) {
return $this->result;
}

return [];
}

private function readSQLFile()
Expand Down Expand Up @@ -156,11 +157,9 @@
{
//todo: split string into single keys
$needle = '(';
$key_text = \substr($line, \strpos($line, $needle, 0) + 1);
$key_text = \substr($line, \strpos($line, $needle) + 1);
$needle = ')';
$key_text = \substr($key_text, 0, \strpos($key_text, $needle, 0));

return $key_text;
return \substr($key_text, 0, \strpos($key_text, $needle));
}

private function extractField($line)
Expand Down Expand Up @@ -191,7 +190,7 @@
if (\count($params) > $counter) {
if ('default' == \mb_strtolower($params[$counter])) {
$field['default'] = $params[$counter] . ' ' . $params[$counter + 1];
$counter = $counter + 2;
//$counter = $counter + 2;

Check warning on line 193 in class/Common/TableChecker.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this commented out code.

See more on https://sonarcloud.io/project/issues?id=XoopsModules25x_modulebuilder&issues=AZ1n-0s0jlhxMrVTDax2&open=AZ1n-0s0jlhxMrVTDax2&pullRequest=173
}
}

Expand All @@ -211,15 +210,15 @@
$numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
if ($numRows) {
//field exist
$this->checkField($table, $field);
$this->checkField($field);
} else {
if (self::CHECKTYPE_UPDATE == $this->checktype || self::CHECKTYPE_UPDATE_REPORT == $this->checktype) {
// create new field
$sql = "ALTER TABLE `$table` ADD " . $field['sql'];
if ('' !== (string)$field['after']) {
$sql .= ' AFTER `' . $field['after'] . '`;';
}
if ($result = $GLOBALS['xoopsDB']->queryF($sql)) {
if ($GLOBALS['xoopsDB']->queryF($sql)) {
$this->result[] = 'Field added:' . $fieldname;
} else {
\xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
Expand All @@ -234,11 +233,10 @@
return true;
}

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

return true;
}
}
8 changes: 4 additions & 4 deletions class/Common/TestdataButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TestdataButtons
*
* @return void
*/
public static function loadButtonConfig($adminObject): void
public static function loadButtonConfig(\Xmf\Module\Admin $adminObject): void
{
$moduleDirName = \basename(\dirname(__DIR__, 2));
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
Expand All @@ -52,13 +52,13 @@ public static function loadButtonConfig($adminObject): void

if (self::SHOW_BUTTONS == $displaySampleButton) {
\xoops_loadLanguage('admin/modulesadmin', 'system');
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'), 'add');
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'), 'add');
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'LOAD_SAMPLEDATA'), $helper->url('testdata/index.php?op=load'));
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), $helper->url('testdata/index.php?op=save'));
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'CLEAR_SAMPLEDATA'), $helper->url('testdata/index.php?op=clear'), 'alert');
// $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), $helper->url( 'testdata/index.php?op=exportschema'), 'add');
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
} else {
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
$adminObject->addItemButton(\constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons');
// $displaySampleButton = $config['displaySampleButton'];
}
}
Expand Down
2 changes: 1 addition & 1 deletion class/Common/VersionChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function checkVerXoops(\XoopsModule $module = null, $requiredVer =
}
$success = true;

if ($module->versionCompare($currentVer, $requiredVer, '<')) {
if ($module->versionCompare($currentVer, $requiredVer)) {
$success = false;
$module->setErrors(\sprintf(\constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer));
}
Expand Down
18 changes: 10 additions & 8 deletions class/Devtools.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,10 @@ public static function function_tabreplacer($src_path, $dst_path): void
* @param $dst_path
* @param array $patKeys
* @param array $patValues
* @param bool $replaceTabs
* @param bool $replaceTabs
* @param string[] $extensions
*/
public static function cloneFileFolder($src_path, $dst_path, $patKeys = [], $patValues = [], $replaceTabs = false, $extensions = ['php']): void
public static function cloneFileFolder($src_path, $dst_path, array $patKeys = [], array $patValues = [], bool $replaceTabs = false, $extensions = ['php']): void
{
// open the source directory
$dir = \opendir($src_path);
Expand All @@ -463,9 +464,10 @@ public static function cloneFileFolder($src_path, $dst_path, $patKeys = [], $pat
* @param $dst_file
* @param array $patKeys
* @param array $patValues
* @param bool $replaceTabs
* @param bool $replaceTabs
* @param $extensions
*/
private static function cloneFile($src_file, $dst_file, $patKeys, $patValues, $replaceTabs, $extensions): void
private static function cloneFile($src_file, $dst_file, array $patKeys, array $patValues, bool $replaceTabs, $extensions): void
{
$replace_code = false;
if (\in_array(\mb_strtolower(\pathinfo($src_file, PATHINFO_EXTENSION)), $extensions)) {
Expand Down Expand Up @@ -499,7 +501,7 @@ private static function cloneFile($src_file, $dst_file, $patKeys, $patValues, $r
* @param bool $action
* @return \XoopsSimpleForm
*/
public static function getFormModulesFq($action = false)
public static function getFormModulesFq(bool $action = false)
{
if (!$action) {
$action = $_SERVER['REQUEST_URI'];
Expand Down Expand Up @@ -528,7 +530,7 @@ public static function getFormModulesFq($action = false)
* @param bool $action
* @return \XoopsSimpleForm
*/
public static function getFormModulesCl($action = false)
public static function getFormModulesCl(bool $action = false)
{
if (!$action) {
$action = $_SERVER['REQUEST_URI'];
Expand Down Expand Up @@ -557,7 +559,7 @@ public static function getFormModulesCl($action = false)
* @param bool $action
* @return \XoopsSimpleForm
*/
public static function getFormModulesTab($action = false)
public static function getFormModulesTab(bool $action = false)
{
if (!$action) {
$action = $_SERVER['REQUEST_URI'];
Expand Down Expand Up @@ -586,7 +588,7 @@ public static function getFormModulesTab($action = false)
* @param bool $action
* @return \XoopsSimpleForm
*/
public static function getFormModulesRemovePrefix($dst_path, $action = false)
public static function getFormModulesRemovePrefix($dst_path, bool $action = false)
{
if (!$action) {
$action = $_SERVER['REQUEST_URI'];
Expand Down
Loading