Passed
Push — master ( 65bdac...4e88da )
by Alxarafe
32:38
created

User::getNomUrl()   F

Complexity

Conditions 50
Paths > 20000

Size

Total Lines 159
Code Lines 106

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 50
eloc 106
nc 54212608
nop 9
dl 0
loc 159
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/* Copyright (C) 2018       Alxarafe            <[email protected]>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
 */
17
namespace Alixar\Base;
18
19
use Alxarafe\Helpers\Config;
20
use Alixar\Base\CommonObject;
21
use Alixar\Helpers\Globals;
22
23
class User extends CommonObject
24
{
25
26
    /**
27
     * @var string ID to identify managed object
28
     */
29
    public $element = 'user';
30
31
    /**
32
     * @var string Name of table without prefix where object is stored
33
     */
34
    public $table_element = 'user';
35
36
    /**
37
     * @var int Field with ID of parent key if this field has a parent
38
     */
39
    public $fk_element = 'fk_user';
40
41
    /**
42
     * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
43
     * @var int
44
     */
45
    public $ismultientitymanaged = 1;
46
    public $id = 0;
47
    public $statut;
48
    public $ldap_sid;
49
    public $search_sid;
50
    public $employee;
51
    public $gender;
52
    public $birth;
53
    public $email;
54
    public $skype;
55
    public $twitter;
56
    public $facebook;
57
    public $job;   // job position
58
    public $signature;
59
60
    /**
61
     * @var string Address
62
     */
63
    public $address;
64
    public $zip;
65
    public $town;
66
    public $state_id;  // The state/department
67
    public $state_code;
68
    public $state;
69
    public $office_phone;
70
    public $office_fax;
71
    public $user_mobile;
72
    public $admin;
73
    public $login;
74
    public $api_key;
75
76
    /**
77
     * @var int Entity
78
     */
79
    public $entity;
80
    //! Clear password in memory
81
    public $pass;
82
    //! Clear password in database (defined if DATABASE_PWD_ENCRYPTED=0)
83
    public $pass_indatabase;
84
    //! Encrypted password in database (always defined)
85
    public $pass_indatabase_crypted;
86
    public $datec;
87
    public $datem;
88
    //! If this is defined, it is an external user
89
    /**
90
     * @deprecated
91
     * @see socid
92
     */
93
    public $societe_id;
94
95
    /**
96
     * @deprecated
97
     * @see contactid
98
     */
99
    public $contact_id;
100
    public $socid;
101
    public $contactid;
102
103
    /**
104
     * @var int ID
105
     */
106
    public $fk_member;
107
108
    /**
109
     * @var int User ID
110
     */
111
    public $fk_user;
112
    public $clicktodial_url;
113
    public $clicktodial_login;
114
    public $clicktodial_password;
115
    public $clicktodial_poste;
116
    public $datelastlogin;
117
    public $datepreviouslogin;
118
    public $photo;
119
    public $lang;
120
    public $rights;                        // Array of permissions user->rights->permx
121
    public $all_permissions_are_loaded;    // All permission are loaded
122
    public $nb_rights;              // Number of rights granted to the user
123
    private $_tab_loaded = array();     // Cache array of already loaded permissions
124
    public $conf;             // To store personal config
125
    public $default_values;         // To store default values for user
126
    public $lastsearch_values_tmp;  // To store current search criterias for user
127
    public $lastsearch_values;      // To store last saved search criterias for user
128
    public $users = array();  // To store all tree of users hierarchy
129
    public $parentof;    // To store an array of all parents for all ids.
130
    private $cache_childids;
131
    public $accountancy_code;   // Accountancy code in prevision of the complete accountancy module
132
    public $thm;     // Average cost of employee - Used for valuation of time spent
133
    public $tjm;     // Average cost of employee
134
    public $salary;     // Monthly salary       - Denormalized value from llx_user_employment
135
    public $salaryextra;    // Monthly salary extra - Denormalized value from llx_user_employment
136
    public $weeklyhours;    // Weekly hours         - Denormalized value from llx_user_employment
137
    public $color;      // Define background color for user in agenda
138
    public $dateemployment;   // Define date of employment by company
139
    public $dateemploymentend;  // Define date of employment end by company
140
    public $default_c_exp_tax_cat;
141
    public $default_range;
142
    public $fields = array(
143
        'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
144
        'lastname' => array('type' => 'varchar(50)', 'label' => 'Name', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 20, 'searchall' => 1, 'comment' => 'Reference of object'),
145
        'firstname' => array('type' => 'varchar(50)', 'label' => 'Name', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 10, 'searchall' => 1, 'comment' => 'Reference of object'),
146
    );
147
148
    /**
149
     *    Constructor of the class
150
     *
151
     *    @param   DoliDb  $db     Database handler
0 ignored issues
show
Bug introduced by alxarafe
The type Alixar\Base\DoliDb was not found. Did you mean DoliDb? If so, make sure to prefix the type with \.
Loading history...
152
     */
153
    function __construct()
154
    {
155
        // User preference
156
        $this->liste_limit = 0;
157
        $this->clicktodial_loaded = 0;
158
159
        // For cache usage
160
        $this->all_permissions_are_loaded = 0;
161
        $this->nb_rights = 0;
162
163
        // Force some default values
164
        $this->admin = 0;
165
        $this->employee = 1;
166
167
        $this->conf = new \stdClass();
168
        $this->rights = new \stdClass();
169
        $this->rights->user = new \stdClass();
170
        $this->rights->user->user = new \stdClass();
171
        $this->rights->user->self = new \stdClass();
172
    }
173
174
    /**
175
     * 	Load a user from database with its id or ref (login).
176
     *  This function does not load permissions, only user properties. Use getrights() for this just after the fetch.
177
     *
178
     * 	@param	int		$id		       		If defined, id to used for search
179
     * 	@param  string	$login       		If defined, login to used for search
180
     * 	@param  string	$sid				If defined, sid to used for search
181
     * 	@param	int		$loadpersonalconf	1=also load personal conf of user (in $user->conf->xxx), 0=do not load personal conf.
182
     *  @param  int     $entity             If a value is >= 0, we force the search on a specific entity. If -1, means search depens on default setup.
183
     * 	@return	int							<0 if KO, 0 not found, >0 if OK
184
     */
185
    function fetch($id = '', $login = '', $sid = '', $loadpersonalconf = 0, $entity = -1)
186
    {
187
        // global $conf, $user;
188
        // Clean parameters
189
        $login = trim($login);
190
191
        // Get user
192
        $sql = "SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.birth, u.email, u.job, u.skype, u.twitter, u.facebook,";
193
        $sql .= " u.signature, u.office_phone, u.office_fax, u.user_mobile,";
194
        $sql .= " u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
195
        $sql .= " u.admin, u.login, u.note,";
196
        $sql .= " u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
197
        $sql .= " u.fk_soc, u.fk_socpeople, u.fk_member, u.fk_user, u.ldap_sid,";
198
        $sql .= " u.statut, u.lang, u.entity,";
199
        $sql .= " u.datec as datec,";
200
        $sql .= " u.tms as datem,";
201
        $sql .= " u.datelastlogin as datel,";
202
        $sql .= " u.datepreviouslogin as datep,";
203
        $sql .= " u.photo as photo,";
204
        $sql .= " u.openid as openid,";
205
        $sql .= " u.accountancy_code,";
206
        $sql .= " u.thm,";
207
        $sql .= " u.tjm,";
208
        $sql .= " u.salary,";
209
        $sql .= " u.salaryextra,";
210
        $sql .= " u.weeklyhours,";
211
        $sql .= " u.color,";
212
        $sql .= " u.dateemployment, u.dateemploymentend,";
213
        $sql .= " u.ref_int, u.ref_ext,";
214
        $sql .= " u.default_range, u.default_c_exp_tax_cat,";   // Expense report default mode
215
        $sql .= " c.code as country_code, c.label as country,";
216
        $sql .= " d.code_departement as state_code, d.nom as state";
217
        $sql .= " FROM " . MAIN_DB_PREFIX . "user as u";
218
        $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as c ON u.fk_country = c.rowid";
219
        $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_departements as d ON u.fk_state = d.rowid";
220
221
        if ($entity < 0) {
222
            if ((empty($conf->multicompany->enabled) || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (!empty($user->entity))) {
0 ignored issues
show
Comprehensibility Best Practice introduced by alxarafe
The variable $user seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by alxarafe
The variable $conf seems to be never defined.
Loading history...
223
                $sql .= " WHERE u.entity IN (0," . Globals::$conf->entity . ")";
224
            } else {
225
                $sql .= " WHERE u.entity IS NOT NULL";    // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database
226
            }
227
        } else {  // The fetch was forced on an entity
228
            if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
229
                $sql .= " WHERE u.entity IS NOT NULL";    // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database
230
            } else {
231
                $sql .= " WHERE u.entity IN (0, " . (($entity != '' && $entity >= 0) ? $entity : Globals::$conf->entity) . ")";   // search in entity provided in parameter
232
            }
233
        }
234
235
        if ($sid) {    // permet une recherche du user par son SID ActiveDirectory ou Samba
236
            //$sql .= " AND (u.ldap_sid = '" . Config::$dbEngine->escape($sid) . "' OR u.login = '" . Config::$dbEngine->escape($login) . "') LIMIT 1";
237
            $sql .= " AND (u.ldap_sid = '" . $sid . "' OR u.login = '" . Config::$dbEngine->escape($login) . "') LIMIT 1";
0 ignored issues
show
Bug introduced by alxarafe
The method escape() does not exist on Alxarafe\Database\Engine. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

237
            $sql .= " AND (u.ldap_sid = '" . $sid . "' OR u.login = '" . Config::$dbEngine->/** @scrutinizer ignore-call */ escape($login) . "') LIMIT 1";

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
238
        } else if ($login) {
239
            // $sql .= " AND u.login = '" . Config::$dbEngine->escape($login) . "'";
240
            $sql .= " AND u.login = '" . $login . "'";
241
        } else {
242
            $sql .= " AND u.rowid = " . $id;
243
        }
244
        $sql .= " ORDER BY u.entity ASC";    // Avoid random result when there is 2 login in 2 different entities
245
246
        $result = Config::$dbEngine->select($sql);
247
        // echo "<p>SQL in 2477 of User: '$sql'</p>";
248
        if ($result) {
249
            if (count($result) > 0) {
250
251
                // Convert array to stdclass
252
                $obj = json_decode(json_encode($result[0]));
253
254
                $this->id = $obj->rowid;
255
                $this->ref = $obj->rowid;
256
257
                $this->ref_int = $obj->ref_int;
258
                $this->ref_ext = $obj->ref_ext;
259
260
                $this->ldap_sid = $obj->ldap_sid;
261
                $this->lastname = $obj->lastname;
262
                $this->firstname = $obj->firstname;
263
264
                $this->employee = $obj->employee;
265
266
                $this->login = $obj->login;
267
                $this->gender = $obj->gender;
268
                // $this->birth = Config::$dbEngine->jdate($obj->birth);
269
                $this->birth = $obj->birth;
270
271
                $this->pass_indatabase = $obj->pass;
272
                $this->pass_indatabase_crypted = $obj->pass_crypted;
273
                $this->pass = $obj->pass;
274
                $this->pass_temp = $obj->pass_temp;
275
                $this->api_key = $obj->api_key;
276
277
                $this->address = $obj->address;
278
                $this->zip = $obj->zip;
279
                $this->town = $obj->town;
280
281
                $this->country_id = $obj->country_id;
282
                $this->country_code = $obj->country_id ? $obj->country_code : '';
283
                //$this->country 		= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
284
285
                $this->state_id = $obj->state_id;
286
                $this->state_code = $obj->state_code;
287
                $this->state = ($obj->state != '-' ? $obj->state : '');
288
289
                $this->office_phone = $obj->office_phone;
290
                $this->office_fax = $obj->office_fax;
291
                $this->user_mobile = $obj->user_mobile;
292
                $this->email = $obj->email;
293
                $this->skype = $obj->skype;
294
                $this->twitter = $obj->twitter;
295
                $this->facebook = $obj->facebook;
296
                $this->job = $obj->job;
297
                $this->signature = $obj->signature;
298
                $this->admin = $obj->admin;
299
                $this->note = $obj->note;
300
                $this->statut = $obj->statut;
301
                $this->photo = $obj->photo;
302
                $this->openid = $obj->openid;
303
                $this->lang = $obj->lang;
304
                $this->entity = $obj->entity;
305
                $this->accountancy_code = $obj->accountancy_code;
306
                $this->thm = $obj->thm;
307
                $this->tjm = $obj->tjm;
308
                $this->salary = $obj->salary;
309
                $this->salaryextra = $obj->salaryextra;
310
                $this->weeklyhours = $obj->weeklyhours;
311
                $this->color = $obj->color;
312
313
                /*
314
                  $this->dateemployment = Config::$dbEngine->jdate($obj->dateemployment);
315
                  $this->dateemploymentend = Config::$dbEngine->jdate($obj->dateemploymentend);
316
317
                  $this->datec = Config::$dbEngine->jdate($obj->datec);
318
                  $this->datem = Config::$dbEngine->jdate($obj->datem);
319
                  $this->datelastlogin = Config::$dbEngine->jdate($obj->datel);
320
                  $this->datepreviouslogin = Config::$dbEngine->jdate($obj->datep);
321
                 */
322
                $this->dateemployment = $obj->dateemployment;
323
                $this->dateemploymentend = $obj->dateemploymentend;
324
325
                $this->datec = $obj->datec;
326
                $this->datem = $obj->datem;
327
                $this->datelastlogin = $obj->datel;
328
                $this->datepreviouslogin = $obj->datep;
329
330
                $this->societe_id = $obj->fk_soc;  // deprecated
331
                $this->contact_id = $obj->fk_socpeople; // deprecated
332
                $this->socid = $obj->fk_soc;
333
                $this->contactid = $obj->fk_socpeople;
334
                $this->fk_member = $obj->fk_member;
335
                $this->fk_user = $obj->fk_user;
336
337
                $this->default_range = $obj->default_range;
338
                $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
339
340
                // Protection when module multicompany was set, admin was set to first entity and then, the module was disabled,
341
                // in such case, this admin user must be admin for ALL entities.
342
                if (empty($conf->multicompany->enabled) && $this->admin && $this->entity == 1) {
343
                    $this->entity = 0;
344
                }
345
346
                // Retreive all extrafield
347
                // fetch optionals attributes and labels
348
                $this->fetch_optionals();
349
            } else {
350
                $this->error = "USERNOTFOUND";
351
                DolUtils::dol_syslog(get_class($this) . "::fetch user not found", LOG_DEBUG);
352
                return 0;
353
            }
354
        } else {
355
            $this->error = Config::$dbEngine->lasterror();
0 ignored issues
show
Bug introduced by alxarafe
The method lasterror() does not exist on Alxarafe\Database\Engine. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

355
            /** @scrutinizer ignore-call */ $this->error = Config::$dbEngine->lasterror();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
356
            return -1;
357
        }
358
359
        // To get back the global configuration unique to the user
360
        if ($loadpersonalconf) {
361
            // Load user->conf for user
362
            $sql = "SELECT param, value FROM " . MAIN_DB_PREFIX . "user_param";
363
            $sql .= " WHERE fk_user = " . $this->id;
364
            $sql .= " AND entity = " . Globals::$conf->entity;
365
            //DolUtils::dol_syslog(get_class($this).'::fetch load personalized conf', LOG_DEBUG);
366
            $resql = Config::$dbEngine->select($sql);
367
            if (is_array($resql)) {
368
                foreach ($resql as $array) {
369
                    $obj = json_decode(json_encode($array));
370
371
                    $p = (!empty($obj->param) ? $obj->param : '');
372
                    if (!empty($p)) {
373
                        $this->conf->$p = $obj->value;
374
                    }
375
                }
376
            } else {
377
                // $this->error = Config::$dbEngine->lasterror();
378
                return -2;
379
            }
380
381
            $result = $this->loadDefaultValues();
382
383
            if ($result < 0) {
384
                // $this->error = Config::$dbEngine->lasterror();
385
                return -3;
386
            }
387
        }
388
389
        return 1;
390
    }
391
392
    /**
393
     *  Load default value in property ->default_values
394
     *
395
     *  @return int						> 0 if OK, < 0 if KO
396
     */
397
    function loadDefaultValues()
398
    {
399
        // global $conf;
400
        // Load user->default_values for user. TODO Save this in memcached ?
401
        $sql = "SELECT rowid, entity, type, page, param, value";
402
        $sql .= " FROM " . MAIN_DB_PREFIX . "default_values";
403
        $sql .= " WHERE entity IN (" . ($this->entity > 0 ? $this->entity . ", " : "") . Globals::$conf->entity . ")"; // Entity of user (if defined) + current entity
404
        $sql .= " AND user_id IN (0" . ($this->id > 0 ? ", " . $this->id : "") . ")";       // User 0 (all) + me (if defined)
405
        $resql = Config::$dbEngine->select($sql);
406
        if (is_array($resql)) {
407
            foreach ($resql as $array) {
408
                $obj = json_decode(json_encode($array));
409
410
                $pagewithoutquerystring = $obj->page;
411
                $pagequeries = '';
412
                if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) { // There is query param
413
                    $pagewithoutquerystring = $reg[1];
414
                    $pagequeries = $reg[2];
415
                }
416
                $this->default_values[$pagewithoutquerystring][$obj->type][$pagequeries ? $pagequeries : '_noquery_'][$obj->param] = $obj->value;
417
                //if ($pagequeries) $this->default_values[$pagewithoutquerystring][$obj->type.'_queries']=$pagequeries;
418
            }
419
            // Sort by key, so _noquery_ is last
420
            if (!empty($this->default_values)) {
421
                foreach ($this->default_values as $a => $b) {
422
                    foreach ($b as $c => $d) {
423
                        krsort($this->default_values[$a][$c]);
424
                    }
425
                }
426
            }
427
            // Config::$dbEngine->free($resql);
428
429
            return 1;
430
        }
431
        DolUtils::dol_print_error(Config::$dbEngine);
432
            return -1;
433
434
    }
