Skip to content

Commit

Permalink
Qual: Fix phan notices (mrp)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Feb 7, 2025
1 parent c316d1e commit 5fe465b
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 130 deletions.
26 changes: 7 additions & 19 deletions dev/tools/phan/baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
*/
return [
// # Issue statistics:
// PhanTypeMismatchArgument : 2490+ occurrences
// PhanTypeMismatchArgument : 2450+ occurrences
// PhanUndeclaredProperty : 530+ occurrences
// PhanTypeMismatchArgumentNullable : 430+ occurrences
// PhanUndeclaredGlobalVariable : 190+ occurrences
// PhanPluginUnknownArrayMethodReturnType : 180+ occurrences
// PhanPluginUnknownArrayMethodReturnType : 170+ occurrences
// PhanPossiblyUndeclaredGlobalVariable : 160+ occurrences
// PhanTypeMismatchProperty : 130+ occurrences
// PhanTypeMismatchArgumentProbablyReal : 120+ occurrences
Expand All @@ -27,8 +27,8 @@ return [
// PhanUndeclaredConstant : 15+ occurrences
// PhanTypeComparisonFromArray : 10+ occurrences
// PhanUndeclaredMethod : 10+ occurrences
// PhanPluginUnknownObjectMethodCall : 8 occurrences
// PhanPluginSuspiciousParamPosition : 7 occurrences
// PhanPluginUnknownObjectMethodCall : 7 occurrences
// PhanPluginDuplicateExpressionBinaryOp : 6 occurrences
// PhanPluginEmptyStatementIf : 6 occurrences
// PhanTypeArraySuspiciousNull : 6 occurrences
Expand Down Expand Up @@ -123,7 +123,6 @@ return [
'htdocs/admin/mails_templates.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'],
'htdocs/admin/mails_ticket.php' => ['PhanTypeMismatchArgumentNullable'],
'htdocs/admin/menus/index.php' => ['PhanTypeMismatchArgument'],
'htdocs/admin/mrp.php' => ['PhanTypeMismatchArgument'],
'htdocs/admin/multicurrency.php' => ['PhanTypeMismatchArgument'],
'htdocs/admin/order.php' => ['PhanTypeMismatchArgument'],
'htdocs/admin/payment.php' => ['PhanTypeMismatchArgument'],
Expand Down Expand Up @@ -466,7 +465,7 @@ return [
'htdocs/core/modules/modSupplierProposal.class.php' => ['PhanTypeMismatchArgument'],
'htdocs/core/modules/modTicket.class.php' => ['PhanTypeMismatchArgument'],
'htdocs/core/modules/movement/doc/pdf_standard_movementstock.modules.php' => ['PhanTypeMismatchArgument'],
'htdocs/core/modules/mrp/doc/pdf_vinci.modules.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'],
'htdocs/core/modules/mrp/doc/pdf_vinci.modules.php' => ['PhanUndeclaredProperty'],
'htdocs/core/modules/mrp/mod_mo_advanced.php' => ['PhanUndeclaredProperty'],
'htdocs/core/modules/oauth/github_oauthcallback.php' => ['PhanUndeclaredGlobalVariable'],
'htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php' => ['PhanTypeMismatchArgument'],
Expand Down Expand Up @@ -608,20 +607,9 @@ return [
'htdocs/loan/document.php' => ['PhanUndeclaredProperty'],
'htdocs/loan/note.php' => ['PhanUndeclaredProperty'],
'htdocs/loan/payment/payment.php' => ['PhanUndeclaredProperty'],
'htdocs/mrp/ajax/ajax_bom.php' => ['PhanTypeMismatchArgument'],
'htdocs/mrp/class/api_mos.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument'],
'htdocs/mrp/class/mo.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'],
'htdocs/mrp/class/moline.class.php' => ['PhanTypeMismatchArgument'],
'htdocs/mrp/index.php' => ['PhanTypeMismatchArgument'],
'htdocs/mrp/mo_agenda.php' => ['PhanTypeMismatchArgument'],
'htdocs/mrp/mo_card.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentProbablyReal'],
'htdocs/mrp/mo_document.php' => ['PhanTypeMismatchArgument'],
'htdocs/mrp/mo_list.php' => ['PhanTypeMismatchArgument'],
'htdocs/mrp/mo_movements.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanTypeMismatchArgument', 'PhanUndeclaredGlobalVariable'],
'htdocs/mrp/mo_note.php' => ['PhanTypeMismatchArgument'],
'htdocs/mrp/mo_production.php' => ['PhanTypeMismatchArgument'],
'htdocs/mrp/tpl/linkedobjectblock.tpl.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'],
'htdocs/mrp/tpl/originproductline.tpl.php' => ['PhanUndeclaredProperty'],
'htdocs/mrp/class/mo.class.php' => ['PhanTypeMismatchProperty'],
'htdocs/mrp/mo_movements.php' => ['PhanUndeclaredGlobalVariable'],
'htdocs/mrp/tpl/linkedobjectblock.tpl.php' => ['PhanUndeclaredProperty'],
'htdocs/multicurrency/class/api_multicurrencies.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument'],
'htdocs/multicurrency/class/multicurrency.class.php' => ['PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchArgument'],
'htdocs/multicurrency/multicurrency_rate.php' => ['PhanTypeMismatchArgument'],
Expand Down
13 changes: 7 additions & 6 deletions htdocs/admin/mrp.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2019 Laurent Destailleur <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -35,7 +35,6 @@
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Societe $mysoc
* @var Translate $langs
* @var User $user
*/
Expand Down Expand Up @@ -263,13 +262,15 @@

