Passed
Pull Request — main (#3)
by Rafael
54:18
created

DolibarrApi   F

Complexity

Total Complexity 65

Size/Duplication

Total Lines 584
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 317
dl 0
loc 584
rs 3.2
c 0
b 0
f 0
wmc 65

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 3
A _checkFilters() 0 5 1
A getModule() 0 4 1
A _forge_criteria_callback() 0 3 1
B _getModules() 0 32 8
B _filterObjectProperties() 0 38 9
A getModuleApiClasses() 0 18 4
A getModuleNamespace() 0 3 1
A _checkAccessToResource() 0 17 4
C _cleanObjectDatas() 0 172 11
A getModules() 0 8 2
D _checkValForAPI() 0 43 18
B getFolderForModuleCode() 0 93 2

How to fix   Complexity   

Complex Class

Complex classes like DolibarrApi often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use DolibarrApi, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/* Copyright (C) 2015       Jean-François Ferry         <[email protected]>
4
 * Copyright (C) 2016	    Laurent Destailleur		    <[email protected]>
5
 * Copyright (C) 2020		Frédéric France		        <[email protected]>
6
 * Copyright (C) 2024		MDW							<[email protected]>
7
 * Copyright (C) 2024       Rafael San José             <[email protected]>
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21
 */
22
23
namespace Dolibarr\Core\Base;
24
25
use Dolibarr\Code\Api\Classes\DolibarrApiAccess;
26
use DoliDB;
27
use Luracast\Restler\Defaults;
28
use Luracast\Restler\Restler;
29
30
/**
31
 * Class for API REST v1
32
 */
33
class DolibarrApi
34
{
35
    /**
36
     * @var Restler $r Restler object
37
     */
38
    public $r;
39
    /**
40
     * @var DoliDB $db Database object
41
     */
42
    protected $db;
43
44
    /**
45
     * Constructor
46
     *
47
     * @param DoliDB $db Database handler
48
     * @param string $cachedir Cache dir
49
     * @param boolean $refreshCache Update cache
50
     */
51
    public function __construct($db, $cachedir = '', $refreshCache = false)
52
    {
53
        global $conf, $dolibarr_main_url_root;
54
55
        if (empty($cachedir)) {
56
            $cachedir = $conf->api->dir_temp;
57
        }
58
        Defaults::$cacheDirectory = $cachedir;
59
60
        $this->db = $db;
61
        $production_mode = (!getDolGlobalString('API_PRODUCTION_MODE') ? false : true);
62
        $this->r = new Restler($production_mode, $refreshCache);
63
64
        $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root));
65
        $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT; // This is to use external domain name found into config file
66
67
        $urlwithouturlrootautodetect = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim(DOL_MAIN_URL_ROOT));
68
        $urlwithrootautodetect = $urlwithouturlroot . DOL_URL_ROOT; // This is to use local domain autodetected by dolibarr from url
69
70
        $this->r->setBaseUrls($urlwithouturlroot, $urlwithouturlrootautodetect);
71
        $this->r->setAPIVersion(1);
72
        //$this->r->setSupportedFormats('json');
73
        //$this->r->setSupportedFormats('jsonFormat');
74
    }
75
76
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
77
78
    public static function getModules($modulesdir = null)
79
    {
80
        if (!isset($modulesdir)) {
81
            $modulesdir = dolGetModulesDirs();
82
        }
83
        $result = static::_getModules($modulesdir);
84
        asort($result);
85
        return $result;
86
    }
87
88
    private static function _getModules($modulesdir)
89
    {
90
        $result = [];
91
        foreach ($modulesdir as $dir) {
92
            // Search available module
93
            dol_syslog("Scan directory " . $dir . " for module descriptor files, then search for API files");
94
95
            $handle = @opendir(dol_osencode($dir));
96
            if (is_resource($handle)) {
97
                while (($file = readdir($handle)) !== false) {
98
99
                    if (is_readable($dir . $file)) {
100
                        $module = DolibarrModules::_getModuleName($file);
101
                        if (!DolibarrModules::isActivated($module)) {
102
                            continue;
103
                        }
104
105
                        $moduledirforclass = static::getFolderForModuleCode($module);
106
                        $moduleClasses = DolibarrApi::getModuleApiClasses($moduledirforclass);
107
108
                        if (empty($moduleClasses)) {
109
                            continue;
110
                        }
111
112
                        foreach ($moduleClasses as $name => $module) {
113
                            $result[$name] = $module;
114
                        }
115
                    }
116
                }
117
            }
118
        }
119
        return $result;
120
    }