435
436
    /**
437
     *  Add a right to the user
438
     *
439
     * 	@param	int		$rid			Id of permission to add or 0 to add several permissions
440
     *  @param  string	$allmodule		Add all permissions of module $allmodule
441
     *  @param  string	$allperms		Add all permissions of module $allmodule, subperms $allperms only
442
     *  @param	int		$entity			Entity to use
443
     *  @param  int	    $notrigger		1=Does not execute triggers, 0=Execute triggers
444
     *  @return int						> 0 if OK, < 0 if KO
445
     *  @see	clearrights, delrights, getrights
446
     */
447
    function addrights($rid, $allmodule = '', $allperms = '', $entity = 0, $notrigger = 0)
448
    {
449
        global $conf, $user, $langs;
450
451
        $entity = (!empty($entity) ? $entity : Globals::$conf->entity);
452
453
        DolUtils::dol_syslog(get_class($this) . "::addrights $rid, $allmodule, $allperms, $entity");
454
        $error = 0;
455
        $whereforadd = '';
456
457
        Config::$dbEngine->begin();
0 ignored issues
show
Bug introduced by alxarafe
The method begin() does not exist on Alxarafe\Database\Engine. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

457
        Config::$dbEngine->/** @scrutinizer ignore-call */ 
458
                           begin();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
458
459
        if (!empty($rid)) {
460
            // Si on a demande ajout d'un droit en particulier, on recupere
461
            // les caracteristiques (module, perms et subperms) de ce droit.
462
            $sql = "SELECT module, perms, subperms";
463
            $sql .= " FROM " . MAIN_DB_PREFIX . "rights_def";
464
            $sql .= " WHERE id = '" . Config::$dbEngine->escape($rid) . "'";
465
            $sql .= " AND entity = " . $entity;
466
467
            $result = Config::$dbEngine->query($sql);
0 ignored issues
show
Bug introduced by alxarafe
The method query() does not exist on Alxarafe\Database\Engine. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

467
            /** @scrutinizer ignore-call */ $result = Config::$dbEngine->query($sql);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
468
            if ($result) {
469
                $obj = Config::$dbEngine->fetch_object($result);
0 ignored issues
show
Bug introduced by alxarafe
The method fetch_object() does not exist on Alxarafe\Database\Engine. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

469
                /** @scrutinizer ignore-call */ $obj = Config::$dbEngine->fetch_object($result);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
470
                $module = $obj->module;
471
                $perms = $obj->perms;
472
                $subperms = $obj->subperms;
473
            } else {
474
                $error++;
475
                dol_print_error(Config::$dbEngine);
476
            }
477
478
            // Where pour la liste des droits a ajouter
479
            $whereforadd = "id=" . Config::$dbEngine->escape($rid);
480
            // Ajout des droits induits
481
            if (!empty($subperms)) {
482
                $whereforadd .= " OR (module='$module' AND perms='$perms' AND (subperms='lire' OR subperms='read'))";
483
            } else {
484
                if (!empty($perms)) {
485
                    $whereforadd .= " OR (module='$module' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
486
                }
487
            }
488
        } else {
489
            // On a pas demande un droit en particulier mais une liste de droits
490
            // sur la base d'un nom de module de de perms
491
            // Where pour la liste des droits a ajouter
492
            if (!empty($allmodule)) {
493
                if ($allmodule == 'allmodules') {
494
                    $whereforadd = 'allmodules';
495
                } else {
496
                    $whereforadd = "module='" . Config::$dbEngine->escape($allmodule) . "'";
497
                    if (!empty($allperms)) {
498
                        $whereforadd .= " AND perms='" . Config::$dbEngine->escape($allperms) . "'";
499
                    }
500
                }
501
            }
502
        }
503
504
        // Ajout des droits trouves grace au critere whereforadd
505
        if (!empty($whereforadd)) {
506
            //print "$module-$perms-$subperms";
507
            $sql = "SELECT id";
508
            $sql .= " FROM " . MAIN_DB_PREFIX . "rights_def";
509
            $sql .= " WHERE entity = " . $entity;
510
            if (!empty($whereforadd) && $whereforadd != 'allmodules') {
511
                $sql .= " AND " . $whereforadd;
512
            }
513
514
            $result = Config::$dbEngine->query($sql);
515
            if ($result) {
516
                $num = Config::$dbEngine->num_rows($result);
0 ignored issues
show
Bug introduced by alxarafe
The method num_rows() does not exist on Alxarafe\Database\Engine. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

516
                /** @scrutinizer ignore-call */ $num = Config::$dbEngine->num_rows($result);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
517
                $i = 0;
518
                while ($i < $num) {
519
                    $obj = Config::$dbEngine->fetch_object($result);
520
                    $nid = $obj->id;
521
522
                    $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user_rights WHERE fk_user = " . $this->id . " AND fk_id=" . $nid . " AND entity = " . $entity;
523
                    if (!Config::$dbEngine->query($sql))
524
                        $error++;
525
                    $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user_rights (entity, fk_user, fk_id) VALUES (" . $entity . ", " . $this->id . ", " . $nid . ")";
526
                    if (!Config::$dbEngine->query($sql))
527
                        $error++;
528
529
                    $i++;
530
                }
531
            }
532
            else {
533
                $error++;
534
                dol_print_error(Config::$dbEngine);
535
            }
536
        }
537
538
        if (!$error && !$notrigger) {
539
            $langs->load("other");
540
            $this->context = array('audit' => $langs->trans("PermissionsAdd") . ($rid ? ' (id=' . $rid . ')' : ''));
541
542
            // Call trigger
543
            $result = $this->call_trigger('USER_MODIFY', $user);
544
            if ($result < 0) {
545
                $error++;
546
            }
547
            // End call triggers
548
        }
549
550
        if ($error) {
551
            Config::$dbEngine->rollback();
552
            return -$error;
553
        } else {
554
            Config::$dbEngine->commit();
555
            return 1;
556
        }
557
    }
