Passed
Pull Request — master (#82)
by
unknown
02:47
created

addOrderToCartProcessingQueue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 13
rs 9.9666

1 Method

Rating   Name   Duplication   Size   Complexity  
A alterCartProcessingTable() 0 9 2
1
<?php
2
3
function requireWPPluginFunctions()
4
{
5
    if (! function_exists('is_plugin_active')) {
6
        require_once(ABSPATH . 'wp-admin/includes/plugin.php');
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
7
    }
8
}
9
10
requireWPPluginFunctions();
11
12
13
/**
14
 * Get lowercase config value from WP DB
15
 *
16
 * @param string $configKey
17
 *
18
 * @return string
19
 * @global wpdb  $wpdb WordPress database abstraction object.
20
 */
21
function getConfigValue($configKey)
22
{
23
    global $wpdb;
24
    $tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME;
25
    $value     = $wpdb->get_var($wpdb->prepare("SELECT value FROM $tableName WHERE config= %s ", $configKey));
26
27
    return $value;
28
}
29
30
/**
31
 * Check if table exists in WordPress DB
32
 *
33
 * @param string $tableToCheck
34
 *
35
 * @return bool
36
 * @see wpdb::get_var()
37
 */
38
function isPgTableCreated($tableToCheck)
39
{
40
    global $wpdb;
41
    $tableName = $wpdb->prefix . $tableToCheck;
42
    if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName) {
43
        return true;
44
    }
45
46
    return false;
47
}
48
49
50
function createLogsTable()
51
{
52
    global $wpdb;
53
    $charset_collate = $wpdb->get_charset_collate();
54
    $LogsTableName   = $wpdb->prefix . PG_LOGS_TABLE_NAME;
55
    $sqlQuery        = "CREATE TABLE $LogsTableName ( 
56
    id int NOT NULL AUTO_INCREMENT,
57
    log text NOT NULL, 
58
    createdAt timestamp DEFAULT CURRENT_TIMESTAMP,
59
    UNIQUE KEY id (id)) 
60
    $charset_collate";
61
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
62
    dbDelta($sqlQuery);
0 ignored issues
show
Bug introduced by
The function dbDelta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

62
    /** @scrutinizer ignore-call */ 
63
    dbDelta($sqlQuery);
Loading history...
63
}
64
65
/**
66
 * @param null $exception
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $exception is correct as it would always require null to be passed?
Loading history...
67
 * @param null $message
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $message is correct as it would always require null to be passed?
Loading history...
68
 */
69
function insertLogEntry($exception = null, $message = null)
70
{
71
    global $wpdb;
72
    if (! isPgTableCreated(PG_LOGS_TABLE_NAME)) {
73
        createLogsTable();
74
    }
75
    $logEntry = new Pagantis\ModuleUtils\Model\Log\LogEntry();
76
    if ($exception instanceof \Exception) {
77
        $logEntry = $logEntry->error($exception);
78
    } else {
79
        $logEntry = $logEntry->info($message);
80
    }
81
    $tableName = $wpdb->prefix . PG_LOGS_TABLE_NAME;
82
    $wpdb->insert($tableName, array('log' => $logEntry->toJson()));
83
}
84
85
/**
86
 * @return bool
87
 */
88
function areDecimalSeparatorEqual()
89
{
90
    $pgDecimalSeparator = getPgSimulatorDecimalSeparatorConfig();
91
    $wc_decimal_sep     = get_option('woocommerce_price_decimal_sep');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

91
    $wc_decimal_sep     = /** @scrutinizer ignore-call */ get_option('woocommerce_price_decimal_sep');
Loading history...
92
    if (stripslashes($wc_decimal_sep) == stripslashes($pgDecimalSeparator)) {
93
        return true;
94
    } else {
95
        return false;
96
    }
97
}
98
99
100
/**
101
 * @return bool
102
 */
