Qual: Fix phan notices (#35827)

# Qual: Fix phan notices

Some type hints updates + correction to get week from date (action/pertype.php)
+ check that value is not null (pdf_* classes).
This commit is contained in:
MDW
2025-10-18 19:10:43 +02:00
committed by GitHub
parent 05e6c8ce11
commit 66683105f1
11 changed files with 69 additions and 67 deletions

View File

@@ -11,20 +11,20 @@ return [
// # Issue statistics:
// PhanUndeclaredProperty : 420+ occurrences
// PhanTypeMismatchProperty : 100+ occurrences
// PhanTypeMismatchArgument : 70+ occurrences
// PhanTypeMismatchArgument : 65+ occurrences
// PhanUndeclaredGlobalVariable : 60+ occurrences
// PhanTypeMismatchArgumentNullable : 40+ occurrences
// PhanTypeInvalidDimOffset : 15+ occurrences
// PhanTypeMismatchDimFetch : 15+ occurrences
// PhanTypeMismatchDimFetch : 10+ occurrences
// PhanUndeclaredMethod : 8 occurrences
// PhanPossiblyUndeclaredGlobalVariable : 6 occurrences
// PhanTypeArraySuspiciousNull : 6 occurrences
// PhanTypeComparisonFromArray : 6 occurrences
// PhanTypeExpectedObjectPropAccess : 5 occurrences
// PhanTypeMismatchArgumentProbablyReal : 5 occurrences
// PhanPluginDuplicateArrayKey : 4 occurrences
// PhanParamTooMany : 3 occurrences
// PhanPluginUndeclaredVariableIsset : 3 occurrences
// PhanTypeMismatchArgumentProbablyReal : 2 occurrences
// PhanPossiblyUndeclaredVariable : 1 occurrence
// PhanTypeExpectedObjectPropAccessButGotNull : 1 occurrence
// PhanTypeMismatchReturn : 1 occurrence
@@ -34,7 +34,7 @@ return [
'htdocs/bookcal/class/calendar.class.php' => ['PhanUndeclaredMethod', 'PhanUndeclaredProperty'],
'htdocs/categories/viewcat.php' => ['PhanUndeclaredProperty'],
'htdocs/comm/action/index.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'],
'htdocs/comm/action/pertype.php' => ['PhanTypeComparisonFromArray', 'PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchDimFetch'],
'htdocs/comm/action/pertype.php' => ['PhanTypeComparisonFromArray', 'PhanTypeExpectedObjectPropAccess'],
'htdocs/comm/action/peruser.php' => ['PhanTypeComparisonFromArray', 'PhanTypeMismatchArgument'],
'htdocs/comm/card.php' => ['PhanTypeMismatchArgument'],
'htdocs/comm/mailing/index.php' => ['PhanUndeclaredProperty'],
@@ -53,7 +53,6 @@ return [
'htdocs/compta/clients.php' => ['PhanUndeclaredGlobalVariable'],
'htdocs/compta/facture/card-rec.php' => ['PhanTypeMismatchArgument'],
'htdocs/compta/facture/card.php' => ['PhanUndeclaredProperty'],
'htdocs/compta/facture/class/api_invoices.class.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'htdocs/compta/facture/class/facture-rec.class.php' => ['PhanUndeclaredProperty'],
'htdocs/compta/facture/class/facture.class.php' => ['PhanUndeclaredProperty'],
'htdocs/compta/localtax/card.php' => ['PhanUndeclaredGlobalVariable'],
@@ -72,7 +71,7 @@ return [
'htdocs/compta/tva/index.php' => ['PhanTypeMismatchArgument'],
'htdocs/compta/tva/quadri_detail.php' => ['PhanTypeArraySuspiciousNull', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument'],
'htdocs/contrat/card.php' => ['PhanUndeclaredGlobalVariable'],
'htdocs/core/actions_addupdatedelete.inc.php' => ['PhanTypeMismatchDimFetch', 'PhanUndeclaredProperty'],
'htdocs/core/actions_addupdatedelete.inc.php' => ['PhanUndeclaredProperty'],
'htdocs/core/actions_massactions.inc.php' => ['PhanUndeclaredProperty'],
'htdocs/core/actions_sendmails.inc.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/core/ajax/ajaxdirtree.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty', 'PhanUndeclaredGlobalVariable'],
@@ -105,7 +104,6 @@ return [
'htdocs/core/menus/standard/auguria.lib.php' => ['PhanTypeMismatchArgument'],
'htdocs/core/modules/asset/mod_asset_advanced.php' => ['PhanUndeclaredProperty'],
'htdocs/core/modules/bom/mod_bom_advanced.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'],
'htdocs/core/modules/cheque/doc/pdf_blochet.class.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'htdocs/core/modules/cheque/modules_chequereceipts.php' => ['PhanTypeMismatchArgument'],
'htdocs/core/modules/commande/doc/pdf_einstein.modules.php' => ['PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'],
'htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'],
@@ -228,7 +226,6 @@ return [
'htdocs/projet/tasks/tpl/linkedobjectblock.tpl.php' => ['PhanUndeclaredProperty'],
'htdocs/public/members/new.php' => ['PhanUndeclaredGlobalVariable'],
'htdocs/public/payment/newpayment.php' => ['PhanUndeclaredProperty'],
'htdocs/public/payment/paymentok.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'htdocs/public/project/suggestbooth.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/public/project/suggestconference.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/public/project/viewandvote.php' => ['PhanUndeclaredGlobalVariable'],

View File

@@ -6,7 +6,7 @@
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
* Copyright (C) 2019-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
*
* 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
@@ -254,11 +254,11 @@ $nowday = $nowarray['mday'];
// Define list of all external calendars (global setup)
$listofextcals = array();
$prev = dol_get_first_day($year, $month);
$first_day = 1;
$first_month = 1;
$first_year = $year;
$prev = dol_get_first_day_week($day, $month, $year);
$week = $prev['week'];
$day = (int) $day;
@@ -339,7 +339,6 @@ $param .= "&maxprint=".urlencode((string) ($maxprint));
$paramnoactionodate = $param;
$prev = dol_get_first_day($year, 1);
$prev_year = $year - 1;
$prev_month = $month;
$prev_day = $day;
@@ -347,6 +346,7 @@ $first_day = 1;
$first_month = 1;
$first_year = $year;
$prev = dol_get_first_day_week(1, 1, $year);
$week = $prev['week'];
$day = (int) $day;

View File

@@ -1533,7 +1533,7 @@ class Facture extends CommonInvoice
/**
* Load an object from a contract and create a new invoice into database
*
* @param Facture $object Object source
* @param Contrat $object Object source
* @param User $user Object user
* @param int[] $lines Ids of lines to use for invoice. If empty, all lines will be used.
* @return int Return integer <0 if KO, 0 if nothing done, 1 if OK

View File

@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2017-2019 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
@@ -153,7 +153,7 @@ if ($action == 'add' && !empty($permissiontoadd)) {
$value = ((GETPOST($key) == '1' || GETPOST($key) == 'on') ? 1 : 0);
} elseif ($object->fields[$key]['type'] == 'reference') {
$tmparraykey = array_keys($object->param_list);
$value = $tmparraykey[GETPOST($key)].','.GETPOST($key.'2');
$value = $tmparraykey[(int) GETPOST($key)].','.GETPOST($key.'2');
} elseif (preg_match('/^chkbxlst:(.*)/', $object->fields[$key]['type']) || $object->fields[$key]['type'] == 'checkbox') {
$value = '';
$values_arr = GETPOST($key, 'array');
@@ -315,7 +315,7 @@ if ($action == 'update' && !empty($permissiontoadd)) {
} elseif ($object->fields[$key]['type'] == 'boolean') {
$value = ((GETPOST($key, 'aZ09') == 'on' || GETPOST($key, 'aZ09') == '1') ? 1 : 0);
} elseif ($object->fields[$key]['type'] == 'reference') {
$value = array_keys($object->param_list)[GETPOST($key)].','.GETPOST($key.'2');
$value = array_keys($object->param_list)[(int) GETPOST($key)].','.GETPOST($key.'2');
} elseif (preg_match('/^chkbxlst:/', $object->fields[$key]['type']) || $object->fields[$key]['type'] == 'checkbox') {
$value = '';
$values_arr = GETPOST($key, 'array');

View File

@@ -1035,9 +1035,9 @@ function pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber = 0,
* @param float $marge_basse Margin bottom we use for the autobreak
* @param float $marge_gauche Margin left (no more used)
* @param float $page_hauteur Page height
* @param CommonObject $object Object shown in PDF
* @param ?CommonObject $object Object shown in PDF
* @param int<0,3> $showdetails Show company address details into footer (0=Nothing, 1=Show address, 2=Show managers, 3=Both)
* @param int $hidefreetext 1=Hide free text, 0=Show free text
* @param int<0,1> $hidefreetext 1=Hide free text, 0=Show free text
* @param float $page_largeur Page width
* @param string $watermark Watermark text to print on page
* @return int Return height of bottom margin including footer text

View File

@@ -208,7 +208,7 @@ class BordereauChequeBlochet extends ModeleChequeReceipts
$this->Body($pdf, $pagenb, $pages, $outputlangs);
// Pied de page
// Page footer
$this->_pagefoot($pdf, null, $outputlangs);
if (method_exists($pdf, 'AliasNbPages')) {
$pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
@@ -427,7 +427,7 @@ class BordereauChequeBlochet extends ModeleChequeReceipts
* Show footer of page. Need this->emetteur object
*
* @param TCPDF $pdf PDF
* @param CommonObject $object Object to show
* @param ?CommonObject $object Object to show
* @param Translate $outputlangs Object lang for output
* @param int<0,1> $hidefreetext 1=Hide free text
* @return int

View File

@@ -228,8 +228,9 @@ class pdf_eratosthene extends ModelePDFCommandes
$realpath = null;
foreach ($pdir as $midir) {
if (!$arephoto) {
if ($conf->entity != $objphoto->entity) {
$dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
$entity = $objphoto->entity;
if ($entity !== null && $conf->entity != $entity) {
$dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities
} else {
$dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
}

View File

@@ -329,8 +329,9 @@ class pdf_octopus extends ModelePDFFactures
$realpath = false;
foreach ($pdir as $midir) {
if (!$arephoto) {
if ($conf->entity != $objphoto->entity) {
$dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
$entity = $objphoto->entity;
if ($entity !== null && $conf->entity != $entity) {
$dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities
} else {
$dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
}
@@ -1480,13 +1481,13 @@ class pdf_octopus extends ModelePDFFactures
if ($object->status > Facture::STATUS_DRAFT && getDolGlobalInt('PDF_INVOICE_SHOW_BALANCE_SUMMARY')) {
// All customer previous invoices
$sql = "SELECT f.rowid, f.datef, f.total_ttc";
$sql.= " FROM " . MAIN_DB_PREFIX . "facture as f";
$sql.= " WHERE f.fk_soc = " . ((int) $object->socid);
$sql.= " AND f.entity IN (" . getEntity('invoice') . ")";
$sql.= " AND f.datef <= '" . $this->db->idate($object->date) . "'";
$sql.= " AND f.rowid < " . ((int) $object->id);
$sql.= " AND f.fk_statut > 0";
$sql.= " ORDER BY f.datef ASC";
$sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
$sql .= " WHERE f.fk_soc = " . ((int) $object->socid);
$sql .= " AND f.entity IN (" . getEntity('invoice') . ")";
$sql .= " AND f.datef <= '" . $this->db->idate($object->date) . "'";
$sql .= " AND f.rowid < " . ((int) $object->id);
$sql .= " AND f.fk_statut > 0";
$sql .= " ORDER BY f.datef ASC";
$old_balance = 0;
$invoices = array();
@@ -1501,12 +1502,12 @@ class pdf_octopus extends ModelePDFFactures
// All payments before current date
$sql_payments = "SELECT p.datep, pf.fk_facture, pf.amount";
$sql_payments.= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
$sql_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
$sql_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
$sql_payments.= " WHERE f.fk_soc = " . ((int) $object->socid);
$sql_payments.= " AND p.datep < '" . $this->db->idate($object->date) . "'";
$sql_payments.= " ORDER BY p.datep ASC";
$sql_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
$sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
$sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
$sql_payments .= " WHERE f.fk_soc = " . ((int) $object->socid);
$sql_payments .= " AND p.datep < '" . $this->db->idate($object->date) . "'";
$sql_payments .= " ORDER BY p.datep ASC";
$total_payments = 0;
$resql_payments = $this->db->query($sql_payments);
@@ -1519,11 +1520,11 @@ class pdf_octopus extends ModelePDFFactures
// Payments made on current invoice date (including current invoice)
$sql_current_date_payments = "SELECT p.datep, pf.fk_facture, pf.amount";
$sql_current_date_payments.= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
$sql_current_date_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
$sql_current_date_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
$sql_current_date_payments.= " WHERE f.fk_soc = " . ((int) $object->socid);
$sql_current_date_payments.= " AND DATE(p.datep) = DATE('" . $this->db->idate($object->date) . "')";
$sql_current_date_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
$sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
$sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
$sql_current_date_payments .= " WHERE f.fk_soc = " . ((int) $object->socid);
$sql_current_date_payments .= " AND DATE(p.datep) = DATE('" . $this->db->idate($object->date) . "')";
$current_date_payments = 0;
$resql_current_date = $this->db->query($sql_current_date_payments);
@@ -1547,7 +1548,7 @@ class pdf_octopus extends ModelePDFFactures
$pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0, 'L', true);
$pdf->SetFont('', '', $default_font_size - 2);
$pdf->SetXY($posxval+8, $posy);
$pdf->SetXY($posxval + 8, $posy);
$titre = $outputlangs->transnoentities("NewBalance").' : '.price($new_balance);
$pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0, 'L', true);

View File

@@ -264,8 +264,9 @@ class pdf_sponge extends ModelePDFFactures
$realpath = false;
foreach ($pdir as $midir) {
if (!$arephoto) {
if ($conf->entity != $objphoto->entity) {
$dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
$entity = $objphoto->entity;
if ($entity !== null && $conf->entity != $entity) {
$dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities
} else {
$dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
}
@@ -1399,13 +1400,13 @@ class pdf_sponge extends ModelePDFFactures
if ($object->status > Facture::STATUS_DRAFT && getDolGlobalInt('PDF_INVOICE_SHOW_BALANCE_SUMMARY')) {
// All customer previous invoices
$sql = "SELECT f.rowid, f.datef, f.total_ttc";
$sql.= " FROM " . MAIN_DB_PREFIX . "facture as f";
$sql.= " WHERE f.fk_soc = " . ((int) $object->socid);
$sql.= " AND f.entity IN (" . getEntity('invoice') . ")";
$sql.= " AND f.datef <= '" . $this->db->idate($object->date) . "'";
$sql.= " AND f.rowid < " . ((int) $object->id);
$sql.= " AND f.fk_statut > 0";
$sql.= " ORDER BY f.datef ASC";
$sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
$sql .= " WHERE f.fk_soc = " . ((int) $object->socid);
$sql .= " AND f.entity IN (" . getEntity('invoice') . ")";
$sql .= " AND f.datef <= '" . $this->db->idate($object->date) . "'";
$sql .= " AND f.rowid < " . ((int) $object->id);
$sql .= " AND f.fk_statut > 0";
$sql .= " ORDER BY f.datef ASC";
$old_balance = 0;
$invoices = array();
@@ -1420,12 +1421,12 @@ class pdf_sponge extends ModelePDFFactures
// All payments before current date
$sql_payments = "SELECT p.datep, pf.fk_facture, pf.amount";
$sql_payments.= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
$sql_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
$sql_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
$sql_payments.= " WHERE f.fk_soc = " . ((int) $object->socid);
$sql_payments.= " AND p.datep < '" . $this->db->idate($object->date) . "'";
$sql_payments.= " ORDER BY p.datep ASC";
$sql_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
$sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
$sql_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
$sql_payments .= " WHERE f.fk_soc = " . ((int) $object->socid);
$sql_payments .= " AND p.datep < '" . $this->db->idate($object->date) . "'";
$sql_payments .= " ORDER BY p.datep ASC";
$total_payments = 0;
$resql_payments = $this->db->query($sql_payments);
@@ -1438,11 +1439,11 @@ class pdf_sponge extends ModelePDFFactures
// Payments made on current invoice date (including current invoice)
$sql_current_date_payments = "SELECT p.datep, pf.fk_facture, pf.amount";
$sql_current_date_payments.= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
$sql_current_date_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
$sql_current_date_payments.= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
$sql_current_date_payments.= " WHERE f.fk_soc = " . ((int) $object->socid);
$sql_current_date_payments.= " AND DATE(p.datep) = DATE('" . $this->db->idate($object->date) . "')";
$sql_current_date_payments .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf";
$sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON p.rowid = pf.fk_paiement";
$sql_current_date_payments .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = pf.fk_facture";
$sql_current_date_payments .= " WHERE f.fk_soc = " . ((int) $object->socid);
$sql_current_date_payments .= " AND DATE(p.datep) = DATE('" . $this->db->idate($object->date) . "')";
$current_date_payments = 0;
$resql_current_date = $this->db->query($sql_current_date_payments);
@@ -1466,7 +1467,7 @@ class pdf_sponge extends ModelePDFFactures
$pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0, 'L', true);
$pdf->SetFont('', '', $default_font_size - 2);
$pdf->SetXY($posxval+8, $posy);
$pdf->SetXY($posxval + 8, $posy);
$titre = $outputlangs->transnoentities("NewBalance").' : '.price($new_balance);
$pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0, 'L', true);

View File

@@ -243,8 +243,9 @@ class pdf_azur extends ModelePDFPropales
$realpath = '';
foreach ($pdir as $midir) {
if (!$arephoto) {
if ($conf->entity != $objphoto->entity) {
$dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
$entity = $objphoto->entity;
if ($entity !== null && $conf->entity != $entity) {
$dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities
} else {
$dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
}

View File

@@ -220,8 +220,9 @@ class pdf_cyan extends ModelePDFPropales
$arephoto = false;
foreach ($pdir as $midir) {
if (!$arephoto) {
if ($conf->entity != $objphoto->entity) {
$dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
$entity = $objphoto->entity;
if ($entity !== null && $conf->entity != $entity) {
$dir = $conf->product->multidir_output[$entity].'/'.$midir; //Check repertories of current entities
} else {
$dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
}