558
559
    /**
560
     *  Remove a right to the user
561
     *
562
     *  @param	int		$rid        Id du droit a retirer
563
     *  @param  string	$allmodule  Retirer tous les droits du module allmodule
564
     *  @param  string	$allperms   Retirer tous les droits du module allmodule, perms allperms
565
     *  @param	int		$entity		Entity to use
566
     *  @param  int	    $notrigger	1=Does not execute triggers, 0=Execute triggers
567
     *  @return int         		> 0 if OK, < 0 if OK
568
     *  @see	clearrights, addrights, getrights
569
     */
570
    function delrights($rid, $allmodule = '', $allperms = '', $entity = 0, $notrigger = 0)
571
    {
572
        global $conf, $user, $langs;
573
574
        $error = 0;
575
        $wherefordel = '';
576
        $entity = (!empty($entity) ? $entity : Globals::$conf->entity);
577
578
        Config::$dbEngine->begin();
579
580
        if (!empty($rid)) {
581
            // Si on a demande supression d'un droit en particulier, on recupere
582
            // les caracteristiques module, perms et subperms de ce droit.
583
            $sql = "SELECT module, perms, subperms";
584
            $sql .= " FROM " . MAIN_DB_PREFIX . "rights_def";
585
            $sql .= " WHERE id = '" . Config::$dbEngine->escape($rid) . "'";
586
            $sql .= " AND entity = " . $entity;
587
588
            $result = Config::$dbEngine->query($sql);
589
            if ($result) {
590
                $obj = Config::$dbEngine->fetch_object($result);
591
                $module = $obj->module;
592
                $perms = $obj->perms;
593
                $subperms = $obj->subperms;
594
            } else {
595
                $error++;
596
                dol_print_error(Config::$dbEngine);
597
            }
598
599
            // Where pour la liste des droits a supprimer
600
            $wherefordel = "id=" . Config::$dbEngine->escape($rid);
601
            // Suppression des droits induits
602
            if ($subperms == 'lire' || $subperms == 'read') {
603
                $wherefordel .= " OR (module='$module' AND perms='$perms' AND subperms IS NOT NULL)";
604
            }
605
            if ($perms == 'lire' || $perms == 'read') {
606
                $wherefordel .= " OR (module='$module')";
607
            }
608
        } else {
609
            // On a demande suppression d'un droit sur la base d'un nom de module ou perms
610
            // Where pour la liste des droits a supprimer
611
            if (!empty($allmodule)) {
612
                if ($allmodule == 'allmodules') {
613
                    $wherefordel = 'allmodules';
614
                } else {
615
                    $wherefordel = "module='" . Config::$dbEngine->escape($allmodule) . "'";
616
                    if (!empty($allperms)) {
617
                        $whereforadd .= " AND perms='" . Config::$dbEngine->escape($allperms) . "'";
0 ignored issues
show
Comprehensibility Best Practice introduced by alxarafe
The variable $whereforadd does not exist. Did you maybe mean $wherefordel?
Loading history...
618
                    }
619
                }
620
            }
621
        }
622
623
        // Suppression des droits selon critere defini dans wherefordel
624
        if (!empty($wherefordel)) {
625
            //print "$module-$perms-$subperms";
626
            $sql = "SELECT id";
627
            $sql .= " FROM " . MAIN_DB_PREFIX . "rights_def";
628
            $sql .= " WHERE entity = " . $entity;
629
            if (!empty($wherefordel) && $wherefordel != 'allmodules') {
630
                $sql .= " AND " . $wherefordel;
631
            }
632
633
            $result = Config::$dbEngine->query($sql);
634
            if ($result) {
635
                $num = Config::$dbEngine->num_rows($result);
636
                $i = 0;
637
                while ($i < $num) {
638
                    $obj = Config::$dbEngine->fetch_object($result);
639
                    $nid = $obj->id;
640
641
                    $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user_rights";
642
                    $sql .= " WHERE fk_user = " . $this->id . " AND fk_id=" . $nid;
643
                    $sql .= " AND entity = " . $entity;
644
                    if (!Config::$dbEngine->query($sql)) {
645
                        $error++;
646
                    }
647
648
                    $i++;
649
                }
650
            } else {
651
                $error++;
652
                dol_print_error(Config::$dbEngine);
653
            }
654
        }
655
656
        if (!$error && !$notrigger) {
657
            $langs->load("other");
658
            $this->context = array('audit' => $langs->trans("PermissionsDelete") . ($rid ? ' (id=' . $rid . ')' : ''));
659
660
            // Call trigger
661
            $result = $this->call_trigger('USER_MODIFY', $user);
662
            if ($result < 0) {
663
                $error++;
664
            }
665
            // End call triggers
666
        }
667
668
        if ($error) {
669
            Config::$dbEngine->rollback();
670
            return -$error;
671
        } else {
672
            Config::$dbEngine->commit();
673
            return 1;
674
        }
675
    }