103
function areThousandsSeparatorEqual()
104
{
105
    $pgThousandSeparator = getPgSimulatorThousandsSeparator();
106
    $wc_price_thousand   = get_option('woocommerce_price_thousand_sep');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

106
    $wc_price_thousand   = /** @scrutinizer ignore-call */ get_option('woocommerce_price_thousand_sep');
Loading history...
107
    if (stripslashes($wc_price_thousand) == stripslashes($pgThousandSeparator)) {
108
        return true;
109
    } else {
110
        return false;
111
    }
112
}
113
114
/**
115
 * @return array|object|null
116
 */
117
function getPgSimulatorThousandsSeparator()
118
{
119
    global $wpdb;
120
    $tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME;
121
    $query     = "SELECT value FROM $tableName WHERE config='PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'";
122
    $result    = $wpdb->get_row($query, ARRAY_A);
0 ignored issues
show
Bug introduced by
The constant ARRAY_A was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
123
124
    return $result['value'];
125
}
126
127
/**
128
 * @return array|object|null
129
 */
130
function getPgSimulatorDecimalSeparatorConfig()
131
{
132
    global $wpdb;
133
    $tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME;
134
    $query     = "SELECT value FROM $tableName WHERE config='PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'";
135
    $result    = $wpdb->get_row($query, ARRAY_A);
0 ignored issues
show
Bug introduced by
The constant ARRAY_A was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
136
137
    return $result['value'];
138
}
139
140
function updateThousandsSeparatorDbConfig()
141
{
142
    global $wpdb;
143
    if (areThousandsSeparatorEqual()) {
144
        return;
145
    }
146
    $tableName         = $wpdb->prefix . PG_CONFIG_TABLE_NAME;
147
    $thousandSeparator = get_option('woocommerce_price_thousand_sep');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

147
    $thousandSeparator = /** @scrutinizer ignore-call */ get_option('woocommerce_price_thousand_sep');
Loading history...
148
    $wpdb->update(
149
        $tableName,
150
        array('value' => $thousandSeparator),
151
        array('config' => 'PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'),
152
        array('%s'),
153
        array('%s')
154
    );
155
}
156
157
function updateDecimalSeparatorDbConfig()
158
{
159
    global $wpdb;
160
    if (areDecimalSeparatorEqual()) {
161
        return;
162
    }
163
    $tableName        = $wpdb->prefix . PG_CONFIG_TABLE_NAME;
164
    $decimalSeparator = get_option('woocommerce_price_decimal_sep');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

164
    $decimalSeparator = /** @scrutinizer ignore-call */ get_option('woocommerce_price_decimal_sep');
Loading history...
165
    $wpdb->update(
166
        $tableName,
167
        array('value' => $decimalSeparator),
168
        array('config' => 'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'),
169
        array('%s'),
170
        array('%s')
171
    );
172
}
173
174
175
/**
176
 * @param $simulatorType
177
 * @param $validSimulatorTypes array
178
 *
179
 * @return bool
180
 */
181
function isSimulatorTypeValid($simulatorType, $validSimulatorTypes)
182
{
183
    if (! in_array($simulatorType, $validSimulatorTypes)) {
184
        return false;
185
    }
186
187
    return true;
188
}
189
190
/**
191
 * @param $currentTemplateName
192
 *
193
 * @param $validTemplateNames array
194
 *
195
 * @return bool
196
 */
