Util::calculate_progress_value()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 2
nop 2
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 20
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Util.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2021 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay
9
 */
10
11
namespace Pronamic\WordPress\Pay\Fundraising;
12
13
/**
14
 * Util.
15
 *
16
 * @author  Reüel van der Steege
17
 * @since   1.0.0
18
 * @version 1.0.0
19
 */
20
class Util {
21
	/**
22
	 * Calculate progress value.
23
	 *
24
	 * @param string $raised Raised amount.
25
	 * @param string $target Target amount.
26
	 *
27
	 * @return float
28
	 */
29
	public static function calculate_progress_value( $raised, $target ) {
30
		$raised = \floatval( $raised );
31
		$target = \floatval( $target );
32
33
		if ( 0 == $target && ( 0 == $raised || $raised > $target ) ) {
34
			$target = 100;
35
		}
36
37
		return (int) floor( ( $raised / $target ) * 100 );
38
	}
39
}
40