676
677
    /**
678
     *  Clear all permissions array of user
679
     *
680
     *  @return	void
681
     *  @see	getrights
682
     */
683
    function clearrights()
684
    {
685
        DolUtils::dol_syslog(get_class($this) . "::clearrights reset user->rights");
686
        $this->rights = '';
687
        $this->all_permissions_are_loaded = false;
688
        $this->_tab_loaded = array();
689
    }
690
691
    /**
692
     * 	Load permissions granted to user into object user
693
     *
694
     * 	@param  string	$moduletag		Limit permission for a particular module ('' by default means load all permissions)
695
     *  @param	int		$forcereload	Force reload of permissions even if they were already loaded (ignore cache)
696
     * 	@return	void
697
     *  @see	clearrights, delrights, addrights
698
     */
699
    function getrights($moduletag = '', $forcereload = 0)
700
    {
701
        global $conf;
702
703
        if (empty($forcereload)) {
704
            if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
705
                // Rights for this module are already loaded, so we leave
706
                return;
707
            }
708
709
            if ($this->all_permissions_are_loaded) {
710
                // We already loaded all rights for this user, so we leave
711
                return;
712
            }
713
        }
714
715
        // Recuperation des droits utilisateurs + recuperation des droits groupes
716
        // D'abord les droits utilisateurs