197
function isTemplatePresent($currentTemplateName, $validTemplateNames)
198
{
199
    if (in_array($currentTemplateName, $validTemplateNames)) {
200
        return true;
201
    }
202
203
    return false;
204
}
205
206
207
function areMerchantKeysSet()
208
{
209
    $settings   = get_option('woocommerce_pagantis_settings');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

209
    $settings   = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
210
    $publicKey  = ! empty($settings['pagantis_public_key']) ? $settings['pagantis_public_key'] : '';
211
    $privateKey = ! empty($settings['pagantis_private_key']) ? $settings['pagantis_private_key'] : '';
212
    if ((empty($publicKey) && empty($privateKey)) || (empty($publicKey) || empty($privateKey))) {
213
        return false;
214
    }
215
216
    return true;
217
}
218
219
function areMerchantKeysSet4x()
220
{
221
    $settings   = get_option('woocommerce_pagantis_settings');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

221
    $settings   = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
222
    $publicKey  = ! empty($settings['pagantis_public_key_4x']) ? $settings['pagantis_public_key_4x'] : '';
223
    $privateKey = ! empty($settings['pagantis_private_key_4x']) ? $settings['pagantis_private_key_4x'] : '';
224
    if ((empty($publicKey) && empty($privateKey)) || (empty($publicKey) || empty($privateKey))) {
225
        return false;
226
    }
227
228
    return true;
229
}
230
231
function isSimulatorEnabled()
232
{
233
    $settings = get_option('woocommerce_pagantis_settings');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

233
    $settings = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
234
    if ((! empty($settings['simulator']) && 'yes' === $settings['simulator']) ? true : false) {
235
        return true;
236
    }
237
238
    return false;
239
}
240
241
function isPluginEnabled()
242
{
243
    $settings = get_option('woocommerce_pagantis_settings');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

243
    $settings = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
244
245
    return (! empty($settings['enabled']) && 'yes' === $settings['enabled']);
246
}
247
248
function isPluginEnabled4x()
249
{
250
    $settings = get_option('woocommerce_pagantis_settings');
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

250
    $settings = /** @scrutinizer ignore-call */ get_option('woocommerce_pagantis_settings');
Loading history...
251
252
    return (! empty($settings['enabled_4x']) && 'yes' === $settings['enabled_4x']);
253
}
254
255
256
function isCountryShopContextValid()
257
{
258
    $locale           = strtolower(strstr(get_locale(), '_', true));
0 ignored issues
show
Bug introduced by
The function get_locale was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

258
    $locale           = strtolower(strstr(/** @scrutinizer ignore-call */ get_locale(), '_', true));
Loading history...
259
    $allowedCountries = maybe_unserialize(getConfigValue('PAGANTIS_ALLOWED_COUNTRIES'));
0 ignored issues
show
Bug introduced by
The function maybe_unserialize was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

259
    $allowedCountries = /** @scrutinizer ignore-call */ maybe_unserialize(getConfigValue('PAGANTIS_ALLOWED_COUNTRIES'));
Loading history...
260
    if (! in_array(strtolower($locale), $allowedCountries)) {
261
        return false;
262
    }
263
264
    return true;
265
}
266
267
/**
268
 * @return bool
269
 */
270
function isProductAmountValid()
271
{
272
    $minAmount = getConfigValue('PAGANTIS_DISPLAY_MIN_AMOUNT');
273
    $maxAmount = getConfigValue('PAGANTIS_DISPLAY_MAX_AMOUNT');
274
    global $product;
275
    if (method_exists($product, 'get_price')) {
276
        $productPrice = $product->get_price();
277
        $validAmount  = ($productPrice >= $minAmount && ($productPrice <= $maxAmount || $maxAmount == '0'));
278
        if ($validAmount) {
279
            return true;
280
        }
281
    }
282
283
    return false;
284
}
285
286
/**
287
 * @return bool
288
 */
289
function isProductAmountValid4x()
290
{
291
    $minAmount = getConfigValue('PAGANTIS_DISPLAY_MIN_AMOUNT_4x');
292
    $maxAmount = getConfigValue('PAGANTIS_DISPLAY_MAX_AMOUNT_4x');
293
    global $product;
294
    if (method_exists($product, 'get_price')) {
295
        $productPrice = $product->get_price();
296
        $validAmount  = ($productPrice >= $minAmount && ($productPrice <= $maxAmount || $maxAmount == '0'));
297
        if ($validAmount) {
298
            return true;
299
        }
300
    }
301
302
    return false;
303
}
304
305
function getAllowedCurrencies()
306
{
307
    return array("EUR");
308
}
309
310
/**
311
 * @return array
312
 */