121
122
    /**
123
     * Get name of directory where the api_...class.php file is stored
124
     *
125
     * @param string $moduleobject Module object name
126
     * @return  string                    Directory name
127
     */
128
    public static function getFolderForModuleCode($moduleobject)
129
    {
130
        $mapping = [
131
            'Accounting' => 'Accountancy',
132
            'Adherent' => 'Adherents',
133
            'Agenda' => 'Comm',
134
            'Ai' => 'Ai',
135
            'Api' => 'Api',
136
            'Banque' => 'ComptaBank',
137
            'Barcode' => 'Barcode',
138
            'BlockedLog' => 'BloquedLog',
139
            'Bom' => 'Bom',
140
            'BookCal' => 'BookCal',
141
            'Bookmark' => 'Bookmark',
142
            'Category' => 'Categories',
143
            'ClickToDial' => 'ClickToDial',
144
            'Commande' => 'Commande',
145
            'Contrat' => 'Contrat',
146
            'Cron' => 'Cron',
147
            'DataPolicy' => 'DataPolicy',
148
            'Dav' => 'Dav',
149
            'DebugBar' => 'DebugBar',
150
            'Don' => 'Don',
151
            'DynamicPrices' => 'DynamicPrices',
152
            'ECM' => 'Ecm',
153
            'EmailCollector' => 'EmailCollector',
154
            'EventOrganization' => 'EventOrganization',
155
            'Expedition' => 'Expedition',
156
            'ExpenseReport' => 'ExpenseReport',
157
            'Export' => 'Exports',
158
            'ExternalRss' => 'ExternalRss',
159
            'ExternalSite' => 'ExternalSite',
160
            'Facture' => 'ComptaFacture',
161
            'Fckeditor' => 'Fckeditor',
162
            'Ficheinter' => 'FichInter',
163
            'Fournisseur' => 'Fourn',
164
            'GeoIPMaxmind' => 'GeoIPMaxmind',
165
            'Gravatar' => 'Gravatar',
166
            'Holiday' => 'Holiday',
167
            'HRM' => 'Hrm',
168
            'Import' => 'Imports',
169
            'Incoterm' => 'Incoterm',
170
            'KnowledgeManagement' => 'KnowledgeManagement',
171
            'Ldap' => 'Ldap',
172
            'Loan' => 'Loan',
173
            'Mailing' => 'Mailing',
174
            'MailmanSpip' => 'MailmanSpip',
175
            'Margin' => 'Margin',
176
            'ModuleBuilder' => 'ModuleBuilder',
177
            'Mrp' => 'Mrp',
178
            'MultiCurrency' => 'MultiCurrency',
179
            'Notification' => 'Notification',
180
            'Oauth' => 'Oauth',
181
            'OpenSurvey' => 'OpenSurvey',
182
            'Partnership' => 'Partnerships',
183
            'PaymentByBankTransfer' => 'PaymentByBankTransfer',
184
            'Paypal' => 'Paypal',
185
            'Prelevement' => 'Prelevement',
186
            'Printing' => 'Printing',
187
            'ProductBatch' => 'ProductBatch',
188
            'Product' => 'Product',
189
            'Projet' => 'Projet',
190
            'Propale' => 'CommPropale',
191
            'ReceiptPrinter' => 'ReceiptPrinter',
192
            'Reception' => 'Reception',
193
            'Recruitment' => 'Recruitement',
194
            'Resource' => 'Resource',
195
            'Salaries' => 'Salaries',
196
            'Service' => 'Service',
197
            'SocialNetworks' => 'SocialNetworks',
198
            'Societe' => 'Societe',
199
            'Stock' => 'ProductStock',
200
            'StockTransfer' => 'StockTransfer',
201
            'Stripe' => 'Stripe',
202
            'SupplierProposal' => 'SupplierProposal',
203
            'Syslog' => 'Syslog',
204
            'TakePos' => 'TakePos',
205
            'Tax' => 'Tax',
206
            'Ticket' => 'Ticket',
207
            'User' => 'User',
208
            'Variants' => 'Variants',
209
            'Webhook' => 'WebHook',
210
            'WebPortal' => 'WebPortal',
211
            'Website' => 'Website',
212
            'Workflow' => 'Workflow',
213
            'Workstation' => 'Workstation',
214
        ];
215
216
        if (isset($mapping[$moduleobject])) {
217
            return $mapping[$moduleobject];
218
        }
219
220
        return null;
221
    }
