瀏覽代碼

Enhance scan using phpstan

Laurent Destailleur 5 年之前
父節點
當前提交
2e68488231

+ 1 - 1
build/phpstan/bootstrap.php

@@ -8,7 +8,7 @@ define('DOL_DOCUMENT_ROOT', __DIR__ . '/../../htdocs');
 define('DOL_DATA_ROOT', __DIR__ . '/../../documents');
 define('DOL_URL_ROOT', '/');
 
-// Load the main.inc.php file to have finctions llx_Header and llx_Footer defined
+// Load the main.inc.php file to have functions llx_Header and llx_Footer defined
 if (! defined("NOLOGIN")) define("NOLOGIN", '1');
 global $conf, $langs, $user, $db;
 include_once __DIR__ . '/../../htdocs/main.inc.php';

+ 4 - 4
htdocs/societe/ajax/company.php

@@ -1,7 +1,7 @@
 <?php
 /* Copyright (C) 2006      Andre Cianfarani     <acianfa@free.fr>
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@inodbox.com>
- * Copyright (C) 2007-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2007-2019 Laurent Destailleur  <eldy@users.sourceforge.net>
  *
  * 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
@@ -58,12 +58,12 @@ if (! empty($action) && $action == 'fetch' && ! empty($id))
 	$ret=$object->fetch($id);
 	if ($ret > 0)
 	{
-		$outname=$object->name;
-		$outlabel = '';
+		$outref = $object->ref;
+		$outname = $object->name;
 		$outdesc = '';
 		$outtype = $object->type;
 
-		$outjson = array('ref' => $outref,'name' => $outname,'desc' => $outdesc,'type' => $outtype);
+		$outjson = array('ref' => $outref, 'name' => $outname, 'desc' => $outdesc, 'type' => $outtype);
 	}
 
 	echo json_encode($outjson);

+ 4 - 2
htdocs/societe/canvas/company/actions_card_company.class.php

@@ -23,9 +23,11 @@
  */
 include_once DOL_DOCUMENT_ROOT.'/societe/canvas/actions_card_common.class.php';
 
+
 /**
- *	\class      ActionsCardCompany
- *	\brief      Class with controller methods for thirdparty canvas
+ *	ActionsCardCompany
+ *
+ *	Class with controller methods for thirdparty canvas
  */
 class ActionsCardCompany extends ActionsCardCommon
 {

+ 4 - 2
htdocs/societe/canvas/individual/actions_card_individual.class.php

@@ -22,9 +22,11 @@
  */
 include_once DOL_DOCUMENT_ROOT.'/societe/canvas/actions_card_common.class.php';
 
+
 /**
- *	\class      ActionsCardIndividual
- *	\brief      Class with controller methods for individual canvas
+ *	ActionsCardIndividual
+ *
+ *	Class with controller methods for individual canvas
  */
 class ActionsCardIndividual extends ActionsCardCommon
 {

+ 3 - 9
htdocs/societe/card.php

@@ -251,10 +251,10 @@ if (empty($reshook))
 				// External modules should update their ones too
 				if (! $error)
 				{
-    $reshook = $hookmanager->executeHooks('replaceThirdparty', array(
+					$reshook = $hookmanager->executeHooks('replaceThirdparty', array(
 						'soc_origin' => $soc_origin->id,
 						'soc_dest' => $object->id
-					), $soc_dest, $action);
+					), $object, $action);
 
 					if ($reshook < 0)
 					{
@@ -1188,7 +1188,7 @@ else
         // Prospect/Customer
         print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
 	    print '<td class="maxwidthonsmartphone">';
-	    $selected=(GETPOSTISSET('client', 'int')?GETPOST('client', 'int'):$object->client);
+	    $selected=(GETPOSTISSET('client')?GETPOST('client', 'int'):$object->client);
 	    print $formcompany->selectProspectCustomerType($selected);
 	    print '</td>';
 
@@ -2257,7 +2257,6 @@ else
         if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
         {
             print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.$object->prefix_comm.'</td>';
-            print $htmllogobar; $htmllogobar='';
             print '</tr>';
         }
 
@@ -2269,7 +2268,6 @@ else
             print $object->code_client;
             if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
             print '</td>';
-            print $htmllogobar; $htmllogobar='';
             print '</tr>';
         }
 
@@ -2281,7 +2279,6 @@ else
             print $object->code_fournisseur;
             if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
             print '</td>';
-            print $htmllogobar; $htmllogobar='';
             print '</tr>';
         }
 
@@ -2291,9 +2288,6 @@ else
             print '<tr><td>';
             print $langs->trans('Gencod').'</td><td>'.$object->barcode;
             print '</td>';
-			if ($htmllogobar) $htmllogobar.=$form->showbarcode($object);
-            print $htmllogobar;
-			$htmllogobar='';
             print '</tr>';
         }
 

+ 1 - 1
htdocs/societe/class/companypaymentmode.class.php

@@ -310,7 +310,7 @@ class CompanyPaymentMode extends CommonObject
 		if ($type)  $morewhere.= " AND type = '".$this->db->escape($type)."'";
 
 		$result = $this->fetchCommon($id, $ref, $morewhere);
-		if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
+		//if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
 		return $result;
 	}
 