313
function getExtraConfig()
314
{
315
    global $wpdb;
316
    $tableName = $wpdb->prefix . PG_CONFIG_TABLE_NAME;
317
    $response  = array();
318
    $dbResult  = $wpdb->get_results("select config, value from $tableName", ARRAY_A);
0 ignored issues
show
Bug introduced by
The constant ARRAY_A was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
319
    foreach ($dbResult as $value) {
320
        $response[$value['config']] = $value['value'];
321
    }
322
323
    return $response;
324
}
325
326
function getModuleVersion()
327
{
328
    $mainFile = plugin_dir_path(PG_WC_MAIN_FILE) . '/WC_Pagantis.php';
0 ignored issues
show
Bug introduced by
The function plugin_dir_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

328
    $mainFile = /** @scrutinizer ignore-call */ plugin_dir_path(PG_WC_MAIN_FILE) . '/WC_Pagantis.php';
Loading history...
329
    $version  = get_file_data($mainFile, array('Version' => 'Version'), false);
0 ignored issues
show
Bug introduced by
The function get_file_data was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

329
    $version  = /** @scrutinizer ignore-call */ get_file_data($mainFile, array('Version' => 'Version'), false);
Loading history...
330
331
    return $version['Version'];
332
}
333
334
/**
335
 * @param $order
336
 *
337
 * @return null
338
 */
339
function getNationalId($order)
340
{
341
    foreach ((array)$order->get_meta_data() as $mdObject) {
342
        $data = $mdObject->get_data();
343
        if ($data['key'] == 'vat_number') {
344
            return $data['value'];
345
        }
346
    }
347
348
    return null;
349
}
350
351
/**
352
 * @param $order
353
 *
354
 * @return mixed
355
 */
356
function getTaxId($order)
357
{
358
    foreach ((array)$order->get_meta_data() as $mdObject) {
359
        $data = $mdObject->get_data();
360
        if ($data['key'] == 'billing_cfpiva') {
361
            return $data['value'];
362
        }
363
    }
364
}
365
366
367
/**
368
 * @param $product_id
369
 *
370
 * @return string
371
 */
372
function isProductPromoted($product_id)
373
{
374
    $metaProduct = get_post_meta($product_id);
0 ignored issues
show
Bug introduced by
The function get_post_meta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

374
    $metaProduct = /** @scrutinizer ignore-call */ get_post_meta($product_id);
Loading history...
375
376
    return (array_key_exists('custom_product_pagantis_promoted', $metaProduct)
377
            && $metaProduct['custom_product_pagantis_promoted']['0'] === 'yes') ? 'true' : 'false';
378
}
379
380
/**
381
 * @return int
382
 */
