Skip to content

Commit

Permalink
Merge branch 'develop' into fix_element_type_part_03
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy authored Mar 9, 2024
2 parents defc98f + a8444e7 commit f4713ad
Show file tree
Hide file tree
Showing 86 changed files with 545 additions and 352 deletions.
1 change: 1 addition & 0 deletions dev/tools/codespell/codespell-lines-ignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
if (empty($this->datea)) {
if (in_array('01', $TWeek) && in_array('52', $TWeek) && $weekNb == '01') {
print $form->selectDate(strtotime(date('Y-m-d', $object->datee)), 'end', '', '', 0, '', 1, 0);
print $form->selectDate(strtotime(date('Y-m-d', $object->datee)), 'end', 0, 0, 0, '', 1, 0);
print $object->datee ? dol_print_date($object->datee, 'daytext') : ' ';
print '<input type="hidden" name="action" value="addin">';
print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
Expand Down
1 change: 1 addition & 0 deletions dev/tools/phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
// Dolibarr uses a lot of internal deprecated stuff, not reporting
'PhanDeprecatedProperty',
'PhanDeprecatedFunction',
'PhanCompatibleNegativeStringOffset',
// Dolibarr has quite a few strange noop assignments like $abc=$abc;
'PhanPluginDuplicateExpressionAssignment',
// Nulls are likely mostly false positives
Expand Down
3 changes: 3 additions & 0 deletions dev/tools/phan/config_extended.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@
// Add any issue types (such as 'PhanUndeclaredMethod')
// here to inhibit them from being reported
'suppress_issue_types' => [
'PhanCompatibleNegativeStringOffset', // return false positive

'PhanPluginWhitespaceTab', // Dolibarr used tabs
'PhanPluginCanUsePHP71Void', // Dolibarr is maintaining 7.0 compatibility
'PhanPluginShortArray', // Dolibarr uses array()
Expand All @@ -335,6 +337,7 @@
'PhanPluginCanUseReturnType', // Fixer - Report/Add return types in the function definition (function abc(string $var) (adds string)
'PhanPluginCanUseNullableParamType', // Fixer - Report/Add nullable parameter types in the function definition
'PhanPluginCanUseNullableReturnType', // Fixer - Report/Add nullable return types in the function definition

'PhanPluginNonBoolBranch', // Not essential - 31240+ occurrences
'PhanPluginNumericalComparison', // Not essential - 19870+ occurrences
'PhanTypeMismatchArgument', // Not essential - 12300+ occurrences
Expand Down
3 changes: 3 additions & 0 deletions dev/tools/phan/config_fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//require_once __DIR__.'/plugins/DeprecatedModuleNameFixer.php';
//require_once __DIR__.'/plugins/PriceFormFixer.php';
//require_once __DIR__.'/plugins/UrlEncodeStringifyFixer.php';
require_once __DIR__.'/plugins/SelectDateFixer.php';

/* Copyright (C) 2024 MDW <[email protected]>
*/
Expand Down Expand Up @@ -176,6 +177,8 @@
// Add any issue types (such as 'PhanUndeclaredMethod')
// here to inhibit them from being reported
'suppress_issue_types' => [
'PhanCompatibleNegativeStringOffset', // return false positive

'PhanPluginWhitespaceTab', // Dolibarr used tabs
'PhanPluginCanUsePHP71Void', // Dolibarr is maintaining 7.0 compatibility
'PhanPluginShortArray', // Dolibarr uses array()
Expand Down
175 changes: 175 additions & 0 deletions dev/tools/phan/plugins/SelectDateFixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?php
/* Copyright (C) 2024 MDW <[email protected]>
*
* For 'price()', replace $form parameter that is '' with 0.
*/

declare(strict_types=1);

use ast\flags;
use Microsoft\PhpParser\Node\Expression\CallExpression;
use Microsoft\PhpParser\Node\QualifiedName;
use Phan\AST\TolerantASTConverter\NodeUtils;
use Phan\CodeBase;
use Phan\IssueInstance;
use Phan\Library\FileCacheEntry;
use Phan\Plugin\Internal\IssueFixingPlugin\FileEdit;
use Phan\Plugin\Internal\IssueFixingPlugin\FileEditSet;
use Phan\Plugin\Internal\IssueFixingPlugin\IssueFixer;
use Microsoft\PhpParser\Node\Expression\ArgumentExpression;
use Microsoft\PhpParser\Node\DelimitedList\ArgumentExpressionList;
use Microsoft\PhpParser\Node\StringLiteral;
use Microsoft\PhpParser\Node\ReservedWord;
use Microsoft\PhpParser\Token;

/**
* This is a prototype, there are various features it does not implement.
*/

call_user_func(static function (): void {
/**
* @param $code_base @unused-param
* @return ?FileEditSet a representation of the edit to make to replace a call to a function alias with a call to the original function
*/
$fix = static function (CodeBase $code_base, FileCacheEntry $contents, IssueInstance $instance): ?FileEditSet {

// Argument {INDEX} (${PARAMETER}) is {CODE} of type {TYPE}{DETAILS} but
// {FUNCTIONLIKE} takes {TYPE}{DETAILS} defined at {FILE}:{LINE} (the inferred real argument type has nothing in common with the parameter's phpdoc type)

//htdocs\supplier_proposal\card.php:1705 PhanTypeMismatchArgumentProbablyReal Argument 3 ($h) is '' of type '' but \Form::selectDate() takes int (no real type) defined at htdocs\core\class\html.form.class.php:6799 (the inferred real argument type has nothing in common with the parameter's phpdoc type)
//htdocs\supplier_proposal\card.php:1705 PhanTypeMismatchArgumentProbablyReal Argument 4 ($m) is '' of type '' but \Form::selectDate() takes int (no real type) defined at htdocs\core\class\html.form.class.php:6799 (the inferred real argument type has nothing in common with the parameter's phpdoc type)

$argument_index = (string) $instance->getTemplateParameters()[0];
$argument_name = (string) $instance->getTemplateParameters()[1];
$argument_code = (string) $instance->getTemplateParameters()[2];
$argument_type = (string) $instance->getTemplateParameters()[3];
$details = (string) $instance->getTemplateParameters()[4];
$functionlike = (string) $instance->getTemplateParameters()[5];

$expected_functionlike = "\\Form::selectDate()";
$expected_name = "selectDate";
if ($functionlike !== $expected_functionlike) {
print "$functionlike != '$expected_functionlike'".PHP_EOL;
return null;
}

// Check if we fix any of this
if (
($argument_name === 'h' && $argument_code === "''")
|| ($argument_name === 'm' && $argument_code === "''")
|| ($argument_name === 'empty' && $argument_code === "''")
) {
$replacement = '0';
$argIdx = ($argument_index - 1) * 2;
$expectedStringValue = "";
} else {
print "ARG$argument_index:$argument_name CODE:$argument_code".PHP_EOL;
return null;
}

// At this point we established that the notification
// matches some we fix.

$line = $instance->getLine();

$edits = [];
foreach ($contents->getNodesAtLine($line) as $node) {
if (!$node instanceof ArgumentExpressionList) {
continue;
}
$arguments = $node->children;
if (count($arguments) <= $argIdx) {
// print "Arg Count is ".count($arguments)." - Skip $instance".PHP_EOL;
continue;
}

$is_actual_call = $node->parent instanceof CallExpression;
if (!$is_actual_call) {
// print "Not actual call - Skip $instance".PHP_EOL;
continue;
}

print "Actual call - $instance".PHP_EOL;
$callable = $node->parent;

$callableExpression = $callable->callableExpression;

if ($callableExpression instanceof Microsoft\PhpParser\Node\QualifiedName) {
$actual_name = $callableExpression->getResolvedName();
} elseif ($callableExpression instanceof Microsoft\PhpParser\Node\Expression\MemberAccessExpression) {
$memberNameToken = $callableExpression->memberName;
$actual_name = (new NodeUtils($contents->getContents()))->tokenToString($memberNameToken);
} else {
print "Callable expression is ".get_class($callableExpression)."- Skip $instance".PHP_EOL;
continue;
}

if ((string) $actual_name !== (string) $expected_name) {
// print "Name unexpected '$actual_name'!='$expected_name' - Skip $instance".PHP_EOL;
continue;
}

foreach ($arguments as $i => $argument) {
if ($argument instanceof ArgumentExpression) {
print "Type$i: ".get_class($argument->expression).PHP_EOL;
}
}

$stringValue = null;


$arg = $arguments[$argIdx];

if (
$arg instanceof ArgumentExpression
&& $arg->expression instanceof StringLiteral
) {
// Get the string value of the StringLiteral
$stringValue = $arg->expression->getStringContentsText();
print "String is '$stringValue'".PHP_EOL;
} elseif ($arg instanceof ArgumentExpression && $arg->expression instanceof ReservedWord) {
$child = $arg->expression->children;
if (!$child instanceof Token) {
continue;
}
$token_str = (new NodeUtils($contents->getContents()))->tokenToString($child);
print "$token_str KIND:".($child->kind ?? 'no kind')." ".get_class($child).PHP_EOL;

if ($token_str !== 'null') {
continue;
}

$stringValue = ''; // Fake empty
} else {
print "Expression is not string or null ".get_class($arg)."/".get_class($arg->expression)."- Skip $instance".PHP_EOL;
continue;
}

if ($stringValue !== $expectedStringValue) {
print "Not replacing $argument_name which is '$stringValue'/".get_class($arg)."/".get_class($arg->expression)."- Skip $instance".PHP_EOL;
continue;
}

print "Fixture elem on $line - $actual_name(...'$stringValue'...) - $instance".PHP_EOL;



// Get the first argument (delimiter)
$argument_to_replace = $arg;

$arg_start_pos = $argument_to_replace->getStartPosition();
$arg_end_pos = $argument_to_replace->getEndPosition();

// Set edit instruction
$edits[] = new FileEdit($arg_start_pos, $arg_end_pos, $replacement);
}
if ($edits) {
return new FileEditSet($edits);
}
return null;
};
IssueFixer::registerFixerClosure(
'PhanTypeMismatchArgumentProbablyReal',
$fix
);
});
4 changes: 2 additions & 2 deletions htdocs/accountancy/bookkeeping/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
print '<tr>';
print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Docdate").'</td>';
print '<td>';
print $form->selectDate('', 'doc_date', '', '', '', "create_mvt", 1, 1);
print $form->selectDate('', 'doc_date', 0, 0, 0, "create_mvt", 1, 1);
print '</td>';
print '</tr>';

Expand Down Expand Up @@ -459,7 +459,7 @@
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setdate">';
print '<input type="hidden" name="mode" value="'.$mode.'">';
print $form->selectDate($object->doc_date ? $object->doc_date : - 1, 'doc_date', '', '', '', "setdate");
print $form->selectDate($object->doc_date ? $object->doc_date : - 1, 'doc_date', 0, 0, 0, "setdate");
print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
print '</form>';
} else {
Expand Down
4 changes: 2 additions & 2 deletions htdocs/adherents/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ function initfieldrequired() {

// Birth Date
print "<tr><td>".$langs->trans("DateOfBirth")."</td><td>\n";
print img_picto('', 'object_calendar', 'class="pictofixedwidth"').$form->selectDate(($object->birth ? $object->birth : -1), 'birth', '', '', 1, 'formsoc');
print img_picto('', 'object_calendar', 'class="pictofixedwidth"').$form->selectDate(($object->birth ? $object->birth : -1), 'birth', 0, 0, 1, 'formsoc');
print "</td></tr>\n";

// Public profil
Expand Down Expand Up @@ -1365,7 +1365,7 @@ function initfieldrequired() {

// Birth Date
print "<tr><td>".$langs->trans("DateOfBirth")."</td><td>\n";
print img_picto('', 'object_calendar', 'class="pictofixedwidth"').$form->selectDate(($object->birth ? $object->birth : -1), 'birth', '', '', 1, 'formsoc');
print img_picto('', 'object_calendar', 'class="pictofixedwidth"').$form->selectDate(($object->birth ? $object->birth : -1), 'birth', 0, 0, 1, 'formsoc');
print "</td></tr>\n";

// Default language
Expand Down
4 changes: 2 additions & 2 deletions htdocs/adherents/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@
$datefrom = dol_get_first_day(dol_print_date($datefrom, "%Y"));
}
}
print $form->selectDate($datefrom, '', '', '', '', "subscription", 1, 1);
print $form->selectDate($datefrom, '', 0, 0, 0, "subscription", 1, 1);
print "</td></tr>";

// Date end subscription
Expand All @@ -1013,7 +1013,7 @@
}
}
print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
print $form->selectDate($dateto, 'end', '', '', '', "subscription", 1, 0);
print $form->selectDate($dateto, 'end', 0, 0, 0, "subscription", 1, 0);
print "</td></tr>";

if ($adht->subscription) {
Expand Down
8 changes: 4 additions & 4 deletions htdocs/admin/expensereport_rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@

echo '<td class="linecoltype">' . $form->selectExpense('', 'fk_c_type_fees', 0, 1, 1) . '</td>';
echo '<td class="linecoltyperule">' . $form->selectarray('code_expense_rules_type', $tab_rules_type, '', 0) . '</td>';
echo '<td class="linecoldatestart">' . $form->selectDate(strtotime(date('Y-m-01', dol_now())), 'start', '', '', 0, '', 1, 0) . '</td>';
echo '<td class="linecoldateend">' . $form->selectDate(strtotime(date('Y-m-t', dol_now())), 'end', '', '', 0, '', 1, 0) . '</td>';
echo '<td class="linecoldatestart">' . $form->selectDate(strtotime(date('Y-m-01', dol_now())), 'start', 0, 0, 0, '', 1, 0) . '</td>';
echo '<td class="linecoldateend">' . $form->selectDate(strtotime(date('Y-m-t', dol_now())), 'end', 0, 0, 0, '', 1, 0) . '</td>';
echo '<td class="linecolamount"><input type="text" value="" class="maxwidth100" name="amount" class="amount right" /></td>';
echo '<td class="linecolrestrictive">' . $form->selectyesno('restrictive', 0, 1) . '</td>';
echo '<td class="right linecolbutton"><input type="submit" class="button button-add" value="' . $langs->trans('Add') . '" /></td>';
Expand Down Expand Up @@ -308,7 +308,7 @@

echo '<td class="linecoldatestart">';
if ($action == 'edit' && $object->id == $rule->id) {
print $form->selectDate(strtotime(date('Y-m-d', $object->dates)), 'start', '', '', 0, '', 1, 0);
print $form->selectDate(strtotime(date('Y-m-d', $object->dates)), 'start', 0, 0, 0, '', 1, 0);
} else {
echo dol_print_date($rule->dates, 'day');
}
Expand All @@ -317,7 +317,7 @@

echo '<td class="linecoldateend">';
if ($action == 'edit' && $object->id == $rule->id) {
print $form->selectDate(strtotime(date('Y-m-d', $object->datee)), 'end', '', '', 0, '', 1, 0);
print $form->selectDate(strtotime(date('Y-m-d', $object->datee)), 'end', 0, 0, 0, '', 1, 0);
} else {
echo dol_print_date($rule->datee, 'day');
}
Expand Down
10 changes: 5 additions & 5 deletions htdocs/comm/propal/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,7 @@
// Date
print '<tr class="field_addprop"><td class="titlefieldcreate fieldrequired">'.$langs->trans('DatePropal').'</td><td class="valuefieldcreate">';
print img_picto('', 'action', 'class="pictofixedwidth"');
print $form->selectDate('', '', '', '', '', "addprop", 1, 1);
print $form->selectDate('', '', 0, 0, 0, "addprop", 1, 1);
print '</td></tr>';

// Validaty duration
Expand Down Expand Up @@ -2042,9 +2042,9 @@
$syear = date("Y", $tmpdte);
$smonth = date("m", $tmpdte);
$sday = date("d", $tmpdte);
print $form->selectDate($syear."-".$smonth."-".$sday, 'date_livraison', '', '', '', "addprop");
print $form->selectDate($syear."-".$smonth."-".$sday, 'date_livraison', 0, 0, 0, "addprop");
} else {
print $form->selectDate(-1, 'date_livraison', '', '', '', "addprop", 1, 1);
print $form->selectDate(-1, 'date_livraison', 0, 0, 0, "addprop", 1, 1);
}
print '</td></tr>';

Expand Down Expand Up @@ -2582,7 +2582,7 @@
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setdate">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
print $form->selectDate($object->date, 're', '', '', 0, "editdate");
print $form->selectDate($object->date, 're', 0, 0, 0, "editdate");
print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
print '</form>';
} else {
Expand Down Expand Up @@ -2610,7 +2610,7 @@
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setecheance">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
print $form->selectDate($object->fin_validite, 'ech', '', '', '', "editecheance");
print $form->selectDate($object->fin_validite, 'ech', 0, 0, 0, "editecheance");
print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
print '</form>';
} else {
Expand Down
4 changes: 2 additions & 2 deletions htdocs/comm/propal/class/propal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,7 @@ public function closeProposal($user, $status, $note = '', $notrigger = 0)
$resql = $this->db->query($sql);
if ($resql) {
// Status self::STATUS_REFUSED by default
$modelpdf = getDolGlobalString('PROPALE_ADDON_PDF_ODT_CLOSED') ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->model_pdf;
$modelpdf = getDolGlobalString('PROPALE_ADDON_PDF_ODT_CLOSED', $this->model_pdf);
$trigger_name = 'PROPAL_CLOSE_REFUSED'; // used later in call_trigger()

if ($status == self::STATUS_SIGNED) { // Status self::STATUS_SIGNED
Expand Down Expand Up @@ -2814,7 +2814,7 @@ public function classifyBilled(User $user, $notrigger = 0, $note = '')
}

if (!$error) {
$modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->model_pdf;
$modelpdf = getDolGlobalString('PROPALE_ADDON_PDF_ODT_CLOSED', $this->model_pdf);

if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
// Define output language
Expand Down
6 changes: 3 additions & 3 deletions htdocs/commande/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@
// Date
print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td>';
print img_picto('', 'action', 'class="pictofixedwidth"');
print $form->selectDate('', 're', '', '', '', "crea_commande", 1, 1); // Always autofill date with current date
print $form->selectDate('', 're', 0, 0, 0, "crea_commande", 1, 1); // Always autofill date with current date
print '</td></tr>';

// Date delivery planned
Expand Down Expand Up @@ -2546,7 +2546,7 @@
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setdate">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
print $form->selectDate($object->date, 'order_', '', '', '', "setdate");
print $form->selectDate($object->date, 'order_', 0, 0, 0, "setdate");
print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
print '</form>';
} else {
Expand All @@ -2568,7 +2568,7 @@
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setdate_livraison">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
print $form->selectDate($object->delivery_date ? $object->delivery_date : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0);
print $form->selectDate($object->delivery_date ? $object->delivery_date : -1, 'liv_', 1, 1, 0, "setdate_livraison", 1, 0);
print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
print '</form>';
} else {
Expand Down
Loading

0 comments on commit f4713ad

Please sign in to comment.