Skip to content

Commit

Permalink
Qual: Fix phan notices
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Jan 16, 2025
1 parent 4f35e53 commit abc8e98
Show file tree
Hide file tree
Showing 23 changed files with 377 additions and 159 deletions.
47 changes: 32 additions & 15 deletions htdocs/core/customreports.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/* Copyright (C) 2020-2024 Laurent Destailleur <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
Expand Down Expand Up @@ -41,9 +42,9 @@
*/

// Initialise values
$search_xaxis = array();
$search_groupby = array();
$tabfamily = null;
$objecttype = null;

if (!defined('USE_CUSTOM_REPORT_AS_INCLUDE')) {
require '../main.inc.php';
Expand All @@ -70,7 +71,7 @@
'@phan-var-force string[] $search_groupby';

$search_yaxis = GETPOST('search_yaxis', 'array');
$search_graph = GETPOST('search_graph', 'restricthtml');
$search_graph = (string) GETPOST('search_graph', 'restricthtml');

// Load variable for pagination
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
Expand Down Expand Up @@ -113,10 +114,18 @@
if (!isset($search_measures)) {
$search_measures = array(0 => 't.count');
}
if (!isset($search_xaxis)) {
// Ensure value is set and not null.
$search_xaxis = array();
}
if (!isset($search_graph)) {
// Ensure value is set and not null
$search_graph = '';
}
if (!empty($object)) {
$objecttype = $object->element.($object->module ? '@'.$object->module : '');
}
if (empty($objecttype)) {
if (!is_string($objecttype) || empty($objecttype)) {
$objecttype = 'thirdparty';
}

Expand Down Expand Up @@ -163,6 +172,7 @@

// Complete $arrayoftype by external modules
$parameters = array('objecttype' => $objecttype, 'tabfamily' => $tabfamily);
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable
$reshook = $hookmanager->executeHooks('loadDataForCustomReports', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
Expand Down Expand Up @@ -191,9 +201,12 @@
} else {
$fileforclass = "/".$objecttype."/class/".$objecttype.".class.php";
}
dol_include_once($fileforclass);
$ObjectClassName = null;

$ObjectClassName = $arrayoftype[$objecttype]['ObjectClassName'];
if ($fileforclass !== null) {
dol_include_once($fileforclass);
$ObjectClassName = $arrayoftype[$objecttype]['ObjectClassName'];
}
if (!empty($ObjectClassName)) {
if (class_exists($ObjectClassName)) {
$object = new $ObjectClassName($db);
Expand Down Expand Up @@ -369,7 +382,7 @@

$newarrayoftype = array();
foreach ($arrayoftype as $key => $val) {
if (dol_eval($val['enabled'], 1, 1, '1')) {
if (dol_eval((string) $val['enabled'], 1, 1, '1')) {
$newarrayoftype[$key] = $arrayoftype[$key];
}
if (!empty($val['langs'])) {
Expand All @@ -378,11 +391,15 @@
}

$count = 0;
$arrayoffilterfields = fillArrayOfFilterFields($object, 't', $langs->trans($newarrayoftype[$objecttype]['label']), $arrayoffilterfields, 0, $count);
$label = '';
if ($objecttype !== null && array_key_exists($objecttype, $newarrayoftype)) {
$label = $langs->trans($newarrayoftype[$objecttype]['label']);
}
$arrayoffilterfields = fillArrayOfFilterFields($object, 't', $label, $arrayoffilterfields, 0, $count);
$arrayoffilterfields = dol_sort_array($arrayoffilterfields, 'position', 'asc', 0, 0, 1);

$count = 0;
$arrayofmesures = fillArrayOfMeasures($object, 't', $langs->trans($newarrayoftype[$objecttype]['label']), $arrayofmesures, 0, $count);
$arrayofmesures = fillArrayOfMeasures($object, 't', $label, $arrayofmesures, 0, $count);
$arrayofmesures = dol_sort_array($arrayofmesures, 'position', 'asc', 0, 0, 1);

$count = 0;
Expand All @@ -396,17 +413,17 @@

// Check parameters
if ($action == 'viewgraph') {
if (is_array($search_measures) && !count($search_measures)) {
if (!count($search_measures)) {
setEventMessages($langs->trans("AtLeastOneMeasureIsRequired"), null, 'warnings');
} elseif ($mode == 'graph' && is_array($search_xaxis) && count($search_xaxis) > 1) {
setEventMessages($langs->trans("OnlyOneFieldForXAxisIsPossible"), null, 'warnings');
$search_xaxis = array(0 => $search_xaxis[0]);
}
if (is_array($search_groupby) && count($search_groupby) >= 2) {
if (count($search_groupby) >= 2) {
setEventMessages($langs->trans("ErrorOnlyOneFieldForGroupByIsPossible"), null, 'warnings');
$search_groupby = array(0 => $search_groupby[0]);
}
if (is_array($search_xaxis) && !count($search_xaxis)) {
if (!count($search_xaxis)) {
setEventMessages($langs->trans("AtLeastOneXAxisIsRequired"), null, 'warnings');
} elseif ($mode == 'graph' && $search_graph == 'bars' && count($search_measures) > $MAXMEASURESINBARGRAPH) {
$langs->load("errors");
Expand All @@ -417,7 +434,7 @@

// Get all possible values of fields when a 'group by' is set, and save this into $arrayofvaluesforgroupby
// $arrayofvaluesforgroupby will be used to forge lael of each grouped series
if (is_array($search_groupby) && count($search_groupby)) {
if (count($search_groupby)) {
$fieldtocount = '';
foreach ($search_groupby as $gkey => $gval) {
$gvalwithoutprefix = preg_replace('/^[a-z]+\./', '', $gval);
Expand Down Expand Up @@ -563,7 +580,7 @@
}
}
//var_dump($labeloffield);
setEventMessages($langs->transnoentitiesnoconv("ErrorTooManyDifferentValueForSelectedGroupBy", $MAXUNIQUEVALFORGROUP, $labeloffield), null, 'warnings');
setEventMessages($langs->transnoentitiesnoconv("ErrorTooManyDifferentValueForSelectedGroupBy", (string) $MAXUNIQUEVALFORGROUP, (string) $labeloffield), null, 'warnings');
$search_groupby = array();
}

Expand Down Expand Up @@ -1064,7 +1081,7 @@ function (array $matches): string {
$legend[] = $langs->trans($arrayofmesures[$val]['label']);
}

$useagroupby = (is_array($search_groupby) && count($search_groupby));
$useagroupby = count($search_groupby);
//var_dump($useagroupby);
//var_dump($arrayofvaluesforgroupby);

Expand Down Expand Up @@ -1221,7 +1238,7 @@ function (array $matches): string {

$px1->SetLegend($legend);
$px1->setShowLegend($SHOWLEGEND);
$px1->SetMinValue($px1->GetFloorMinValue());
$px1->SetMinValue((int) $px1->GetFloorMinValue());
$px1->SetMaxValue($px1->GetCeilMaxValue());
$px1->SetWidth($WIDTH);
$px1->SetHeight($HEIGHT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede

if ($dir === null) {
dol_syslog(get_class($this).'::'.__METHOD__."Target directory should not be null.". getCallerInfoString(), LOG_ERR);
$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
$this->error = $langs->transnoentities("ErrorCanNotCreateDir", "Null dir");
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/modules/commande/modules_commande.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ abstract class ModelePDFCommandes extends CommonDocGenerator
/**
* Local tax rates Array[tax_type][tax_rate]
*
* @var array<string,array<int,float>>
* @var array<int,array<string,float>>
*/
public $localtax1;

/**
* Local tax rates Array[tax_type][tax_rate]
*
* @var array<string,array<int,float>>
* @var array<int,array<string,float>>
*/
public $localtax2;

Expand Down
11 changes: 10 additions & 1 deletion htdocs/core/modules/delivery/doc/pdf_typhon.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright (C) 2008 Chiptronik
* Copyright (C) 2011-2021 Philippe Grand <[email protected]>
* Copyright (C) 2015 Marcos García <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2024 Nick Fragoulis
*
Expand Down Expand Up @@ -72,8 +72,17 @@ class pdf_typhon extends ModelePDFDeliveryOrder
*/
public $version = 'dolibarr';

/**
* @var float
*/
public $posxcomm; // For customer comment column
/**
* @var float
*/
public $posxweightvol; // For weight or volume
/**
* @var float
*/
public $posxremainingqty;


Expand Down
13 changes: 11 additions & 2 deletions htdocs/core/modules/expedition/doc/pdf_merou.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 2005-2011 Regis Houssin <[email protected]>
* Copyright (C) 2013 Florian Henry <[email protected]>
* Copyright (C) 2015 Marcos García <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2024 Nick Fragoulis
*
Expand Down Expand Up @@ -65,8 +65,17 @@ class pdf_merou extends ModelePdfExpedition
*/
public $type;

/**
* @var Contact
*/
public $destinataire;
/**
* @var ?Societe
*/
public $expediteur;
/**
* @var User
*/
public $livreur;

/**
Expand Down Expand Up @@ -624,7 +633,7 @@ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
$label .= $object->tracking_url;
}
$pdf->SetFont('', 'B', $default_font_size - 3);
$pdf->writeHTMLCell(50, 8, '', '', $label, '', 'L');
$pdf->writeHTMLCell(50, 8, '', '', $label, 0, 1, false, true, 'L');
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Copyright (C) 2019 Markus Welters <[email protected]>
* Copyright (C) 2019 Rafael Ingenleuf <[email protected]>
* Copyright (C) 2020 Marc Guenneugues <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
* Copyright (C) 2024 Nick Fragoulis
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -77,19 +77,46 @@ class pdf_standard_expensereport extends ModeleExpenseReport
*/
public $version = 'dolibarr';

/**
* @var float
*/
public $posxpiece;
/**
* @var float
*/
public $posxcomment;
/**
* @var float
*/
public $posxtva;
/**
* @var float
*/
public $posxup;
/**
* @var float
*/
public $posxqty;
/**
* @var float
*/
public $posxtype;

/**
* @var int posx date
*/
public $posxdate;
/**
* @var float
*/
public $posxprojet;
/**
* @var float
*/
public $postotalht;
/**
* @var float
*/
public $postotalttc;


Expand Down
18 changes: 9 additions & 9 deletions htdocs/core/modules/facture/doc/pdf_crabe.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Copyright (C) 2018-2024 Frédéric France <[email protected]>
* Copyright (C) 2022-2024 Anthony Berton <[email protected]>
* Copyright (C) 2022 Charlene Benke <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
* Copyright (C) 2024 Nick Fragoulis
* Copyright (C) 2024 Alexandre Spangaro <[email protected]>
*
Expand Down Expand Up @@ -800,7 +800,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'])) {
$this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['tot_ht'] = 0;
}
$this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne, 'tot_ht'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'] + $object->lines[$i]->total_ht);
$this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne, 'tot_ht' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['tot_ht'] + $object->lines[$i]->total_ht);
} else {
if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
$this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
Expand Down Expand Up @@ -901,7 +901,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
$pagecount = $pdf->setSourceFile($termsofsale);
for ($i = 1; $i <= $pagecount; $i++) {
$tplIdx = $pdf->importPage($i);
if ($tplIdx!==false) {
if ($tplIdx !== false) {
$s = $pdf->getTemplatesize($tplIdx);
$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
$pdf->useTemplate($tplIdx);
Expand Down Expand Up @@ -1884,7 +1884,7 @@ protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $
$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);

if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
$pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius, '1001', 'F', null, explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
$pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius, '1001', 'F', array(), explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
}
}

Expand All @@ -1903,10 +1903,10 @@ protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $

if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE')) {
$pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
if (empty($hidetop)) {
//$pdf->SetXY($this->posxpicture-1, $tab_top+1);
//$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
}
//if (empty($hidetop)) {
//$pdf->SetXY($this->posxpicture-1, $tab_top+1);
//$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
//}
}

if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
Expand Down Expand Up @@ -2338,7 +2338,7 @@ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $output
// Show shipping frame
$pdf->SetXY($posx + 2, $posy - 5);
$pdf->SetFont('', '', $default_font_size - 2);
$pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
$pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
$pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');

// Show shipping name
Expand Down
Loading

0 comments on commit abc8e98

Please sign in to comment.