383
function getPromotedAmount()
384
{
385
    $promotedAmount = 0;
386
    foreach (WC()->cart->get_cart() as $key => $item) {
0 ignored issues
show
Bug introduced by
The function WC was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

386
    foreach (/** @scrutinizer ignore-call */ WC()->cart->get_cart() as $key => $item) {
Loading history...
387
        $promotedProduct = isProductPromoted($item['product_id']);
388
        if ($promotedProduct == 'true') {
389
            $promotedAmount += $item['line_total'] + $item['line_tax'];
390
        }
391
    }
392
393
    return $promotedAmount;
394
}
395
396
/**
397
 * @param $cartHash
398
 * @param $pagantisOrderId
399
 *
400
 * @param $wcOrderID
401
 * @param $paymentProcessingToken
402
 */
403
function addOrderToProcessingQueue($cartHash, $pagantisOrderId, $wcOrderID, $paymentProcessingToken)
404
{
405
    global $wpdb;
406
    $tableName = $wpdb->prefix . PG_CART_PROCESS_TABLE;
407
    $wpdb->insert($tableName, array(
408
        'id'          => $cartHash,
409
        'order_id' => $pagantisOrderId,
410
        'wc_order_id' => $wcOrderID,
411
        'token'       => $paymentProcessingToken
412
    ), array('%s', '%s', '%s', '%s'));
413
}
414
415
function alterCartProcessingTable()
416
{
417
    global $wpdb;
418
    $tableName = $wpdb->prefix . PG_CART_PROCESS_TABLE;
419
    if (! $wpdb->get_var("SHOW COLUMNS FROM `{$tableName}` LIKE 'token'")) {
420
        $wpdb->query("ALTER TABLE $tableName ADD COLUMN `token` VARCHAR(32) NOT NULL AFTER `wc_order_id`");
421
        $wpdb->query("ALTER TABLE $tableName DROP PRIMARY KEY, ADD PRIMARY KEY(id,order_id)");
422
    }
423
    wp_cache_flush();
0 ignored issues
show
Bug introduced by
The function wp_cache_flush was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

423
    /** @scrutinizer ignore-call */ 
424
    wp_cache_flush();
Loading history...
424
}
425
426
/**
427
 * Check if orders table exists
428
 */
429
function createOrderProcessingTable()
430
{
431
    global $wpdb;
432
    $tableName = $wpdb->prefix . PG_CART_PROCESS_TABLE;
433
434
    if (! isPgTableCreated(PG_CART_PROCESS_TABLE)) {
435
        $charset_collate = $wpdb->get_charset_collate();
436
        $sql             = "CREATE TABLE IF NOT EXISTS $tableName  
437
            (id VARCHAR(60) NOT NULL, 
438
            order_id VARCHAR(60) NOT NULL, 
439
            wc_order_id VARCHAR(50) NOT NULL,
440
            token VARCHAR(32) NOT NULL, 
441
            PRIMARY KEY(id,order_id)) $charset_collate";
442
443
        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
444
        dbDelta($sql);
0 ignored issues
show
Bug introduced by
The function dbDelta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

444
        /** @scrutinizer ignore-call */ 
445
        dbDelta($sql);
Loading history...
445
    }
446
}
447
448
449
/**
450
 * Get the orders of a customer
451
 *
452
 * @param WP_User $current_user
0 ignored issues
show
Bug introduced by
The type WP_User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
453
 * @param         $billingEmail
454
 *
455
 * @return mixed
456
 * @uses Wordpress Core Post API
457
 */
458
function getOrders($current_user, $billingEmail)
459
{
460
    $sign_up         = '';
461
    $total_orders    = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $total_orders is dead and can be removed.
Loading history...
462
    $total_amt       = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $total_amt is dead and can be removed.
Loading history...
463
    $refund_amt      = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $refund_amt is dead and can be removed.
Loading history...
464
    $total_refunds   = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $total_refunds is dead and can be removed.
Loading history...
465
    $partial_refunds = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $partial_refunds is dead and can be removed.
Loading history...
466
    if ($current_user->user_login) {
467
        $is_guest        = "false";
0 ignored issues
show
Unused Code introduced by
The assignment to $is_guest is dead and can be removed.
Loading history...
468
        $sign_up         = substr($current_user->user_registered, 0, 10);
0 ignored issues
show
Unused Code introduced by
The assignment to $sign_up is dead and can be removed.
Loading history...
469
        $customer_orders = get_posts(array(
0 ignored issues
show
Bug introduced by
The function get_posts was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

469
        $customer_orders = /** @scrutinizer ignore-call */ get_posts(array(
Loading history...
470
            'numberposts' => -1,
471
            'meta_key'    => '_customer_user',
472
            'meta_value'  => $current_user->ID,
473
            'post_type'   => array('shop_order'),
474
            'post_status' => array('wc-completed', 'wc-processing', 'wc-refunded'),
475
        ));
476
    } else {
477
        $is_guest        = "true";
478
        $customer_orders = get_posts(array(
479
            'numberposts' => -1,
480
            'meta_key'    => '_billing_email',
481
            'meta_value'  => $billingEmail,
482
            'post_type'   => array('shop_order'),
483
            'post_status' => array('wc-completed', 'wc-processing', 'wc-refunded'),
484
        ));
485
        foreach ($customer_orders as $customer_order) {
486
            if (trim($sign_up) == '' || strtotime(substr($customer_order->post_date, 0, 10)) <= strtotime($sign_up)) {
487
                $sign_up = substr($customer_order->post_date, 0, 10);
488
            }
489
        }
490
    }
491
492
    return $customer_orders;
493
}
494