Skip to content

Commit

Permalink
Qual: Fixes for modulebuilder (phan, phpstan, bugs, format)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Aug 17, 2024
1 parent e9b2f1e commit 136aa05
Show file tree
Hide file tree
Showing 40 changed files with 833 additions and 649 deletions.
6 changes: 5 additions & 1 deletion htdocs/api/class/api.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,14 @@ protected function _filterObjectProperties($object, $properties)

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Clean sensible object datas
* Clean sensitive object data
* @phpstan-template T of Object
*
* @param Object $object Object to clean
* @return Object Object with cleaned properties
*
* @phpstan-param T $object
* @phpstan-return T
*/
protected function _cleanObjectDatas($object)
{
Expand Down
306 changes: 153 additions & 153 deletions htdocs/core/lib/modulebuilder.lib.php

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion htdocs/core/modules/mailings/modules_mailings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <[email protected]>
* Copyright (C) 2004-2008 Laurent Destailleur <[email protected]>
* Copyright (C) 2004 Eric Seigne <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -390,6 +391,7 @@ public static function getEmailingSelectorsList($forcedir = null)

$objMod = new $modName($db);
if (is_object($objMod)) {
'@phan-var-force ModeleBoxes $objMod';
// Define disabledbyname and disabledbymodule
$disabledbyname = 0;
$disabledbymodule = 0; // TODO Set to 2 if module is not enabled
Expand All @@ -400,7 +402,7 @@ public static function getEmailingSelectorsList($forcedir = null)
$disabledbyname = 1;
}

// We set info of modules
// We set info of modules @phan-suppress-next-line PhanUndeclaredProperty
$widget[$j]['picto'] = (empty($objMod->picto) ? (empty($objMod->boximg) ? img_object('', 'generic') : $objMod->boximg) : img_object('', $objMod->picto));
$widget[$j]['file'] = $files[$key];
$widget[$j]['fullpath'] = $fullpath[$key];
Expand Down
326 changes: 207 additions & 119 deletions htdocs/modulebuilder/index.php

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions htdocs/modulebuilder/template/admin/about.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2004-2017 Laurent Destailleur <[email protected]>
* Copyright (C) ---Put here your own copyright and developer email---
* Copyright (C) ---Replace with your own copyright and developer email---
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -29,7 +29,10 @@
$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
}
// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
$tmp2 = realpath(__FILE__);
$i = strlen($tmp) - 1;
$j = strlen($tmp2) - 1;
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
$i--;
$j--;
Expand Down
5 changes: 4 additions & 1 deletion htdocs/modulebuilder/template/admin/myobject_extrafields.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
}
// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
$tmp2 = realpath(__FILE__);
$i = strlen($tmp) - 1;
$j = strlen($tmp2) - 1;
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
$i--;
$j--;
Expand Down
15 changes: 7 additions & 8 deletions htdocs/modulebuilder/template/admin/setup.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
/* Copyright (C) 2004-2017 Laurent Destailleur <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) ---Put here your own copyright and developer email---
* Copyright (C) ---Replace with your own copyright and developer email---
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -218,26 +217,26 @@

$className = $myTmpObjects[$tmpobjectkey]['class'];
$tmpobject = new $className($db);
'@phan-var-force MyObject $tmpobject';
$tmpobject->initAsSpecimen();

// Search template files
$file = '';
$className = '';
$filefound = 0;
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
foreach ($dirmodels as $reldir) {
$file = dol_buildpath($reldir."core/modules/mymodule/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
if (file_exists($file)) {
$filefound = 1;
$className = "pdf_".$modele."_".strtolower($tmpobjectkey);
break;
}
}

if ($filefound) {
if ($className !== '') {
require_once $file;

$module = new $className($db);
'@phan-var-force ModelePDFMyObject $module';

'@phan-var-force ModelePDFMyObject $module';

Expand Down Expand Up @@ -372,8 +371,7 @@
require_once $dir.'/'.$file.'.php';

$module = new $file($db);

'@phan-var-force CommonNumRefGenerator $module';
'@phan-var-force ModeleNumRefMyObject $module';

// Show modules according to features level
if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
Expand Down Expand Up @@ -416,6 +414,7 @@

$className = $myTmpObjectArray['class'];
$mytmpinstance = new $className($db);
'@phan-var-force MyObject $mytmpinstance';
$mytmpinstance->initAsSpecimen();

// Info
Expand Down Expand Up @@ -498,6 +497,7 @@
if (is_dir($dir)) {
$handle = opendir($dir);
if (is_resource($handle)) {
$filelist = array();
while (($file = readdir($handle)) !== false) {
$filelist[] = $file;
}
Expand All @@ -512,7 +512,6 @@

require_once $dir.'/'.$file;
$module = new $className($db);

'@phan-var-force ModelePDFMyObject $module';

$modulequalified = 1;
Expand Down
Loading

0 comments on commit 136aa05

Please sign in to comment.