$mrp = new Mo($db);
$mrp->initAsSpecimen();
$product = new Product($db);
$product->initAsSpecimen();

// Info
$htmltooltip = '';
$htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
$mrp->type = 0;
$nextval = $module->getNextValue($mysoc, $mrp);
if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
$nextval = $module->getNextValue($product, $mrp);
if ((string) $nextval != $langs->trans("NotAvailable")) {
$htmltooltip .= ''.$langs->trans("NextValue").': ';
if ($nextval) {
if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
Expand All @@ -282,7 +283,7 @@
}

print '<td class="center">';
print $form->textwithpicto('', $htmltooltip, 1, 0);
print $form->textwithpicto('', $htmltooltip, 1, 'info');
print '</td>';

print "</tr>\n";
Expand Down Expand Up @@ -417,7 +418,7 @@


print '<td class="center">';
print $form->textwithpicto('', $htmltooltip, 1, 0);
print $form->textwithpicto('', $htmltooltip, 1, 'info');
print '</td>';

// Preview
Expand Down
6 changes: 3 additions & 3 deletions htdocs/core/modules/mrp/doc/pdf_vinci.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,15 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
// Enough for 6 chars
if ($this->getColumnStatus('qty')) {
$qty = $bom->lines[$i]->qty;
$this->printStdColumnContent($pdf, $curY, 'qty', $qty);
$this->printStdColumnContent($pdf, $curY, 'qty', (string) $qty);
$nexY = max($pdf->GetY(), $nexY);
}

// Quantity
// Enough for 6 chars
if ($this->getColumnStatus('qtytot')) {
$qtytot = $object->qty * $bom->lines[$i]->qty;
$this->printStdColumnContent($pdf, $curY, 'qtytot', $qtytot);
$this->printStdColumnContent($pdf, $curY, 'qtytot', (string) $qtytot);
$nexY = max($pdf->GetY(), $nexY);
}

Expand Down Expand Up @@ -1108,7 +1108,7 @@ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
$pdf->SetFont('', 'B', $default_font_size + 3);
$pdf->SetXY($posx, $posy);
$pdf->SetTextColor(0, 0, 60);
$pdf->MultiCell($w, 3, html_entity_decode($prodToMake->description), '', 'R', false, 1, '', '', true, 0, false, true, 51, 'T', true);
$pdf->MultiCell($w, 3, html_entity_decode($prodToMake->description), '', 'R', false, 1, null, null, true, 0, false, true, 51, 'T', true);
$posy = $pdf->GetY() - 5;

// dimensions
Expand Down
3 changes: 2 additions & 1 deletion htdocs/mrp/ajax/ajax_bom.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2019 Laurent Destailleur (eldy) <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2025 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 @@ -52,7 +53,7 @@
* @var User $user
*/

$idbom = GETPOST('idbom', 'alpha');
$idbom = GETPOSTINT('idbom');
//$action = GETPOST('action', 'aZ09');

$object = new BOM($db);
Expand Down
42 changes: 27 additions & 15 deletions htdocs/mrp/class/api_mos.class.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2015 Jean-François Ferry <[email protected]>
* Copyright (C) 2019 Maxime Kohlhaas <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -38,7 +38,7 @@
class Mos extends DolibarrApi
{
/**
* @var Mo $mo {@type Mo}
* @var Mo {@type Mo}
*/
public $mo;

Expand Down Expand Up @@ -94,6 +94,8 @@ public function get($id)
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
* @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
* @return array Array of order objects
* @phan-return Mo[]
* @phpstan-return Mo[]
*
* @throws RestException
*/
Expand Down Expand Up @@ -175,6 +177,8 @@ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100,
* Create MO object
*
* @param array $request_data Request datas
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
* @return int ID of MO
*/
public function post($request_data = null)
Expand Down Expand Up @@ -208,6 +212,8 @@ public function post($request_data = null)
*
* @param int $id Id of MO to update
* @param array $request_data Datas
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
* @return Object Updated object
*/
public function put($id, $request_data = null)
Expand Down Expand Up @@ -259,6 +265,8 @@ public function put($id, $request_data = null)
*
* @param int $id MO ID
* @return array
* @phan-return array<string,array{code:int,message:string}>
* @phpstan-return array<string,array{code:int,message:string}>
*/
public function delete($id)
{
Expand Down Expand Up @@ -312,6 +320,8 @@ public function delete($id)
*
* @param int $id ID of state
* @param array $request_data Request datas
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
*
* @url POST {id}/produceandconsumeall
*
Expand Down Expand Up @@ -431,7 +441,7 @@ public function produceAndConsumeAll($id, $request_data = null)
$error++;
throw new RestException(500, $moline->error);
}
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $value["objectid"], $value["fk_warehouse"], $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $value["objectid"], $value["fk_warehouse"], $qtytoprocess, 0, $labelmovement, dol_now(), '', '', (string) $tmpproduct->status_batch, $id_product_batch, $codemovement);
} else {
$moline = new MoLine($this->db);
$moline->fk_mo = $this->mo->id;
Expand All @@ -450,7 +460,7 @@ public function produceAndConsumeAll($id, $request_data = null)
$error++;
throw new RestException(500, $moline->error);
}
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $value["objectid"], $value["fk_warehouse"], $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $value["objectid"], $value["fk_warehouse"], $qtytoprocess, 0, $labelmovement, '', '', (string) $tmpproduct->status_batch, dol_now(), $id_product_batch, $codemovement);
}
if ($idstockmove < 0) {
$error++;
Expand Down Expand Up @@ -519,9 +529,9 @@ public function produceAndConsumeAll($id, $request_data = null)
$stockmove->origin_type = 'mo';
$stockmove->origin_id = $this->mo->id;
if ($qtytoprocess >= 0) {
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', (string) $tmpproduct->status_batch, $id_product_batch, $codemovement);
} else {
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, '', '', (string) $tmpproduct->status_batch, dol_now(), $id_product_batch, $codemovement);
}
if ($idstockmove < 0) {
$error++;
Expand Down Expand Up @@ -579,9 +589,9 @@ public function produceAndConsumeAll($id, $request_data = null)
$stockmove->origin_type = 'mo';
$stockmove->origin_id = $this->mo->id;
if ($qtytoprocess >= 0) {
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, '', '', (string) $tmpproduct->status_batch, dol_now(), $id_product_batch, $codemovement);
} else {
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', (string) $tmpproduct->status_batch, $id_product_batch, $codemovement);
}
if ($idstockmove < 0) {
$error++;
Expand Down Expand Up @@ -688,6 +698,8 @@ public function produceAndConsumeAll($id, $request_data = null)
*
* @param int $id ID of state
* @param array $request_data Request datas
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
*
* @url POST {id}/produceandconsume
*
Expand Down Expand Up @@ -803,15 +815,15 @@ public function produceAndConsume($id, $request_data = null)
$stockmove->origin_id = $this->mo->id;
if ($arrayname == "arraytoconsume") {
if ($qtytoprocess >= 0) {
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', (string) $tmpproduct->status_batch, $id_product_batch, $codemovement);
} else {
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, 0, $labelmovement, '', '', (string) $tmpproduct->status_batch, dol_now(), $id_product_batch, $codemovement);
}
} else {
if ($qtytoprocess >= 0) {
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, $pricetoproduce, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
$idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, $pricetoproduce, $labelmovement, '', '', (string) $tmpproduct->status_batch, dol_now(), $id_product_batch, $codemovement);
} else {
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement);
$idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', (string) $tmpproduct->status_batch, $id_product_batch, $codemovement);
}
}
if ($idstockmove <= 0) {
Expand Down Expand Up @@ -962,10 +974,10 @@ protected function _cleanObjectDatas($object)
}

