Qual: Fix phan notices in some payment/strip related classes (#31453)

* fix concat

* fix overwrite

* Clean code

* Do not analyze custom

* Update baseline, ignore everything in custom

* Qual: Fix notices in files related to ticket class

* Qual: Fix companybankaccount.class

* Fix phan/phpstan notices

---------

Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com>
Co-authored-by: Frédéric FRANCE <frederic.france@free.fr>
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
MDW 2024-10-20 00:32:01 +02:00 committed by GitHub
parent c44e0e1d0c
commit fb3972b702
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 222 additions and 57 deletions

View File

@ -10,8 +10,8 @@
return [
// # Issue statistics:
// PhanUndeclaredProperty : 770+ occurrences
// PhanPluginUnknownPropertyType : 710+ occurrences
// PhanPossiblyUndeclaredGlobalVariable : 600+ occurrences
// PhanPluginUnknownPropertyType : 660+ occurrences
// PhanPossiblyUndeclaredGlobalVariable : 580+ occurrences
// PhanTypeMismatchArgumentProbablyReal : 400+ occurrences
// PhanUndeclaredGlobalVariable : 380+ occurrences
// PhanPluginUnknownArrayMethodReturnType : 300+ occurrences
@ -787,18 +787,15 @@ return [
'htdocs/societe/class/api_contacts.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchProperty'],
'htdocs/societe/class/api_thirdparties.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'],
'htdocs/societe/class/client.class.php' => ['PhanPluginUnknownArrayPropertyType'],
'htdocs/societe/class/companybankaccount.class.php' => ['PhanPluginUnknownPropertyType'],
'htdocs/societe/class/companypaymentmode.class.php' => ['PhanPluginUnknownPropertyType'],
'htdocs/societe/class/societeaccount.class.php' => ['PhanPluginUnknownPropertyType'],
'htdocs/societe/consumption.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'],
'htdocs/societe/list.php' => ['PhanPluginUndeclaredVariableIsset', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'],
'htdocs/societe/paymentmodes.php' => ['PhanPossiblyNullTypeMismatchProperty', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchProperty', 'PhanUndeclaredGlobalVariable'],
'htdocs/societe/paymentmodes.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeExpectedObjectPropAccess', 'PhanUndeclaredGlobalVariable'],
'htdocs/societe/price.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'],
'htdocs/societe/tpl/linesalesrepresentative.tpl.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'htdocs/societe/website.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'htdocs/stripe/ajax/ajax.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'htdocs/stripe/class/actions_stripe.class.php' => ['PhanPluginBothLiteralsBinaryOp', 'PhanPluginSuspiciousParamPosition', 'PhanPluginUnknownArrayMethodParamType', 'PhanUndeclaredProperty'],
'htdocs/stripe/class/stripe.class.php' => ['PhanPluginConstantVariableNull', 'PhanPluginEmptyStatementIf', 'PhanPossiblyUndeclaredVariable', 'PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'],
'htdocs/stripe/class/actions_stripe.class.php' => ['PhanPluginBothLiteralsBinaryOp', 'PhanPluginSuspiciousParamPosition'],
'htdocs/stripe/class/stripe.class.php' => ['PhanPluginConstantVariableNull', 'PhanPluginEmptyStatementIf', 'PhanPossiblyUndeclaredVariable', 'PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchProperty'],
'htdocs/supplier_proposal/card.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/supplier_proposal/class/api_supplier_proposals.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanUndeclaredProperty'],
'htdocs/supplier_proposal/class/supplier_proposal.class.php' => ['PhanUndeclaredProperty'],

View File