222
223
    public static function getModuleApiClasses($moduleName): array
224
    {
225
        $result = [];
226
        $apiPath = realpath(constant('BASE_PATH') . '/../Dolibarr/Code/' . $moduleName . '/Api');
227
        if ($apiPath === false) {
228
            return $result;
229
        }
230
231
        $dir = opendir($apiPath);
232
        while (($file = readdir($dir)) !== false) {
233
            if (pathinfo($file, PATHINFO_EXTENSION) !== 'php') {
234
                continue;
235
            }
236
            $className = pathinfo($file, PATHINFO_FILENAME);
237
            $result[$className] = static::getModuleNamespace($moduleName, $className);
238
        }
239
        closedir($dir);
240
        return $result;
241
    }
242
243
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
244
245
    /**
246
     * Obtains the namespace of an API module.
247
     *
248
     * @param $moduleName
249
     * @param $className
250
     * @return string
251
     */
252
    public static function getModuleNamespace($moduleName, $className): string
253
    {
254
        return 'Dolibarr\\Code\\' . $moduleName . '\\Api\\' . $className;
255
    }
256
257
    /**
258
     * Obtains an instance of $moduleName/$className, or null.
259
     *
260
     * @param $moduleName
261
     * @param $className
262
     * @return mixed
263
     */
264
    public static function getModule($moduleName, $className)
265
    {
266
        $namespace = static::getModuleNamespace($moduleName, $className);
267
        return new $namespace();
268
    }
269
270
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
271
272
    /**
273
     * Check access by user to a given resource
274
     *
275
     * @param string $resource element to check
276
     * @param int $resource_id Object ID if we want to check a particular record (optional) is linked to a owned thirdparty (optional).
277
     * @param string $dbtablename 'TableName&SharedElement' with Tablename is table where object is stored. SharedElement is an optional key to define where to check entity. Not used if objectid is null (optional)
278
     * @param string $feature2 Feature to check, second level of permission (optional). Can be or check with 'level1|level2'.
279
     * @param string $dbt_keyfield Field name for socid foreign key if not fk_soc. Not used if objectid is null (optional)
280
     * @param string $dbt_select Field name for select if not rowid. Not used if objectid is null (optional)
281
     * @return bool
282
     */
283
    protected static function _checkAccessToResource($resource, $resource_id = 0, $dbtablename = '', $feature2 = '', $dbt_keyfield = 'fk_soc', $dbt_select = 'rowid')
284
    {
285
        // phpcs:enable
286
        // Features/modules to check
287
        $featuresarray = array($resource);
288
        if (preg_match('/&/', $resource)) {
289
            $featuresarray = explode("&", $resource);
290
        } elseif (preg_match('/\|/', $resource)) {
291
            $featuresarray = explode("|", $resource);
292
        }
293
294
        // More subfeatures to check
295
        if (!empty($feature2)) {
296
            $feature2 = explode("|", $feature2);
297
        }
298
299
        return checkUserAccessToObject(DolibarrApiAccess::$user, $featuresarray, $resource_id, $dbtablename, $feature2, $dbt_keyfield, $dbt_select);
300
    }