/**
* Validate fields before create or update object
* Validate fields before creating or updating an object
*
* @param array $data Array of data to validate
* @return array
* @param ?array<null|int|float|string> $data Data to validate
* @return array<string,null|int|float|string>
*
* @throws RestException
*/
Expand Down
10 changes: 5 additions & 5 deletions htdocs/mrp/class/mo.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset =
if ($key == 't.rowid') {
$sqlwhere[] = $this->db->sanitize($key)." = ".((int) $value);
} elseif (strpos($key, 'date') !== false) {
$sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate($value)."'";
$sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate((int) $value)."'";
} else {
$sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
}
Expand Down Expand Up @@ -768,7 +768,7 @@ public function createProduction(User $user, $notrigger = 0)
}
}

$resultline = $moline->create($user, false); // Never use triggers here
$resultline = $moline->create($user, 0); // Never use triggers here
if ($resultline <= 0) {
$error++;
$this->error = $moline->error;
Expand Down Expand Up @@ -808,7 +808,7 @@ public function createProduction(User $user, $notrigger = 0)
$moline->fk_default_workstation = $line->fk_default_workstation;
}

$resultline = $moline->create($user, false); // Never use triggers here
$resultline = $moline->create($user, 0); // Never use triggers here
if ($resultline <= 0) {
$error++;
$this->error = $moline->error;
Expand Down Expand Up @@ -1747,9 +1747,9 @@ public function printOriginLinesList($restrictlist = '', $selectedLines = array(
// Qty
print '<td class="right">'.$langs->trans('Qty');
if ($this->bom->bomtype == 0) {
print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityOf", $this->bom->qty).')</span>';
print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityOf", (string) $this->bom->qty).')</span>';
} else {
print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityToConsumeOf", $this->bom->qty).')</span>';
print ' <span class="opacitymedium">('.$langs->trans("ForAQuantityToConsumeOf", (string) $this->bom->qty).')</span>';
}
// Unit
print '<td class="right">'.$langs->trans('Unit');
Expand Down
Loading

0 comments on commit 5fe465b

Please sign in to comment.