Skip to content

Commit

Permalink
Qual: Fix phan/phpstan notices in class files (part 5) (#31617)
Browse files Browse the repository at this point in the history
* Qual: fix commonstickergen..don.class

* Fix notifications for pdf_paiement...cronjob.class

* Qual: Fix notifications for emailcollector..price_parser.class

* Ensure that NULL is used in the database when fk's are 0/empty

* Fix notifications for pdf_paiement...cronjob.class

* Cope with updated phpstan, and make fk_origin_stock int in multiple locations
  • Loading branch information
mdeweerd authored Nov 6, 2024
1 parent 0d7bc50 commit 178d748
Show file tree
Hide file tree
Showing 52 changed files with 510 additions and 225 deletions.
5 changes: 5 additions & 0 deletions build/phpstan/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21470,6 +21470,11 @@ parameters:
count: 1
path: ../../htdocs/opensurvey/class/opensurveysondage.class.php

-
message: "#^Property Opensurveysondage\\:\\:\\$status \\(int\\) in isset\\(\\) is not nullable\\.$#"
count: 1
path: ../../htdocs/opensurvey/class/opensurveysondage.class.php

-
message: "#^Left side of && is always true\\.$#"
count: 1
Expand Down
95 changes: 33 additions & 62 deletions dev/tools/phan/baseline.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev/tools/phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
'simplify_ast' => true,
'analyzed_file_extensions' => ['php','inc'],
'globals_type_map' => [
'_Avery_Labels' => 'array<string,array{name:string,paper-size:string,orientation:string,metric:string,marginLeft:float,marginTop:float,NX:int,NY:int,SpaceX:float,SpaceY:float,width:float,height:float,font-size:float,custom_x:float,custom_y:float}>',
'_Avery_Labels' => 'array<string,array{name:string,paper-size:string|array{0:float,1:float},orientation:string,metric:string,marginLeft:float,marginTop:float,NX:int,NY:int,SpaceX:float,SpaceY:float,width:float,height:float,font-size:float,custom_x:float,custom_y:float}>',
'action' => 'string',
'actioncode' => 'string',
'badgeStatus0' => 'string',
Expand Down
4 changes: 2 additions & 2 deletions htdocs/adherents/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@
$arrayfields[$tableprefix.'.'.$key] = array(
'label' => $val['label'],
'checked' => (($visible < 0) ? 0 : 1),
'enabled' => (abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
'position' => $val['position'],
'enabled' => (int) (abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
'position' => (int) $val['position'],
'help' => isset($val['help']) ? $val['help'] : ''
);
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/compta/paiement/class/paiement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom
$fac = new Facture($this->db);
$fac->fetch($key);
$fac->fetch_thirdparty();
if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty @phan-suppress-current-line PhanPossiblyUndeclaredVariable
$result = $acc->add_url_line(
$bank_line_id,
$fac->thirdparty->id,
Expand Down
5 changes: 3 additions & 2 deletions htdocs/core/class/commonobject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,17 +344,18 @@ abstract class CommonObject
public $newref;

/**
* @var int|array<int, string> The object's status. Use status instead.
* @var null|int|array<int, string> The object's status. Use status instead.
* @deprecated Use $status instead.
* @see $status
* @see setStatut(), $status
*/
public $statut;

/**
* @var int|array<int, string> The object's status (an int).
* @var null|int|array<int, string> The object's status (an int).
* Or an array listing all the potential status of the object:
* array: int of the status => translated label of the status
* In some classes status must be able to be null.
* See for example the Account class.
* @see setStatut()
*/
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/class/commonstickergenerator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ abstract class CommonStickerGenerator extends CommonDocGenerator
protected $_COUNTY = 1;
protected $_First = 1;
/**
* @var array{name:string,paper-size:string,orientation:string,metric:string,marginLeft:float,marginTop:float,NX:int,NY:int,SpaceX:float,SpaceY:float,width:float,height:float,font-size:float,custom_x:float,custom_y:float}
* @var ?array{name:string,paper-size:'custom'|array{0:float,1:float},orientation:string,metric:string,marginLeft:float,marginTop:float,NX:int,NY:int,SpaceX:float,SpaceY:float,width:float,height:float,font-size:float,custom_x:float,custom_y:float}
*/
public $Tformat;

/**
* @var array<string,array{name:string,paper-size:string,orientation:string,metric:string,marginLeft:float,marginTop:float,NX:int,NY:int,SpaceX:float,SpaceY:float,width:float,height:float,font-size:float,custom_x:float,custom_y:float}>
* @var array<string,array{name:string,paper-size:'custom'|array{0:float,1:float},orientation:string,metric:string,marginLeft:float,marginTop:float,NX:int,NY:int,SpaceX:float,SpaceY:float,width:float,height:float,font-size:float,custom_x:float,custom_y:float}>
*/
public $_Avery_Labels;
// phpcs:enable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class pdf_standard_actions
public $marge_basse;

/**
* @var array format
* @var array{0:float,1:float} format
*/
public $format;

Expand Down
11 changes: 7 additions & 4 deletions htdocs/core/modules/cheque/doc/pdf_blochet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class BordereauChequeBlochet extends ModeleChequeReceipts
*/
public $line_per_page;

/**
* @var string
*/
public $ref_ext;


Expand Down Expand Up @@ -206,7 +209,7 @@ public function write_file($object, $_dir, $number, $outputlangs)
$this->Body($pdf, $pagenb, $pages, $outputlangs);

// Pied de page
$this->_pagefoot($pdf, '', $outputlangs);
$this->_pagefoot($pdf, null, $outputlangs);
if (method_exists($pdf, 'AliasNbPages')) {
$pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
}
Expand Down Expand Up @@ -422,10 +425,10 @@ public function Body(&$pdf, $pagenb, $pages, $outputlangs)
* Show footer of page. Need this->emetteur object
*
* @param TCPDF $pdf PDF
* @param Object $object Object to show
* @param ?CommonObject $object Object to show
* @param Translate $outputlangs Object lang for output
* @param int $hidefreetext 1=Hide free text
* @return mixed
* @param int<0,1> $hidefreetext 1=Hide free text
* @return int
*/
protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $mode =
$result = $object->fetch_contact($arrayidcontact[0]);
}

$contactobject = null;
// Recipient name
if (!empty($usecontact)) {
// We can use the company of contact instead of thirdparty company
Expand Down Expand Up @@ -426,7 +427,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $mode =
* @param CommonObject $object member
* @param Translate $outputlangs translation object
* @param string $array_key key for array
* @return array array of substitutions
* @return array<string,string> Array of substitutions
*/
public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __construct($db)
*
* @param TCPDF $pdf PDF reference
* @param Translate $outputlangs Output langs
* @param array $param Associative array containing label content and optional parameters
* @param array<string,string> $param Associative array containing label content and optional parameters
* @return void
*/
public function addSticker(&$pdf, $outputlangs, $param)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class pdf_standardlabel extends CommonStickerGenerator
*
* @param TCPDF $pdf PDF reference
* @param Translate $outputlangs Output langs
* @param array $param Associative array containing label content and optional parameters
* @param array<string,string> $param Associative array containing label content and optional parameters
* @return void
*/
public function addSticker(&$pdf, $outputlangs, $param)
Expand Down Expand Up @@ -228,7 +228,7 @@ public function Add_PDF_label(&$pdf, $textleft, $header, $footer, $outputlangs,
/**
* Function to build PDF on disk, then output on HTTP stream.
*
* @param array $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param array<array{textleft:string,textheader:string,textfooter:string,textright:string,photo:string}> $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param Translate $outputlangs Lang object for output language
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param string $outputdir Output directory for pdf file
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private function writeBarcode(&$pdf, $code, $encoding, $is2d, $x, $y, $w, $h)
*
* @param TCPDF $pdf PDF reference
* @param Translate $outputlangs Output langs
* @param array $param Associative array containing label content and optional parameters
* @param array{textleft:string,textheader:string,textfooter:string,textright:string,code:string,encoding:string,is2d:int<0,1>|bool} $param Associative array containing label content and optional parameters
* @return void
*/
public function addSticker(&$pdf, $outputlangs, $param)
Expand Down Expand Up @@ -251,7 +251,7 @@ public function addSticker(&$pdf, $outputlangs, $param)
/**
* Function to build PDF on disk, then output on HTTP stream.
*
* @param array $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param array<array{textleft:string,textheader:string,textfooter:string,textright:string,code:string,encoding:string,is2d:int<0,1>|bool}> $arrayofrecords Array of record information (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>)
* @param Translate $outputlangs Lang object for output language
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param string $outputdir Output directory for pdf file
Expand Down
44 changes: 40 additions & 4 deletions htdocs/core/modules/rapport/pdf_paiement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,55 @@
*/
class pdf_paiement extends CommonDocGenerator
{
/**
* @var int
*/
public $tab_top;

/**
* @var int
*/
public $line_height;

/**
* @var int
*/
public $line_per_page;

/**
* @var int
*/
public $tab_height;

/**
* @var int
*/
public $posxdate;

/**
* @var int
*/
public $posxpaymenttype;
/**
* @var int
*/
public $posxinvoice;
/**
* @var int
*/
public $posxbankaccount;
/**
* @var int
*/
public $posxinvoiceamount;
/**
* @var int
*/
public $posxpaymentamount;

/**
* @var string
*/
public $doc_type;

/**
Expand Down Expand Up @@ -208,6 +241,8 @@ public function write_file($_dir, $month, $year, $outputlangs)
$result = $this->db->query($sql);
if ($result) {
$numpaiement = $this->db->num_rows($result);
} else {
$numpaiement = 0;
}

// number of bill
Expand Down Expand Up @@ -464,7 +499,7 @@ protected function _pagehead(&$pdf, $page, $showaddress, $outputlangs)
*
* @param TCPDF $pdf PDF object
* @param int $page Page
* @param array $lines Array of lines
* @param array<int,array<int,string>> $lines Array of lines
* @param Translate $outputlangs Object langs
* @return void
*/
Expand All @@ -477,13 +512,14 @@ public function Body(&$pdf, $page, $lines, $outputlangs)
$pdf->SetFont('', '', $default_font_size - 1);
$oldprowid = 0;
$total_page = 0;
$total_mod = 0;
$mod = 0;
$total = 0;
$pdf->SetFillColor(220, 220, 220);
$yp = 0;
$numlines = count($lines);
if (($this->doc_type == 'client' && getDolGlobalString('PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type == 'fourn' && getDolGlobalString('PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
$mod = $lines[0][2];
$total_mod = 0;
}
for ($j = 0; $j < $numlines; $j++) {
$i = $j;
Expand Down Expand Up @@ -528,9 +564,9 @@ public function Body(&$pdf, $page, $lines, $outputlangs)
$pdf->SetXY($this->posxpaymentamount, $this->tab_top + 10 + $yp);
$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxpaymentamount, $this->line_height, $lines[$j][4], 0, 'R', 1);
$yp += 5;
$total_page += $lines[$j][9];
$total_page += (float) $lines[$j][9];
if (($this->doc_type == 'client' && getDolGlobalString('PAYMENTS_REPORT_GROUP_BY_MOD')) || ($this->doc_type == 'fourn' && getDolGlobalString('PAYMENTS_FOURN_REPORT_GROUP_BY_MOD'))) {
$total_mod += $lines[$j][9];
$total_mod += (float) $lines[$j][9];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
*/
class InterfaceNotification extends DolibarrTriggers
{
/**
* @var string[]
*/
public $listofmanagedevents = array();

/**
Expand Down Expand Up @@ -102,7 +105,7 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
/**
* Return list of events managed by notification module
*
* @return array Array of events managed by notification module
* @return array<array{rowid:int,code:string,contexts:string,label:string,description:string,elementtype:string}> Array of events managed by notification module
*/
public function getListOfManagedEvents()
{
Expand Down
21 changes: 12 additions & 9 deletions htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,15 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf

$contactid = empty($object->context['contactid']) ? 0 : $object->context['contactid'];
$res = 0;
$contactObj = null;

if (!empty($contactid)) {
$contact = new Contact($this->db);
$res = $contact->fetch($contactid);
$contactObj = new Contact($this->db);
$res = $contactObj->fetch($contactid);
}

if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
$sendto = $contact->email;
if ($contactObj !== null && !empty($contactObj->email) && !empty($contactObj->statut)) {
$sendto = $contactObj->email;
} elseif (!empty($object->fk_soc)) {
$object->fetch_thirdparty();
$sendto = $object->thirdparty->email;
Expand Down Expand Up @@ -256,13 +257,14 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf

$contactid = empty($object->context['contactid']) ? 0 : $object->context['contactid'];
$res = 0;
$contactObj = null;

if ($contactid > 0) {
// TODO This security test has no sens. We must check that $contactid is inside $linked_contacts[]['id'] when $linked_contacts[]['source'] = 'external' or 'thirdparty'
// Refuse email if not
$contact = new Contact($this->db);
$res = $contact->fetch($contactid);
if (! in_array($contact, $linked_contacts)) {
$contactObj = new Contact($this->db);
$res = $contactObj->fetch($contactid);
if (! in_array($contactObj, $linked_contacts)) {
$error_msg = $langs->trans('Error'). ': ';
$error_msg .= $langs->transnoentities('TicketWrongContact');
setEventMessages($error_msg, [], 'errors');
Expand All @@ -272,8 +274,8 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
}

$sendto = '';
if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
$sendto = $contact->email;
if ($contactObj !== null && $res > 0 && !empty($contactObj->email) && !empty($contactObj->statut)) {
$sendto = $contactObj->email;
} elseif (!empty($linked_contacts) && ($contactid == -2 || (GETPOST('massaction', 'alpha') == 'close' && GETPOST('confirm', 'alpha') == 'yes'))) {
// if sending to all contacts or sending to contacts while mass closing
$temp_emails = [];
Expand Down Expand Up @@ -350,6 +352,7 @@ private function composeAndSendAdminMessage($sendto, $base_subject, $body, Ticke

$trackid = 'tic'.$object->id;

$old_MAIN_MAIL_AUTOCOPY_TO = null;
if (getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) {
$old_MAIN_MAIL_AUTOCOPY_TO = getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO');
$conf->global->MAIN_MAIL_AUTOCOPY_TO = '';
Expand Down
8 changes: 4 additions & 4 deletions htdocs/core/triggers/interface_80_modStripe_Stripe.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
}

// If payment mode is linked to Stripe, we update/delete Stripe too
if ($action == 'COMPANYPAYMENTMODE_CREATE' && $object->type == 'card') {
// For creation of credit card, we do not create in Stripe automatically
}
if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card' && $object instanceof CompanyPaymentMode) {
//if ($action == 'COMPANYPAYMENTMODE_CREATE' && $object instanceof CompanyPaymentMode && $object->type == 'card') {
// For creation of credit card, we do not create in Stripe automatically
//}
if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object instanceof CompanyPaymentMode && $object->type == 'card') {
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);

if (!empty($object->stripe_card_ref)) {
Expand Down
Loading

0 comments on commit 178d748

Please sign in to comment.