717
        $sql = "SELECT DISTINCT r.module, r.perms, r.subperms";
718
        $sql .= " FROM " . MAIN_DB_PREFIX . "user_rights as ur";
719
        $sql .= ", " . MAIN_DB_PREFIX . "rights_def as r";
720
        $sql .= " WHERE r.id = ur.fk_id";
721
        if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
722
            $sql .= " AND r.entity IN (0," . (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ? "1," : "") . Globals::$conf->entity . ")";
723
        } else {
724
            $sql .= " AND ur.entity = " . Globals::$conf->entity;
725
        }
726
        $sql .= " AND ur.fk_user= " . $this->id;
727
        $sql .= " AND r.perms IS NOT NULL";
728
        if ($moduletag) {
729
            // $sql .= " AND r.module = '" . Config::$dbEngine->escape($moduletag) . "'";
730
            $sql .= " AND r.module = '" . $moduletag . "'";
731
        }
732
733
        $resql = Config::$dbEngine->select($sql);
734
        if (is_array($resql)) {
735
            foreach ($resql as $array) {
736
                $obj = json_decode(json_encode($array));
737
738
                $module = $obj->module;
739
                $perms = $obj->perms;
740
                $subperms = $obj->subperms;
741
742
                if ($perms) {
743
                    if (!isset($this->rights) || !is_object($this->rights)) {
744
                        $this->rights = new \stdClass(); // For avoid error
745
                    }
746
                    if ($module) {
747
                        if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
748
                            $this->rights->$module = new \stdClass();
749
                        }
750
                        if ($subperms) {
751
                            if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
752
                                $this->rights->$module->$perms = new \stdClass();
753
                            }
754
                            if (empty($this->rights->$module->$perms->$subperms)) {
755
                                $this->nb_rights++;
756
                            }
757
                            $this->rights->$module->$perms->$subperms = 1;
758
                        } else {
759
                            if (empty($this->rights->$module->$perms)) {
760
                                $this->nb_rights++;
761
                            }
762
                            $this->rights->$module->$perms = 1;
763
                        }
764
                    }
765
                }