301
302
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
303
304
    /**
305
     * Function to forge a SQL criteria from a Generic filter string.
306
     * Function no more used. Kept for backward compatibility with old APIs of modules
307
     *
308
     * @param array $matches Array of found string by regex search.
309
     *                              Each entry is 1 and only 1 criteria.
310
     *                              Example: "t.ref:like:'SO-%'", "t.date_creation:<:'20160101'", "t.date_creation:<:'2016-01-01 12:30:00'", "t.nature:is:NULL", "t.field2:isnot:NULL"
311
     * @return string               Forged criteria. Example: "t.field like 'abc%'"
312
     */
313
    protected static function _forge_criteria_callback($matches)
314
    {
315
        return dolForgeCriteriaCallback($matches);
316
    }
317
318
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
319
320
    /**
321
     * Check and convert a string depending on its type/name.
322
     *
323
     * @param string $field Field name
324
     * @param string|array $value Value to check/clean
325
     * @param Object $object Object
326
     * @return  string|array                Value cleaned
327
     */
328
    protected function _checkValForAPI($field, $value, $object)
329
    {
330
        // phpcs:enable
331
        if (!is_array($value)) {
332
            // Sanitize the value using its type declared into ->fields of $object
333
            if (!empty($object->fields) && !empty($object->fields[$field]) && !empty($object->fields[$field]['type'])) {
334
                if (strpos($object->fields[$field]['type'], 'int') || strpos($object->fields[$field]['type'], 'double') || in_array($object->fields[$field]['type'], array('real', 'price', 'stock'))) {
335
                    return sanitizeVal($value, 'int');
336
                }
337
                if ($object->fields[$field]['type'] == 'html') {
338
                    return sanitizeVal($value, 'restricthtml');
339
                }
340
                if ($object->fields[$field]['type'] == 'select') {
341
                    // Check values are in the list of possible 'options'
342
                    // TODO
343
                }
344
                if ($object->fields[$field]['type'] == 'sellist' || $object->fields[$field]['type'] == 'checkbox') {
345
                    // TODO
346
                }
347
                if ($object->fields[$field]['type'] == 'boolean' || $object->fields[$field]['type'] == 'radio') {
348
                    // TODO
349
                }
350
                if ($object->fields[$field]['type'] == 'email') {
351
                    return sanitizeVal($value, 'email');
352
                }
353
                if ($object->fields[$field]['type'] == 'password') {
354
                    return sanitizeVal($value, 'none');
355
                }
356
                // Others will use 'alphanohtml'
357
            }
358
359
            if (in_array($field, array('note', 'note_private', 'note_public', 'desc', 'description'))) {
360
                return sanitizeVal($value, 'restricthtml');
361
            } else {
362
                return sanitizeVal($value, 'alphanohtml');
363
            }
364
        } else {    // Example when $field = 'extrafields' and $value = content of $object->array_options
365
            $newarrayvalue = array();
366
            foreach ($value as $tmpkey => $tmpvalue) {
367
                $newarrayvalue[$tmpkey] = $this->_checkValForAPI($tmpkey, $tmpvalue, $object);
368
            }
369
370
            return $newarrayvalue;
371
        }
372
    }
373
374
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
375
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
376
377
    /**
378
     * Filter properties that will be returned on object
379
     *
380
     * @param Object $object Object to clean
381
     * @param String $properties Comma separated list of properties names
382
     * @return  Object                  Object with cleaned properties
383
     */
384
    protected function _filterObjectProperties($object, $properties)
385
    {
386
        // phpcs:enable
387
        // If properties is empty, we return all properties
388
        if (empty($properties)) {
389
            return $object;
390
        }
391
392
        // Copy of exploded array for efficiency
393
        $arr_properties = explode(',', $properties);
394
        $magic_properties = array();
395
        $real_properties = get_object_vars($object);
396
397
        // Unsetting real properties may unset magic properties.
398
        // We keep a copy of the requested magic properties
399
        foreach ($arr_properties as $key) {
400
            if (!array_key_exists($key, $real_properties)) {
401
                // Not a real property,
402
                // check if $key is a magic property (we want to keep '$obj->$key')
403
                if (property_exists($object, $key) && isset($object->$key)) {
404
                    $magic_properties[$key] = $object->$key;
405
                }
406
            }
407
        }
408
409
        // Filter real properties (may indirectly unset magic properties)
410
        foreach (get_object_vars($object) as $key => $value) {
411
            if (!in_array($key, $arr_properties)) {
412
                unset($object->$key);
413
            }
414
        }
415
416
        // Restore the magic properties
417
        foreach ($magic_properties as $key => $value) {
418
            $object->$key = $value;
419
        }
420
421
        return $object;
422
    }