+ 1 - 1
htdocs/societe/class/societeaccount.class.php

@@ -79,7 +79,7 @@ class SocieteAccount extends CommonObject
 	public $fields=array(
 		'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
 		'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>5, 'default'=>1),
-		'key_account' => array('type'=>'varchar(128)', 'label'=>'KeyAccount', 'visible'=>-1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Key account',),
+		'key_account' => array('type'=>'varchar(128)', 'label'=>'KeyAccount', 'visible'=>1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Key account',),
 		'login' => array('type'=>'varchar(64)', 'label'=>'Login', 'visible'=>1, 'enabled'=>1, 'position'=>10),
 		'pass_encoding' => array('type'=>'varchar(24)', 'label'=>'PassEncoding', 'visible'=>0, 'enabled'=>1, 'position'=>30),
 		'pass_crypted' => array('type'=>'varchar(128)', 'label'=>'Password', 'visible'=>1, 'enabled'=>1, 'position'=>31, 'notnull'=>1),

+ 1 - 36
htdocs/societe/index.php

@@ -63,41 +63,6 @@ print load_fiche_titre($transAreaType, $linkback, 'title_companies.png');
 print '<div class="fichecenter"><div class="fichethirdleft">';
 
 
-if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo
-{
-    // Search thirdparty
-    if (! empty($conf->societe->enabled) && $user->rights->societe->lire)
-    {
-    	$listofsearchfields['search_thirdparty']=array('text'=>'ThirdParty');
-    }
-    // Search contact/address
-    if (! empty($conf->societe->enabled) && $user->rights->societe->lire)
-    {
-    	$listofsearchfields['search_contact']=array('text'=>'Contact');
-    }
-
-    if (count($listofsearchfields))
-    {
-    	print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
-    	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-    	print '<table class="noborder nohover centpercent">';
-    	$i=0;
-    	foreach($listofsearchfields as $key => $value)
-    	{
-    		if ($i == 0) print '<tr class="liste_titre"><th colspan="3">'.$langs->trans("Search").'</th></tr>';
-    		print '<tr '.$bc[false].'>';
-    		print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>';
-    		if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
-    		print '</tr>';
-    		$i++;
-    	}
-    	print '</table>';
-    	print '</form>';
-    	print '<br>';
-    }
-}
-
-
 /*
  * Statistics area
  */
@@ -194,7 +159,7 @@ if (! empty($conf->categorie->enabled) && ! empty($conf->global->CATEGORY_GRAPHS
 	print '<div class="div-table-responsive-no-min">';
 	print '<table class="noborder nohover" width="100%">';
 	print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Categories").'</th></tr>';
-	print '<tr '.$bc[0].'><td class="center" colspan="2">';
+	print '<tr><td class="center" colspan="2">';
 	$sql = "SELECT c.label, count(*) as nb";
 	$sql.= " FROM ".MAIN_DB_PREFIX."categorie_societe as cs";
 	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";

+ 2 - 2
htdocs/societe/paymentmodes.php

@@ -1208,8 +1208,8 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
 		print_liste_field_titre("BIC");
 		if (! empty($conf->prelevement->enabled))
 		{
-			print print_liste_field_titre("RUM");
-			print print_liste_field_titre("WithdrawMode");
+			print_liste_field_titre("RUM");
+			print_liste_field_titre("WithdrawMode");
 		}
 		print_liste_field_titre("DefaultRIB", '', '', '', '', '', '', '', 'center ');
 		print_liste_field_titre('', '', '', '', '', '', '', '', 'center ');

+ 16 - 2
htdocs/societe/societecontact.php

@@ -37,6 +37,18 @@ $langs->loadLangs(array("orders", "companies"));
 $id=GETPOST('id', 'int')?GETPOST('id', 'int'):GETPOST('socid', 'int');
 $ref=GETPOST('ref', 'alpha');
 $action=GETPOST('action', 'alpha');
+$massaction=GETPOST('massaction', 'alpha');
+
+$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit;
+$sortfield=GETPOST("sortfield", 'alpha');
+$sortorder=GETPOST("sortorder", 'alpha');
+$page=GETPOST("page", 'int');
+if (! $sortorder) $sortorder="ASC";
+if (! $sortfield) $sortfield="s.nom";
+if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) { $page = 0; }
+$offset = $limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
 
 // Security check
 if ($user->societe_id) $socid=$user->societe_id;
@@ -233,12 +245,14 @@ if ($id > 0 || ! empty($ref))
 			{
 				$num = $db->num_rows($resql);
 
-				if ($num  > 0 )
+				if ($num  > 0)
 				{
+					$param = '';
+
 					$titre=$langs->trans("MembersListOfTiers");
 					print '<br>';
 
-					print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
+					print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, 0, '');
 
 					print "<table class=\"noborder\" width=\"100%\">";
 					print '<tr class="liste_titre">';

+ 15 - 4
htdocs/societe/website.php

@@ -230,9 +230,9 @@ dol_fiche_end();
 $newcardbutton = '';
 if (! empty($conf->website->enabled)) {
 	if (! empty($user->rights->societe->lire)) {
-        $morehtmlright.= dolGetButtonTitle($langs->trans("AddWebsiteAccount"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/website/websiteaccount_card.php?action=create&fk_soc='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id));
+		$newcardbutton.= dolGetButtonTitle($langs->trans("AddWebsiteAccount"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/website/websiteaccount_card.php?action=create&fk_soc='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id));
     } else {
-        $morehtmlright.= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/website/websiteaccount_card.php?action=create&fk_soc='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', 0);
+    	$newcardbutton.= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/website/websiteaccount_card.php?action=create&fk_soc='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', 0);
 	}
 }
 
@@ -248,14 +248,15 @@ foreach($objectwebsiteaccount->fields as $key => $val)
 	$sql.='t.'.$key.', ';
 }
 // Add fields from extrafields
-foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
+if (! empty($extrafields->attributes[$object->table_element]['label']))
+	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
 // Add fields from hooks
 $parameters=array();
 $reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters, $objectwebsiteaccount);    // Note that $action and $object may have been modified by hook
 $sql.=$hookmanager->resPrint;
 $sql=preg_replace('/, $/', '', $sql);
 $sql.= " FROM ".MAIN_DB_PREFIX."societe_account as t";
-if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_account_extrafields as ef on (t.rowid = ef.fk_object)";
+if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
 if ($objectwebsiteaccount->ismultientitymanaged == 1) $sql.= " WHERE t.entity IN (".getEntity('societeaccount').")";
 else $sql.=" WHERE 1 = 1";
 $sql.=" AND fk_soc = ".$object->id;
@@ -428,6 +429,16 @@ foreach ($extrafields->attribute_computed as $key => $val)
 }
 
 
+// Detect if we need a fetch on each output line
+$needToFetchEachLine=0;
+if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0)
+{
+	foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
+	{
+		if (preg_match('/\$object/', $val)) $needToFetchEachLine++;  // There is at least one compute field that use $object
+	}
+}
+
 // Loop on record
 // --------------------------------------------------------------------
 $i=0;

+ 85 - 1
phpstan.neon

@@ -4,6 +4,7 @@ parameters:
 		- %currentWorkingDirectory%/htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php
 		- %currentWorkingDirectory%/htdocs/includes/*
 		- %currentWorkingDirectory%/htdocs/*/class/api_*
+		- %currentWorkingDirectory%/htdocs/*/canvas/*/tpl/*.tpl.php
 	autoload_directories:
 		- %currentWorkingDirectory%/htdocs/accountancy/class
 		- %currentWorkingDirectory%/htdocs/adherents/class
@@ -23,14 +24,94 @@ parameters:
 		- %currentWorkingDirectory%/htdocs/compta/facture/class
 		- %currentWorkingDirectory%/htdocs/compta/localtax/class
 		- %currentWorkingDirectory%/htdocs/compta/paiement/class
+		- %currentWorkingDirectory%/htdocs/compta/prelevement/class
+		- %currentWorkingDirectory%/htdocs/compta/salaries/class
+		- %currentWorkingDirectory%/htdocs/compta/sociales/class
+		- %currentWorkingDirectory%/htdocs/compta/tva/class
 		- %currentWorkingDirectory%/htdocs/conf
 		- %currentWorkingDirectory%/htdocs/contact/class
 		- %currentWorkingDirectory%/htdocs/contrat/class
 		- %currentWorkingDirectory%/htdocs/core/class
+		- %currentWorkingDirectory%/htdocs/core/lib
+		- %currentWorkingDirectory%/htdocs/core/triggers
+		- %currentWorkingDirectory%/htdocs/core/modules/bank
+		- %currentWorkingDirectory%/htdocs/core/modules/bom
+		- %currentWorkingDirectory%/htdocs/core/modules/commande
+		- %currentWorkingDirectory%/htdocs/core/modules/expedition
+		#- %currentWorkingDirectory%/htdocs/core/modules/expensereport
+		- %currentWorkingDirectory%/htdocs/core/modules/facture
+		- %currentWorkingDirectory%/htdocs/core/modules/fichinter
+		- %currentWorkingDirectory%/htdocs/core/modules/holiday
+		- %currentWorkingDirectory%/htdocs/core/modules/livraison
+		#- %currentWorkingDirectory%/htdocs/core/modules/member
+		- %currentWorkingDirectory%/htdocs/core/modules/payment
+		- %currentWorkingDirectory%/htdocs/core/modules/product
+		- %currentWorkingDirectory%/htdocs/core/modules/propale
+		- %currentWorkingDirectory%/htdocs/core/modules/reception
+		#- %currentWorkingDirectory%/htdocs/core/modules/stock
+		- %currentWorkingDirectory%/htdocs/core/modules/supplier_invoice
+		- %currentWorkingDirectory%/htdocs/core/modules/supplier_order
+		#- %currentWorkingDirectory%/htdocs/core/modules/supplier_payment
+		- %currentWorkingDirectory%/htdocs/core/modules/supplier_proposal
+		- %currentWorkingDirectory%/htdocs/cron/class
+		- %currentWorkingDirectory%/htdocs/datapolicy/class
+		- %currentWorkingDirectory%/htdocs/debugbar/class
+		- %currentWorkingDirectory%/htdocs/don/class
+		- %currentWorkingDirectory%/htdocs/ecm/class
+		- %currentWorkingDirectory%/htdocs/emailcollector/class
+		- %currentWorkingDirectory%/htdocs/expedition/class
+		- %currentWorkingDirectory%/htdocs/expensereport/class
+		- %currentWorkingDirectory%/htdocs/exports/class
+		- %currentWorkingDirectory%/htdocs/fichinter/class
+		- %currentWorkingDirectory%/htdocs/fourn/class
+		- %currentWorkingDirectory%/htdocs/holiday/class
+		- %currentWorkingDirectory%/htdocs/hrm/class
+		- %currentWorkingDirectory%/htdocs/imports/class
+		- %currentWorkingDirectory%/htdocs/livraison/class
+		- %currentWorkingDirectory%/htdocs/loan/class
+		- %currentWorkingDirectory%/htdocs/mailmanspip/class
+		- %currentWorkingDirectory%/htdocs/multicurrency/class
+		- %currentWorkingDirectory%/htdocs/opensurvey/class
 		- %currentWorkingDirectory%/htdocs/product/class
+		- %currentWorkingDirectory%/htdocs/projet/class
+		- %currentWorkingDirectory%/htdocs/reception/class
+		- %currentWorkingDirectory%/htdocs/resource/class
 		- %currentWorkingDirectory%/htdocs/societe/class
+		- %currentWorkingDirectory%/htdocs/stripe/class
+		- %currentWorkingDirectory%/htdocs/supplier_proposal/class
+		- %currentWorkingDirectory%/htdocs/ticket/class
 		- %currentWorkingDirectory%/htdocs/user/class
-	autoload_files: []
+		- %currentWorkingDirectory%/htdocs/variants/class
+		- %currentWorkingDirectory%/htdocs/website/class
+	autoload_files: 
+		- %currentWorkingDirectory%/build/phpstan/bootstrap.php
+		- %currentWorkingDirectory%/htdocs/core/lib/accounting.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/admin.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/agenda.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/ajax.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/asset.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/bank.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/barcode.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/categories.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/company.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/contact.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/contract.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/cron.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/date.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/doc.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/doleditor.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/donation.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/ecm.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/emailing.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/expedition.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/expensereport.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/fichinter.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/files.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/fiscalyear.lib.php
+		#- %currentWorkingDirectory%/htdocs/core/lib/format_cards.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/fourn.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/functions.lib.php
+		- %currentWorkingDirectory%/htdocs/core/lib/functions2.lib.php
 	featureToggles:
 		subtractableTypes: false
 		validateParameters: false
@@ -66,6 +147,9 @@ parameters:
 		- '#Undefined variable: \$db#'
 		- '#Undefined variable: \$conf#'
 		- '#Undefined variable: \$hookmanager#'
+		- '#Undefined variable: \$mysoc#'
+		- '#Undefined variable: \$error#'
+		- '#Undefined variable: \$errors#'
 	internalErrorsCountLimit: 50
 	cache:
 	    nodesByFileCountMax: 512