766
            }
767
        }
768
769
        // Maintenant les droits groupes
770
        $sql = "SELECT DISTINCT r.module, r.perms, r.subperms";
771
        $sql .= " FROM " . MAIN_DB_PREFIX . "usergroup_rights as gr,";
772
        $sql .= " " . MAIN_DB_PREFIX . "usergroup_user as gu,";
773
        $sql .= " " . MAIN_DB_PREFIX . "rights_def as r";
774
        $sql .= " WHERE r.id = gr.fk_id";
775
        if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
776
            if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
777
                $sql .= " AND gu.entity IN (0," . Globals::$conf->entity . ")";
778
            } else {
779
                $sql .= " AND r.entity = " . Globals::$conf->entity;
780
            }
781
        } else {
782
            $sql .= " AND gr.entity = " . Globals::$conf->entity;
783
            $sql .= " AND r.entity = " . Globals::$conf->entity;
784
        }
785
        $sql .= " AND gr.fk_usergroup = gu.fk_usergroup";
786
        $sql .= " AND gu.fk_user = " . $this->id;
787
        $sql .= " AND r.perms IS NOT NULL";
788
        if ($moduletag) {
789
            $sql .= " AND r.module = '" . $moduletag . "'";
790
        }
791
792
        $resql = Config::$dbEngine->select($sql);
