Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Multiple fixes inspired by phpstan level 5 and phan #29143

Merged
merged 8 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion htdocs/admin/security_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Copyright (C) 2004-2017 Laurent Destailleur <[email protected]>
* Copyright (C) 2005-2017 Regis Houssin <[email protected]>
* Copyright (C) 2013 Juanjo Menent <[email protected]>
* Copyright (C) 2024 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 @@ -86,7 +87,7 @@
if (!preg_match('/^0/', $tmpumask)) {
$tmpumask = '0'.$tmpumask;
}
if (empty($tmpumask) || $tmpumask === '0') {
if (empty($tmpumask)) { // Also matches '0'
$tmpumask = '0664';
}

Expand Down
17 changes: 9 additions & 8 deletions htdocs/core/class/notify.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Copyright (C) 2022 Anthony Berton <[email protected]>
* Copyright (C) 2023 William Mead <[email protected]>
* Copyright (C) 2024 Jon Bendtsen <[email protected]>
* Copyright (C) 2024 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 @@ -213,7 +214,7 @@ public function confirmMessage($action, $socid, $object)
$texte = img_object($langs->trans("Notifications"), 'email', 'class="pictofixedwidth"').$langs->trans("NoNotificationsWillBeSent");
} elseif ($nb == 1) {
$texte = img_object($langs->trans("Notifications"), 'email', 'class="pictofixedwidth"').$langs->trans("ANotificationsWillBeSent");
} elseif ($nb >= 2) {
} else { // Always >= 2 if ($nb >= 2) {
$texte = img_object($langs->trans("Notifications"), 'email', 'class="pictofixedwidth"').$langs->trans("SomeNotificationsWillBeSent", $nb);
}

Expand Down Expand Up @@ -485,7 +486,7 @@ public function getNotificationsArray($notifcode, $socid = 0, $object = null, $u
$newval2 = trim($obj->email);
$isvalid = isValidEmail($newval2);
if (empty($resarray[$newval2])) {
$resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
$resarray[$newval2] = array('type' => 'tocontact', 'code' => trim($obj->code), 'emaildesc' => 'Contact id '.$obj->rowid, 'email' => $newval2, 'contactid' => $obj->rowid, 'isemailvalid' => $isvalid);
}
}
$i++;
Expand Down Expand Up @@ -524,7 +525,7 @@ public function getNotificationsArray($notifcode, $socid = 0, $object = null, $u
$newval2 = trim($obj->email);
$isvalid = isValidEmail($newval2);
if (empty($resarray[$newval2])) {
$resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
$resarray[$newval2] = array('type' => 'touser', 'code' => trim($obj->code), 'emaildesc' => 'User id '.$obj->rowid, 'email' => $newval2, 'userid' => $obj->rowid, 'isemailvalid' => $isvalid);
}
}
$i++;
Expand Down Expand Up @@ -575,7 +576,7 @@ public function getNotificationsArray($notifcode, $socid = 0, $object = null, $u
if ($newval2) {
$isvalid = isValidEmail($newval2, 0);
if (empty($resarray[$newval2])) {
$resarray[$newval2] = array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
$resarray[$newval2] = array('type' => 'tofixedemail', 'code' => trim($key), 'emaildesc' => trim($val2), 'email' => $newval2, 'isemailvalid' => $isvalid);
}
}
}
Expand Down Expand Up @@ -889,7 +890,7 @@ public function send($notifcode, $object, $filename_list = array(), $mimetype_li
$dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object, $object_type);
$template = $notifcode.'_TEMPLATE';
$mesg = $outputlangs->transnoentitiesnoconv('Notify_'.$notifcode).' '.$newref.' '.$dir_output;
break;
break;
}