423
424
    /**
425
     * Clean sensible object datas
426
     *
427
     * @param Object $object Object to clean
428
     * @return  Object              Object with cleaned properties
429
     */
430
    protected function _cleanObjectDatas($object)
431
    {
432
        // phpcs:enable
433
        // Remove $db object property for object
434
        unset($object->db);
435
        unset($object->isextrafieldmanaged);
436
        unset($object->ismultientitymanaged);
437
        unset($object->restrictiononfksoc);
438
        unset($object->table_rowid);
439
        unset($object->pass);
440
        unset($object->pass_indatabase);
441
442
        // Remove linkedObjects. We should already have and keep only linkedObjectsIds that avoid huge responses
443
        unset($object->linkedObjects);
444
        //unset($object->lines[$i]->linked_objects);        // This is the array to create linked object during create
445
446
        unset($object->fields);
447
        unset($object->oldline);
448
449
        unset($object->error);
450
        unset($object->errors);
451
        unset($object->errorhidden);
452
453
        unset($object->ref_previous);
454
        unset($object->ref_next);
455
        unset($object->imgWidth);
456
        unset($object->imgHeight);
457
        unset($object->barcode_type_code);
458
        unset($object->barcode_type_label);
459
460
        unset($object->mode_reglement);     // We use mode_reglement_id now
461
        unset($object->cond_reglement);     // We use cond_reglement_id now
462
        unset($object->note);               // We use note_public or note_private now
463
        unset($object->contact);            // We use contact_id now
464
        unset($object->thirdparty);         // We use thirdparty_id or fk_soc or socid now
465
466
        unset($object->projet); // Should be fk_project
467
        unset($object->project); // Should be fk_project
468
        unset($object->fk_projet); // Should be fk_project
469
        unset($object->author); // Should be fk_user_author
470
        unset($object->timespent_old_duration);
471
        unset($object->timespent_id);
472
        unset($object->timespent_duration);
473
        unset($object->timespent_date);
474
        unset($object->timespent_datehour);
475
        unset($object->timespent_withhour);
476
        unset($object->timespent_fk_user);
477
        unset($object->timespent_note);
478
        unset($object->fk_delivery_address);
479
        unset($object->model_pdf);
480
        unset($object->sendtoid);
481
        unset($object->name_bis);
482
        unset($object->newref);
483
        unset($object->oldref);
484
        unset($object->alreadypaid);
485
        unset($object->openid);
486
        unset($object->fk_bank);
487
        unset($object->showphoto_on_popup);
488
        unset($object->nb);
489
        unset($object->nbphoto);
490
        unset($object->output);
491
        unset($object->tpl);
492
        //unset($object->libelle);
493
494
        unset($object->stats_propale);
495
        unset($object->stats_commande);
496
        unset($object->stats_contrat);
497
        unset($object->stats_facture);
498
        unset($object->stats_commande_fournisseur);
499
        unset($object->stats_reception);
500
        unset($object->stats_mrptoconsume);
501
        unset($object->stats_mrptoproduce);
502
503
        unset($object->origin_object);
504
        unset($object->origin);
505
        unset($object->element);
506
        unset($object->element_for_permission);
507
        unset($object->fk_element);
508
        unset($object->table_element);
509
        unset($object->table_element_line);
510
        unset($object->class_element_line);
511
        unset($object->picto);
512
        unset($object->linked_objects);
513
514
        unset($object->fieldsforcombobox);
515
        unset($object->regeximgext);
516
517
        unset($object->skip_update_total);
518
        unset($object->context);
519
        unset($object->next_prev_filter);
520
521
        unset($object->region);
522
        unset($object->region_code);
523
        unset($object->country);
524
        unset($object->state);
525
        unset($object->state_code);
526
        unset($object->fk_departement);
527
        unset($object->departement);
528
        unset($object->departement_code);
529
530
        unset($object->libelle_statut);
531
        unset($object->libelle_paiement);
532
        unset($object->labelStatus);
533
        unset($object->labelStatusShort);
534
535
        unset($object->actionmsg);
536
        unset($object->actionmsg2);
537
538
        unset($object->prefix_comm);
539
540
        if (!isset($object->table_element) || $object->table_element != 'ticket') {
541
            unset($object->comments);
542
        }
543
544
        // Remove the $oldcopy property because it is not supported by the JSON
545
        // encoder. The following error is generated when trying to serialize
546
        // it: "Error encoding/decoding JSON: Type is not supported"
547
        // Note: Event if this property was correctly handled by the JSON
548
        // encoder, it should be ignored because keeping it would let the API
549
        // have a very strange behavior: calling PUT and then GET on the same
550
        // resource would give different results:
551
        // PUT /objects/{id} -> returns object with oldcopy = previous version of the object
552
        // GET /objects/{id} -> returns object with oldcopy empty
553
        unset($object->oldcopy);
554
555
        // If object has lines, remove $db property
556
        if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
557
            $nboflines = count($object->lines);
558
            for ($i = 0; $i < $nboflines; $i++) {
559
                $this->_cleanObjectDatas($object->lines[$i]);
560
561
                unset($object->lines[$i]->contact);
562
                unset($object->lines[$i]->contact_id);
563
                unset($object->lines[$i]->country);
564
                unset($object->lines[$i]->country_id);
565
                unset($object->lines[$i]->country_code);
566
                unset($object->lines[$i]->mode_reglement_id);
567
                unset($object->lines[$i]->mode_reglement_code);
568
                unset($object->lines[$i]->mode_reglement);
569
                unset($object->lines[$i]->cond_reglement_id);
570
                unset($object->lines[$i]->cond_reglement_code);
571
                unset($object->lines[$i]->cond_reglement);
572
                unset($object->lines[$i]->fk_delivery_address);
573
                unset($object->lines[$i]->fk_projet);
574
                unset($object->lines[$i]->fk_project);
575
                unset($object->lines[$i]->thirdparty);
576
                unset($object->lines[$i]->user);
577
                unset($object->lines[$i]->model_pdf);
578
                unset($object->lines[$i]->note_public);
579
                unset($object->lines[$i]->note_private);
580
                unset($object->lines[$i]->fk_incoterms);
581
                unset($object->lines[$i]->label_incoterms);
582
                unset($object->lines[$i]->location_incoterms);
583
                unset($object->lines[$i]->name);
584
                unset($object->lines[$i]->lastname);
585
                unset($object->lines[$i]->firstname);
586
                unset($object->lines[$i]->civility_id);
587
                unset($object->lines[$i]->fk_multicurrency);
588
                unset($object->lines[$i]->multicurrency_code);
589
                unset($object->lines[$i]->shipping_method_id);
590
            }
591
        }
592
593
        if (!empty($object->thirdparty) && is_object($object->thirdparty)) {
594
            $this->_cleanObjectDatas($object->thirdparty);
595
        }
596
597
        if (!empty($object->product) && is_object($object->product)) {
598
            $this->_cleanObjectDatas($object->product);
599
        }
600
601
        return $object;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $object also could return the type object which is incompatible with the documented return type object.
Loading history...
602
    }
603
604
    /**
605
     * Return if a $sqlfilters parameter is valid
606
     * Function no more used. Kept for backward compatibility with old APIs of modules
607
     *
608
     * @param string $sqlfilters sqlfilter string
609
     * @param string $error Error message
610
     * @return  boolean|string                  True if valid, False if not valid
611
     */
612
    protected function _checkFilters($sqlfilters, &$error = '')
613
    {
614
        // phpcs:enable
615
        $firstandlastparenthesis = 0;
616
        return dolCheckFilters($sqlfilters, $error, $firstandlastparenthesis);
617
    }
618
}
619