793
        if (is_array($resql)) {
794
            foreach ($resql as $array) {
795
                $obj = json_decode(json_encode($array));
796
797
                $module = $obj->module;
798
                $perms = $obj->perms;
799
                $subperms = $obj->subperms;
800
801
                if ($perms) {
802
                    if (!isset($this->rights) || !is_object($this->rights)) {
803
                        $this->rights = new \stdClass(); // For avoid error
804
                    }
805
                    if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
806
                        $this->rights->$module = new \stdClass();
807
                    }
808
                    if ($subperms) {
809
                        if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
810
                            $this->rights->$module->$perms = new \stdClass();
811
                        }
812
                        if (empty($this->rights->$module->$perms->$subperms)) {
813
                            $this->nb_rights++;
814
                        }
815
                        $this->rights->$module->$perms->$subperms = 1;
816
                    } else {
817
                        if (empty($this->rights->$module->$perms)) {
818
                            $this->nb_rights++;
819
                        }
820
                        // if we have already define a subperm like this $this->rights->$module->level1->level2 with llx_user_rights, we don't want override level1 because the level2 can be not define on user group
821
                        if (!is_object($this->rights->$module->$perms)) {
822
                            $this->rights->$module->$perms = 1;
823
                        }
824
                    }
825
                }
826
            }
827
        }
828
829
        // For backward compatibility
830
        if (isset($this->rights->propale) && !isset($this->rights->propal)) {
831
            $this->rights->propal = $this->rights->propale;
832
        }
833
        if (isset($this->rights->propal) && !isset($this->rights->propale)) {
834
            $this->rights->propale = $this->rights->propal;
835
        }
836
837
        if (!$moduletag) {
838
            // Si module etait non defini, alors on a tout charge, on peut donc considerer
839
            // que les droits sont en cache (car tous charges) pour cet instance de user
840
            $this->all_permissions_are_loaded = 1;
841
        } else {
842
            // Si module defini, on le marque comme charge en cache
843
            $this->_tab_loaded[$moduletag] = 1;
844
        }
845
    }
846
847
    /**
848
     *  Change status of a user
849
     *
850
     * 	@param	int		$statut		Status to set
851
     *  @return int     			<0 if KO, 0 if nothing is done, >0 if OK
852
     */
853
    function setstatus($statut)
854
    {
855
        // global $conf, $langs, $user;
856
857
        $error = 0;
858
859
        // Check parameters
860
        if ($this->statut == $statut) {
861
            return 0;
862
        } else {
863
            $this->statut = $statut;
864
        }
865
866
        Config::$dbEngine->begin();
867
868
        // Deactivate user
869
        $sql = "UPDATE " . MAIN_DB_PREFIX . "user";
870
        $sql .= " SET statut = " . $this->statut;
871
        $sql .= " WHERE rowid = " . $this->id;
872
        $result = Config::$dbEngine->query($sql);
873
874
        DolUtils::dol_syslog(get_class($this) . "::setstatus", LOG_DEBUG);
875
        if ($result) {
876
            // Call trigger
877
            $result = $this->call_trigger('USER_ENABLEDISABLE', $user);
0 ignored issues
show
Comprehensibility Best Practice introduced by alxarafe
The variable $user seems to be never defined.
Loading history...
878
            if ($result < 0) {
879
                $error++;
880
            }
881
            // End call triggers
882
        }
883
884
        if ($error) {
885
            Config::$dbEngine->rollback();
886
            return -$error;
887
        } else {
888
            Config::$dbEngine->commit();
889
            return 1;
890
        }
891
    }
892
893
    /**
894
     * Sets object to supplied categories.
895
     *
896
     * Deletes object from existing categories not supplied.
897
     * Adds it to non existing supplied categories.
898
     * Existing categories are left untouch.
899
     *
900
     * @param int[]|int $categories Category or categories IDs
901
     * @return void
902
     */
903
    public function setCategories($categories)
904
    {
905
        // Handle single category
906
        if (!is_array($categories)) {
907
            $categories = array($categories);
908
        }
909
910
        // Get current categories
911
        require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
912
        $c = new Categorie(Config::$dbEngine);
913
        $existing = $c->containing($this->id, Categorie::TYPE_USER, 'id');
914
915
        // Diff
916
        if (is_array($existing)) {
917
            $to_del = array_diff($existing, $categories);
918
            $to_add = array_diff($categories, $existing);
919
        } else {
920
            $to_del = array(); // Nothing to delete
921
            $to_add = $categories;
922
        }
923
924
        // Process
925
        foreach ($to_del as $del) {
926
            if ($c->fetch($del) > 0) {
927
                $c->del_type($this, 'user');
928
            }
929
        }
930
        foreach ($to_add as $add) {
931
            if ($c->fetch($add) > 0) {
932
                $c->add_type($this, 'user');
933
            }
934
        }
935
936
        return;
937
    }
938
939
    /**
940
     *    	Delete the user
941
     *
942
     * 		@return		int		<0 if KO, >0 if OK
943
     */