include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
Expand All @@ -915,7 +916,7 @@ public function send($notifcode, $object, $filename_list = array(), $mimetype_li

$ref = dol_sanitizeFileName($newref);
$pdf_path = $dir_output."/".$ref.".pdf";
if (!dol_is_file($pdf_path)||(is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
if (!dol_is_file($pdf_path) || (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) {
// We can't add PDF as it is not generated yet.
$filepdf = '';
} else {
Expand Down Expand Up @@ -944,7 +945,7 @@ public function send($notifcode, $object, $filename_list = array(), $mimetype_li
$sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string
}

$parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list, 'outputlangs'=>$outputlangs, 'labeltouse'=>$labeltouse);
$parameters = array('notifcode' => $notifcode, 'sendto' => $sendto, 'replyto' => $replyto, 'file' => $filename_list, 'mimefile' => $mimetype_list, 'filename' => $mimefilename_list, 'outputlangs' => $outputlangs, 'labeltouse' => $labeltouse);
if (!isset($action)) {
$action = '';
}
Expand Down Expand Up @@ -1210,7 +1211,7 @@ public function send($notifcode, $object, $filename_list = array(), $mimetype_li
}

if ($sendto) {
$parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list, 'subject'=>&$subject, 'message'=>&$message);
$parameters = array('notifcode' => $notifcode, 'sendto' => $sendto, 'replyto' => $replyto, 'file' => $filename_list, 'mimefile' => $mimetype_list, 'filename' => $mimefilename_list, 'subject' => &$subject, 'message' => &$message);
$reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook)) {
if (!empty($hookmanager->resArray['files'])) {
Expand Down
26 changes: 13 additions & 13 deletions htdocs/core/lib/barcode.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
*
* @param string $code Code
* @param string $encoding Encoding ('EAN13', 'ISBN', 'C128', 'UPC', 'CBR', 'QRCODE', 'DATAMATRIX', 'ANY'...)
* @param integer $scale Scale
* @param int<1,max> $scale Scale
* @param string $mode 'png' or 'jpg' ...
* @return array|string $bars array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info) or string with error message
* @return array{encoding:string,bars:string,text:string}|string $bars array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info) or string with error message
*/
function barcode_print($code, $encoding = "ANY", $scale = 2, $mode = "png")
{
Expand Down Expand Up @@ -124,7 +124,7 @@ function barcode_print($code, $encoding = "ANY", $scale = 2, $mode = "png")
*
* @param string $code Code
* @param string $encoding Encoding
* @return array|false array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info)
* @return array{encoding:string,bars:string,text:string}|false array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info)
*/
function barcode_encode($code, $encoding)
{
Expand Down Expand Up @@ -172,7 +172,7 @@ function barcode_encode($code, $encoding)
* Calculate EAN sum
*
* @param string $ean EAN to encode
* @return integer Sum
* @return int<0,9> EAN Sum
*/
function barcode_gen_ean_sum($ean)
{
Expand Down Expand Up @@ -206,8 +206,8 @@ function barcode_gen_ean_bars($ean)

$line = $guards[0];
for ($i = 1; $i < 13; $i++) {
$str = $digits[$ean[$i]];
if ($i < 7 && $mirror[$ean[0]][$i - 1] == 1) {
$str = $digits[(int) $ean[$i]];
if ($i < 7 && $mirror[(int) $ean[0]][$i - 1] == 1) {
$line .= strrev($str);
} else {
$line .= $str;
Expand All @@ -226,7 +226,7 @@ function barcode_gen_ean_bars($ean)
*
* @param string $ean Code
* @param string $encoding Encoding
* @return array array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info, 'error': error message if error)
* @return array{encoding:string,bars:string,text:string,error:string}|array{text:string,error:string} array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info, 'error': error message if error)
*/
function barcode_encode_ean($ean, $encoding = "EAN-13")
{
Expand Down Expand Up @@ -282,7 +282,7 @@ function barcode_encode_ean($ean, $encoding = "EAN-13")
*
* @param string $upc Code
* @param string $encoding Encoding
* @return array array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info, 'error': error message if error)
* @return array{encoding:string,bars:string,text:string,error:string}|array{text:string,error:string} array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info, 'error': error message if error)
*/
function barcode_encode_upc($upc, $encoding = "UPC")
{
Expand Down Expand Up @@ -332,7 +332,7 @@ function barcode_encode_upc($upc, $encoding = "UPC")
*
* @param string $code Code
* @param string $encoding Encoding
* @return array|false array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info)
* @return array{encoding:string,bars:string,text:string}|false array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info)
*/
function barcode_encode_genbarcode($code, $encoding)
{
Expand Down Expand Up @@ -403,10 +403,10 @@ function barcode_encode_genbarcode($code, $encoding)
*
* @param string $text the text-line (<position>:<font-size>:<character> ...)
* @param string $bars where to place the bars (<space-width><bar-width><space-width><bar-width>...)
* @param int $scale scale factor ( 1 < scale < unlimited (scale 50 will produce 5400x300 pixels when using EAN-13!!!))
* @param int<1,max> $scale scale factor ( 1 < scale < unlimited (scale 50 will produce 5400x300 pixels when using EAN-13!!!))
* @param string $mode png,gif,jpg (default='png')
* @param int $total_y the total height of the image ( default: scale * 60 )
* @param array $space default: $space[top] = 2 * $scale; $space[bottom]= 2 * $scale; $space[left] = 2 * $scale; $space[right] = 2 * $scale;
* @param array{}|array{top:int,bottom:int,left:int,right:int} $space default: $space[top] = 2 * $scale; $space[bottom]= 2 * $scale; $space[left] = 2 * $scale; $space[right] = 2 * $scale;
* @return string|void
*/
function barcode_outimage($text, $bars, $scale = 1, $mode = "png", $total_y = 0, $space = [])
Expand All @@ -424,7 +424,7 @@ function barcode_outimage($text, $bars, $scale = 1, $mode = "png", $total_y = 0,
if ($total_y < 1) {
$total_y = (int) $scale * 60;
}
if (!$space) {
if (!is_array($space) || empty($space)) {
$space = array('top' => 2 * $scale, 'bottom' => 2 * $scale, 'left' => 2 * $scale, 'right' => 2 * $scale);
}

Expand All @@ -435,7 +435,7 @@ function barcode_outimage($text, $bars, $scale = 1, $mode = "png", $total_y = 0,
for ($i = 0; $i < $ln; $i++) {
$val = strtolower($bars[$i]);
if ($width) {
$xpos += $val * $scale;
$xpos += (int) $val * $scale;
$width = false;
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/lib/functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -8992,8 +8992,8 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
* $mesg = make_substitutions($mesg, $substitutionarray, $langs);
*
* @param string $text Source string in which we must do substitution
* @param array $substitutionarray Array with key->val to substitute. Example: array('__MYKEY__' => 'MyVal', ...)
* @param Translate $outputlangs Output language
* @param array<string,string> $substitutionarray Array with key->val to substitute. Example: array('__MYKEY__' => 'MyVal', ...)
* @param ?Translate $outputlangs Output language
* @param int $converttextinhtmlifnecessary 0=Convert only value into HTML if text is already in HTML
* 1=Will also convert initial $text into HTML if we try to insert one value that is HTML
* @return string Output string after substitutions
Expand Down
Loading
Loading