|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Parser |
|
4
|
|
|
* |
|
5
|
|
|
* @author Pronamic <[email protected]> |
|
6
|
|
|
* @copyright 2005-2018 Pronamic |
|
7
|
|
|
* @license GPL-3.0-or-later |
|
8
|
|
|
* @package Pronamic\WordPress\Money |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Money; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Parser |
|
15
|
|
|
* |
|
16
|
|
|
* @author Remco Tolsma |
|
17
|
|
|
* @version 1.0 |
|
18
|
|
|
*/ |
|
19
|
|
|
class Parser { |
|
20
|
|
|
/** |
|
21
|
|
|
* Parse. |
|
22
|
|
|
* |
|
23
|
|
|
* @link https://github.com/wp-pay/core/blob/2.0.2/src/Core/Util.php#L128-L176 |
|
24
|
|
|
* |
|
25
|
|
|
* @param string $money |
|
|
|
|
|
|
26
|
|
|
* @return Money |
|
27
|
|
|
*/ |
|
28
|
|
|
public function parse( $string ) { |
|
29
|
|
|
global $wp_locale; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
$decimal_sep = $wp_locale->number_format['decimal_point']; |
|
32
|
|
|
|
|
33
|
|
|
// Seperators. |
|
34
|
|
|
$seperators = array( $decimal_sep, '.', ',' ); |
|
35
|
|
|
$seperators = array_unique( array_filter( $seperators ) ); |
|
36
|
|
|
|
|
37
|
|
|
// Check. |
|
38
|
|
|
foreach ( array( - 3, - 2 ) as $i ) { |
|
39
|
|
|
$test = substr( $string, $i, 1 ); |
|
40
|
|
|
|
|
41
|
|
|
if ( in_array( $test, $seperators, true ) ) { |
|
42
|
|
|
$decimal_sep = $test; |
|
43
|
|
|
|
|
44
|
|
|
break; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
// Split. |
|
49
|
|
|
$position = strrpos( $string, $decimal_sep ); |
|
50
|
|
|
|
|
51
|
|
|
if ( false !== $position ) { |
|
52
|
|
|
$full = substr( $string, 0, $position ); |
|
53
|
|
|
$half = substr( $string, $position + 1 ); |
|
54
|
|
|
|
|
55
|
|
|
$full = filter_var( $full, FILTER_SANITIZE_NUMBER_INT ); |
|
56
|
|
|
$half = filter_var( $half, FILTER_SANITIZE_NUMBER_INT ); |
|
57
|
|
|
|
|
58
|
|
|
$string = $full . '.' . $half; |
|
59
|
|
|
} else { |
|
60
|
|
|
$string = filter_var( $string, FILTER_SANITIZE_NUMBER_INT ); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
// Filter. |
|
64
|
|
|
$value = filter_var( $string, FILTER_VALIDATE_FLOAT ); |
|
65
|
|
|
|
|
66
|
|
|
return new Money( $value ); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.