944
    function delete()
945
    {
946
        global $user, $conf, $langs;
947
948
        $error = 0;
949
950
        Config::$dbEngine->begin();
951
952
        $this->fetch($this->id);
953
954
        DolUtils::dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
955
956
        // Remove rights
957
        $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user_rights WHERE fk_user = " . $this->id;
958
959
        if (!$error && !Config::$dbEngine->query($sql)) {
960
            $error++;
961
            $this->error = Config::$dbEngine->lasterror();
962
        }
963
964
        // Remove group
965
        $sql = "DELETE FROM " . MAIN_DB_PREFIX . "usergroup_user WHERE fk_user  = " . $this->id;
966
        if (!$error && !Config::$dbEngine->query($sql)) {
967
            $error++;
968
            $this->error = Config::$dbEngine->lasterror();
969
        }
970
971
        // If contact, remove link
972
        if ($this->contact_id) {
973
            $sql = "UPDATE " . MAIN_DB_PREFIX . "socpeople SET fk_user_creat = null WHERE rowid = " . $this->contact_id;
974
            if (!$error && !Config::$dbEngine->query($sql)) {
975
                $error++;
976
                $this->error = Config::$dbEngine->lasterror();
977
            }
978
        }
979
980
        // Remove extrafields
981
        if ((!$error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) { // For avoid conflicts if trigger used
982
            $result = $this->deleteExtraFields();
983
            if ($result < 0) {
984
                $error++;
985
                DolUtils::dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR);
986
            }
987
        }
988
989
        // Remove user
990
        if (!$error) {
991
            $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user WHERE rowid = " . $this->id;
992
            DolUtils::dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
993
            if (!Config::$dbEngine->query($sql)) {
994
                $error++;
995
                $this->error = Config::$dbEngine->lasterror();
996
            }
997
        }
998
999
        if (!$error) {
1000
            // Call trigger
1001
            $result = $this->call_trigger('USER_DELETE', $user);
1002
            if ($result < 0) {
1003
                $error++;
1004
                Config::$dbEngine->rollback();
1005
                return -1;
1006
            }
1007
            // End call triggers
1008
1009
            Config::$dbEngine->commit();
1010
            return 1;
1011
        } else {
1012
            Config::$dbEngine->rollback();
1013
            return -1;
1014
        }
1015
    }
1016
1017
    /**
1018
     *  Create a user into database
1019
     *
1020
     *  @param	User	$user        	Objet user doing creation
1021
     *  @param  int		$notrigger		1=do not execute triggers, 0 otherwise
1022
     *  @return int			         	<0 if KO, id of created user if OK
1023
     */
1024
    function create($user, $notrigger = 0)
1025
    {
1026
        global $conf, $langs;
1027
        global $mysoc;
1028
1029
        // Clean parameters
1030
        $this->login = trim($this->login);
1031
        if (!isset($this->entity)) {
1032
            $this->entity = Globals::$conf->entity; // If not defined, we use default value
1033
        }
1034
        DolUtils::dol_syslog(get_class($this) . "::create login=" . $this->login . ", user=" . (is_object($user) ? $user->id : ''), LOG_DEBUG);
1035
1036
        // Check parameters
1037
        if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1038
            $langs->load("errors");
1039
            $this->error = $langs->trans("ErrorBadEMail", $this->email);
1040
            return -1;
1041
        }
1042
        if (empty($this->login)) {
1043
            $langs->load("errors");
1044
            $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login"));
1045
            return -1;
1046
        }
1047
1048
        $this->datec = dol_now();
1049
1050
        $error = 0;
1051
        Config::$dbEngine->begin();
1052
1053
        $sql = "SELECT login FROM " . MAIN_DB_PREFIX . "user";
1054
        $sql .= " WHERE login ='" . Config::$dbEngine->escape($this->login) . "'";
1055
        $sql .= " AND entity IN (0," . Config::$dbEngine->escape($conf->entity) . ")";
1056
1057
        DolUtils::dol_syslog(get_class($this) . "::create", LOG_DEBUG);
1058
        $resql = Config::$dbEngine->query($sql);
1059
        if ($resql) {
1060
            $num = Config::$dbEngine->num_rows($resql);
1061
            Config::$dbEngine->free($resql);
0 ignored issues
show
Bug introduced by alxarafe
The method free() does not exist on Alxarafe\Database\Engine. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1061
            Config::$dbEngine->/** @scrutinizer ignore-call */ 
1062
                               free($resql);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1062
1063
            if ($num) {
1064
                $this->error = 'ErrorLoginAlreadyExists';
1065
                DolUtils::dol_syslog(get_class($this) . "::create " . $this->error, LOG_WARNING);
1066
                Config::$dbEngine->rollback();
1067
                return -6;
1068
            } else {
1069
                $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user (datec,login,ldap_sid,entity)";
1070
                $sql .= " VALUES('" . Config::$dbEngine->idate($this->datec) . "','" . Config::$dbEngine->escape($this->login) . "','" . Config::$dbEngine->escape($this->ldap_sid) . "'," . Config::$dbEngine->escape($this->entity) . ")";
0 ignored issues
show
Bug introduced by alxarafe
The method idate() does not exist on Alxarafe\Database\Engine. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1070
                $sql .= " VALUES('" . Config::$dbEngine->/** @scrutinizer ignore-call */ idate($this->datec) . "','" . Config::$dbEngine->escape($this->login) . "','" . Config::$dbEngine->escape($this->ldap_sid) . "'," . Config::$dbEngine->escape($this->entity) . ")";

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1071
                $result = Config::$dbEngine->query($sql);
1072