@ -716,8 +716,8 @@ if ($event->type == 'payout.created') {
$companypaymentmode->last_four = $db->escape($event->data->object->card->last4);
$companypaymentmode->card_type = $db->escape($event->data->object->card->branding);
$companypaymentmode->proprio = $db->escape($event->data->object->billing_details->name);
$companypaymentmode->exp_date_month = $db->escape($event->data->object->card->exp_month);
$companypaymentmode->exp_date_year = $db->escape($event->data->object->card->exp_year);
$companypaymentmode->exp_date_month = (int) $event->data->object->card->exp_month;
$companypaymentmode->exp_date_year = (int) $event->data->object->card->exp_year;
$companypaymentmode->cvn = null;
$companypaymentmode->datec = $db->escape($event->data->object->created);
$companypaymentmode->default_rib = 0;
@ -754,8 +754,8 @@ if ($event->type == 'payout.created') {
$companypaymentmode->number = $db->escape($event->data->object->id);
$companypaymentmode->last_four = $db->escape($event->data->object->card->last4);
$companypaymentmode->proprio = $db->escape($event->data->object->billing_details->name);
$companypaymentmode->exp_date_month = $db->escape($event->data->object->card->exp_month);
$companypaymentmode->exp_date_year = $db->escape($event->data->object->card->exp_year);
$companypaymentmode->exp_date_month = (int) $event->data->object->card->exp_month;
$companypaymentmode->exp_date_year = (int) $event->data->object->card->exp_year;
$companypaymentmode->cvn = null;
$companypaymentmode->datec = $db->escape($event->data->object->created);
$companypaymentmode->default_rib = 0;

View File

@ -166,13 +166,34 @@ class CompanyBankAccount extends Account
* @var string label
*/
public $label;
/**
* @var string
*/
public $code_banque;
/**
* @var string
*/
public $code_guichet;
/**
* @var string
*/
public $number;
/**
* @var string
*/
public $cle_rib;
/**
* @var string
*/
public $bic;
/**
* @var string
*/
public $iban_prefix;
/**
* @var string
*/
public $bank;
/**
@ -185,6 +206,9 @@ class CompanyBankAccount extends Account
*/
public $fk_country;
/**
* @var string
*/
public $country_code;
/**
@ -213,22 +237,58 @@ class CompanyBankAccount extends Account
* @var string
*/
public $frstrecur;
/**
* @var string
*/
public $import_key;
/**
* @var string
*/
public $last_four;
/**
* @var string
*/
public $card_type;
/**
* @var string
*/
public $cvn;
/**
* @var int
*/
public $exp_date_month;
/**
* @var int
*/
public $exp_date_year;
/**
* @var int
*/
public $approved;
/**
* @var string email
*/
public $email;
/**
* @var int|string
*/
public $ending_date;
/**
* @var float
*/
public $max_total_amount_of_all_payments;
/**
* @var string
*/
public $preapproval_key;
/**
* @var int|string
*/
public $starting_date;
/**
* @var float
*/
public $total_amount_of_all_payments;
@ -302,7 +362,7 @@ class CompanyBankAccount extends Account
/**
* Create bank information record.
*
* @param $user User
* @param ?User $user User
* @param int<0,1> $notrigger 1=Disable triggers
* @return int Return integer <0 if KO, > 0 if OK (ID of newly created company bank account information)
*/

View File

@ -131,46 +131,129 @@ class CompanyPaymentMode extends CommonObject
*/
public $label;
/**
* @var ?string
*/
public $bank;
/**
* @var string
*/
public $code_banque;
/**
* @var string
*/
public $code_guichet;
/**
* @var string
*/
public $number;
/**
* @var string
*/
public $cle_rib;
/**
* @var string
*/
public $bic;
/**
* @var string iban
* @deprecated
* @deprecated Use $iban_prefix
* @see $iban_prefix
*/
public $iban;
/**
* iban_prefix
* @var string
* @var string IBAN prefix
*/
public $iban_prefix;
/**
* @var string
*/
public $domiciliation;
/**
* @var string
*/
public $proprio;
/**
* @var string
*/
public $owner_address;
/**
* @var int
*/
public $default_rib;
/**
* @var string
*/
public $rum;
/**
* @var int
*/
public $date_rum;
/**
* @var string
*/
public $frstrecur;
/**
* @var string
*/
public $type;
/**
* @var string
*/
public $last_four;
/**
* @var string
*/
public $card_type;
/**
* @var ?string
*/
public $cvn;
/**
* @var int
*/
public $exp_date_month;
/**
* @var int
*/
public $exp_date_year;
/**
* @var string
*/
public $country_code;
/**
* @var int
*/
public $approved;
/**
* @var string
*/
public $email;
/**
* @var float
*/
public $max_total_amount_of_all_payments;
/**
* @var string
*/
public $preapproval_key;
/**
* @var float
*/
public $total_amount_of_all_payments;
/**
* @var string
*/
public $stripe_card_ref; // External system payment mode ID
/**
* @var string
*/
public $stripe_account; // External system customer ID
/**
* @var string
*/
public $ext_payment_site; // External system 'StripeLive', 'StripeTest', 'StancerLive', 'StancerTest', ...
/**
@ -178,16 +261,25 @@ class CompanyPaymentMode extends CommonObject
*/
public $status;
/**
* @var int
*/
public $starting_date;
/**
* @var int
*/
public $ending_date;
/**
* Date creation record (datec)
*
* @var integer
* @var int
*/
public $datec;
/**
* @var string
*/
public $import_key;
// END MODULEBUILDER PROPERTIES
@ -348,11 +440,11 @@ class CompanyPaymentMode extends CommonObject
/**
* Return a link to the object card (with optionally the picto)
*
* @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
* @param string $option On what the link point to ('nolink', ...)
* @param int $notooltip 1=Disable tooltip
* @param string $morecss Add more css on link
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
* @param int<0,2> $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
* @param string $option On what the link point to ('nolink', ...)
* @param int<0,1> $notooltip 1=Disable tooltip
* @param string $morecss Add more css on link
* @param int<-1,1> $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
* @return string String with URL
*/
public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
@ -417,9 +509,9 @@ class CompanyPaymentMode extends CommonObject
/**
* Set a Payment mode as Default
*
* @param int $id Payment mode ID
* @param int $alltypes 1=The default is for all payment types instead of per type
* @return int 0 if KO, 1 if OK
* @param int $id Payment mode ID
* @param int<0,1> $alltypes 1=The default is for all payment types instead of per type
* @return int 0 if KO, 1 if OK
*/
public function setAsDefault($id = 0, $alltypes = 0)
{
@ -475,8 +567,8 @@ class CompanyPaymentMode extends CommonObject
/**
* Return label of the status
*
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
* @return string Label of status
* @param int<0,6> $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
* @return string Label of status
*/
public function getLibStatut($mode = 0)
{
@ -487,8 +579,8 @@ class CompanyPaymentMode extends CommonObject
/**
* Return the status
*
* @param int $status Id status
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
* @param int $status Id status
* @param int<0,6> $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
* @return string Label of status
*/
public function LibStatut($status, $mode = 0)

View File

@ -94,10 +94,12 @@ $stripe = null; // Stripe object
$stripeacc = null; // Stripe Account
$stripecu = null; // Remote stripe customer
$servicestatus = 0;
$site_account = 'UnknownSiteAccount';
// Init Stripe objects
if (isModEnabled('stripe')) {
$service = 'StripeTest';
$servicestatus = 0;
if (getDolGlobalString('STRIPE_LIVE') && !GETPOST('forcesandbox', 'alpha')) {
$service = 'StripeLive';
$servicestatus = 1;
@ -168,7 +170,8 @@ if (empty($reshook)) {
}
if (!$error) {
$companybankaccount->oldcopy = dol_clone($companybankaccount, 2);
$cbClassName = get_class($companybankaccount);
$cbClassName::$oldcopy = dol_clone($companybankaccount, 2);
$companybankaccount->socid = $object->id;
@ -246,7 +249,8 @@ if (empty($reshook)) {
$companypaymentmode->fetch($id);
if (!$error) {
$companybankaccount->oldcopy = dol_clone($companybankaccount, 2);
$cbClassName = get_class($companybankaccount);
$cbClassName::$oldcopy = dol_clone($companybankaccount, 2);
$companypaymentmode->fk_soc = $object->id;
@ -905,7 +909,7 @@ if (!$id) {
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
$companybankaccount->fetch(0, '', $object->id);
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
$companypaymentmode->fetch(0, null, $object->id, 'card');
$companypaymentmode->fetch(0, '', $object->id, 'card');
} else {
$companybankaccount->fetch($id);
$companypaymentmode->fetch($id);
@ -1142,6 +1146,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
// Get list of remote payment modes
$listofsources = array();
$customerstripe = null;
if (isset($stripe) && is_object($stripe)) {
try {
$customerstripe = $stripe->customerStripe($object, $stripeacc, $servicestatus);
@ -1631,14 +1636,14 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
// } elseif ($val == 'IBAN') {
// $string .= $rib->iban.' ';*/
//}
}
if (!empty($rib->label) && $rib->number) {
if (!checkBanForAccount($rib)) {
$string .= ' '.img_picto($langs->trans("ValueIsNotValid"), 'warning');
} else {
$string .= ' '.img_picto($langs->trans("ValueIsValid"), 'info');
if (!empty($rib->label) && $rib->number) {
if (!checkBanForAccount($rib)) {
$string .= ' '.img_picto($langs->trans("ValueIsNotValid"), 'warning');
} else {
$string .= ' '.img_picto($langs->trans("ValueIsValid"), 'info');
}
}
}
} // EndFor $rib_list as $rib
print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($string).'">';
print $string;
print '</td>';
@ -1721,7 +1726,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
if ($conf->browser->layout == 'phone') {
$morecss = 'maxwidth100';
}
$out .= $formadmin->select_language($defaultlang, 'lang_idrib'.$rib->id, 0, 0, 0, 0, 0, $morecss);
$out .= $formadmin->select_language($defaultlang, 'lang_idrib'.$rib->id, 0, array(), 0, 0, 0, $morecss);
}
// Button
$out .= '<input class="button buttongen reposition nomargintop nomarginbottom" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
@ -1922,7 +1927,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
$companybankaccounttemp = new CompanyBankAccount($db);
$companypaymentmodetemp = new CompanyPaymentMode($db);
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
$result = $companypaymentmodetemp->fetch(0, null, $object->id, 'ban');
$result = $companypaymentmodetemp->fetch(0, '', $object->id, 'ban');
include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
$ecmfile = new EcmFiles($db);
@ -1991,6 +1996,9 @@ if ($socid && $action == 'edit' && $permissiontoaddupdatepaymentinformation) {
foreach ($bankaccount->getFieldsToShow(1) as $val) {
$require = false;
$tooltip = '';
$name = 'Unset';
$size = 8;
$content = 'NoContent';
if ($val == 'BankCode') {
$name = 'code_banque';
$size = 8;
@ -2028,6 +2036,7 @@ if ($socid && $action == 'edit' && $permissiontoaddupdatepaymentinformation) {
print '<tr>';
print '<td'.($require ? ' class="fieldrequired" ' : '').'>';
if ($tooltip) {
// $tooltip looks like $tooltiptrigger so: @phan-suppress-next-line PhanPluginSuspiciousParamOrder
print $form->textwithpicto($langs->trans($val), $tooltip, 4, 'help', '', 0, 3, $name);
} else {
print $langs->trans($val);
@ -2163,6 +2172,9 @@ if ($socid && $action == 'create' && $permissiontoaddupdatepaymentinformation) {
foreach ($companybankaccount->getFieldsToShow(1) as $val) {
$require = false;
$tooltip = '';
$size = 8;
$name = 'Unknown';
$content = 'NoContent';
if ($val == 'BankCode') {
$name = 'code_banque';
$size = 8;
@ -2199,6 +2211,7 @@ if ($socid && $action == 'create' && $permissiontoaddupdatepaymentinformation) {
print '<tr><td'.($require ? ' class="fieldrequired" ' : '').'>';
if ($tooltip) {
// tooltip lookslike tooltip trigger so @phan-suppress-next-line PhanPluginSuspiciousParamOrder
print $form->textwithpicto($langs->trans($val), $tooltip, 4, 'help', '', 0, 3, $name);
} else {
print $langs->trans($val);

View File

@ -110,7 +110,7 @@ if ($action == 'getConnexionToken') {
$stripe = new Stripe($db);
$customer = $stripe->customerStripe($object->thirdparty, $stripeacc, $servicestatus, 1);
$intent = $stripe->getPaymentIntent($json_obj->amount, $object->multicurrency_code, null, 'Stripe payment: '.$fulltag.(is_object($object) ? ' ref='.$object->ref : ''), $object, $customer, $stripeacc, $servicestatus, 1, 'terminal', false, null, 0, 1);
$intent = $stripe->getPaymentIntent($json_obj->amount, $object->multicurrency_code, '', 'Stripe payment: '.$fulltag.(is_object($object) ? ' ref='.$object->ref : ''), $object, $customer, $stripeacc, $servicestatus, 1, 'terminal', false, null, 0, 1);
echo json_encode(array('client_secret' => $intent->client_secret));
} catch (Error $e) {

View File

@ -59,10 +59,10 @@ class ActionsStripeconnect extends CommonHookActions
/**
* formObjectOptions
*
* @param array $parameters Parameters
* @param CommonObject $object Object
* @param string $action Action
* @return int
* @param array<string,mixed> $parameters Parameters
* @param CommonObject $object Object
* @param string $action Action
* @return int
*/
public function formObjectOptions($parameters, &$object, &$action)
{
@ -82,6 +82,7 @@ class ActionsStripeconnect extends CommonHookActions
}
if (is_object($object) && $object->element == 'societe') {
'@phan-var-force Societe $object';
$this->resprints .= '<tr><td>';
$this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
$this->resprints .= $langs->trans('StripeCustomer');
@ -99,6 +100,7 @@ class ActionsStripeconnect extends CommonHookActions
}
$this->resprints .= '</td></tr>';
} elseif ($object instanceof CommonObject && $object->element == 'member') {
'@phan-var-force Adherent $object';
$this->resprints .= '<tr><td>';
$this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
$this->resprints .= $langs->trans('StripeCustomer');
@ -133,6 +135,7 @@ class ActionsStripeconnect extends CommonHookActions
}
$this->resprints .= '</td></tr>';
} elseif ($object instanceof CommonObject && $object->element == 'adherent_type') {
'@phan-var-force Adherent $object';
$this->resprints .= '<tr><td>';
$this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
$this->resprints .= $langs->trans('PlanStripe');
@ -157,9 +160,9 @@ class ActionsStripeconnect extends CommonHookActions
/**
* addMoreActionsButtons
*
* @param array $parameters Parameters
* @param Object $object Object
* @param string $action action
* @param array<string,mixed> $parameters Parameters
* @param Object $object Object
* @param string $action action
* @return int 0
*/
public function addMoreActionsButtons($parameters, &$object, &$action)

View File

@ -170,13 +170,13 @@ class Stripe extends CommonObject
* Get the Stripe customer of a thirdparty (with option to create it in Stripe if not linked yet).
* Search on site_account = 0 or = $stripearrayofkeysbyenv[$status]['publishable_key']
*
* @param CommonObject $object Object thirdparty to check, or create on stripe (create on stripe also update the stripe_account table for current entity). Used for AdherentType and Societe.
* @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect
* @param int $status Status (0=test, 1=live)
* @param int $createifnotlinkedtostripe 1=Create the stripe customer and the link if the thirdparty is not yet linked to a stripe customer
* @param Societe|Adherent $object Object thirdparty to check, or create on stripe (create on stripe also update the stripe_account table for current entity). Used for AdherentType and Societe.
* @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect
* @param int<0,1> $status Status (0=test, 1=live)
* @param int<0,1> $createifnotlinkedtostripe 1=Create the stripe customer and the link if the thirdparty is not yet linked to a stripe customer
* @return \Stripe\Customer|null Stripe Customer or null if not found
*/
public function customerStripe(CommonObject $object, $key = '', $status = 0, $createifnotlinkedtostripe = 0)
public function customerStripe($object, $key = '', $status = 0, $createifnotlinkedtostripe = 0)
{
global $conf, $user;
@ -1362,7 +1362,7 @@ class Stripe extends CommonObject
$charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$description", "stripe_account" => "$account"));
}
}
'@phan-var-force stdclass|\Stripe\Charge $charge';
'@phan-var-force stdClass|\Stripe\Charge $charge';
if (isset($charge->id)) {
}
@ -1377,7 +1377,7 @@ class Stripe extends CommonObject
} elseif ($charge->source->type == 'three_d_secure') {
$stripe = new Stripe($this->db);
$src = \Stripe\Source::retrieve("".$charge->source->three_d_secure->card, array(
"stripe_account" => $stripe->getStripeAccount($service)
"stripe_account" => $stripe->getStripeAccount($service)
));
$return->message = $src->card->brand." ....".$src->card->last4;
} else {