Passed
Push — master ( 9b0854...75b594 )
by Chris
02:31 queued 33s
created

lsx_currencies_get_price_html()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 14
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 19
rs 9.7998
1
<?php
2
/**
3
 * SCPO Engine
4
 *
5
 * @package   LSX Testimonials
6
 * @author    LightSpeed
7
 * @license   GPL3
8
 * @link
9
 * @copyright 2018 LightSpeed
10
 */
11
12
/**
13
 * Wraps your price in the currency html
14
 *
15
 * @param string $value
16
 * @return void
17
 */
18
function lsx_currencies_get_price_html( $value = '' ) {
19
	$prefix = '<span class="amount lsx-currencies" ';
20
	$value = preg_replace( '/[^0-9.]+/', '', $value );
21
	$decimals = substr_count( $value, '.' );
22
23
	if ( false !== $decimals && $decimals > 1 ) {
24
		$decimals--;
25
		$decimals = (int) $decimals;
26
		$value = preg_replace( '/' . preg_quote( '.', '/' ) . '/', '', $value, $decimals );
27
	}
28
	$prefix .= '>';
29
	$suffix = '</span>';
30
	setlocale( LC_MONETARY, 'en_US' );
31
32
	// Work out the other tags
33
	$currency = '<span class="currency-icon ' . mb_strtolower( lsx_currencies()->base_currency ) . '">' . lsx_currencies()->base_currency . '</span>';
34
	$amount = '<span class="value" data-price-' . lsx_currencies()->base_currency . '="' . trim( str_replace( 'USD', '', money_format( '%i', ltrim( rtrim( $value ) ) ) ) ) . '">' . str_replace( 'USD', '', money_format( '%i', ltrim( rtrim( $value ) ) ) ) . '</span>';
0 ignored issues
show
Bug introduced by
ltrim(rtrim($value)) of type string is incompatible with the type double expected by parameter $number of money_format(). ( Ignorable by Annotation )

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

34
	$amount = '<span class="value" data-price-' . lsx_currencies()->base_currency . '="' . trim( str_replace( 'USD', '', money_format( '%i', /** @scrutinizer ignore-type */ ltrim( rtrim( $value ) ) ) ) ) . '">' . str_replace( 'USD', '', money_format( '%i', ltrim( rtrim( $value ) ) ) ) . '</span>';
Loading history...
35
	$price_html = '<span class="amount lsx-currencies">' . $currency . $amount . '</span>';
36
	return $price_html;
37
}
38
39
/**
40
 * A shortcode to wrap a value in your content
41
 *
42
 * @param array $atts
43
 * @return void
44
 */
45
function lsx_currency_value( $atts ) {
46
	$a = shortcode_atts(
0 ignored issues
show
Bug introduced by
The function shortcode_atts 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

46
	$a = /** @scrutinizer ignore-call */ shortcode_atts(
Loading history...
47
		array(
48
			'value' => '0.00',
49
		),
50
		$atts
51
	);
52
	return lsx_currencies_get_price_html( $a['value'] );
0 ignored issues
show
Bug introduced by
Are you sure the usage of lsx_currencies_get_price_html($a['value']) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
53
}
54
add_shortcode( 'lsx_currency_value', 'lsx_currency_value' );
0 ignored issues
show
Bug introduced by
The function add_shortcode 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

54
/** @scrutinizer ignore-call */ 
55
add_shortcode( 'lsx_currency_value', 'lsx_currency_value' );
Loading history...
55