Completed
Push — master ( 87f113...1d200b )
by Milan
03:04
created

Filters   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 89
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setVat() 0 4 1
A change() 0 4 1
A changeTo() 0 4 1
A format() 0 5 1
A formatTo() 0 4 1
A vat() 0 4 1
A formatVat() 0 4 1
A formatVatTo() 0 4 1
1
<?php
2
3
namespace h4kuna\Exchange;
4
5
use h4kuna\Number;
6
7
class Filters
8
{
9
10
	/** @var Exchange */
11
	private $exchange;
12
13
	/** @var Currency\Formats */
14
	private $formats;
15
16
	/** @var Number\Tax */
17
	private $vat;
18
19
	public function __construct(Exchange $exchange, Currency\Formats $formats)
20
	{
21
		$this->exchange = $exchange;
22
		$this->formats = $formats;
23
	}
24
25
	/**
26
	 * @param Number\Tax $vat
27
	 */
28
	public function setVat(Number\Tax $vat)
29
	{
30
		$this->vat = $vat;
31
	}
32
33
	public function change($number, $from = NULL, $to = NULL)
34
	{
35
		return $this->exchange->change($number, $from, $to);
36
	}
37
38
	public function changeTo($number, $to = NULL)
39
	{
40
		return $this->change($number, NULL, $to);
41
	}
42
43
	/**
44
	 * Count and format number.
45
	 * @param number $number
46
	 * @param string|NULL
47
	 * @param string $to output currency, NULL set actual
48
	 * @return string
49
	 */
50
	public function format($number, $from = NULL, $to = NULL)
51
	{
52
		$data = $this->exchange->transfer($number, $from, $to);
53
		return $this->formats->getFormat($data[1]->code)->format($data[0], $data[1]->code);
0 ignored issues
show
Unused Code introduced by
The call to UnitPersistentFormatState::format() has too many arguments starting with $data[1]->code.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
54
	}
55
56
	/**
57
	 * @param float $number
58
	 * @param string $to
59
	 * @return string
60
	 */
61
	public function formatTo($number, $to)
62
	{
63
		return $this->format($number, NULL, $to);
64
	}
65
66
	/**
67
	 * @param float|int $number
68
	 * @return float
69
	 */
70
	public function vat($number)
71
	{
72
		return $this->vat->add($number);
73
	}
74
75
	/**
76
	 * @param float|int $number
77
	 * @param string|NULL $from
78
	 * @param string|NULL $to
79
	 * @return string
80
	 */
81
	public function formatVat($number, $from = NULL, $to = NULL)
82
	{
83
		return $this->format($this->vat($number), $from, $to);
84
	}
85
86
	/**
87
	 * @param float|int $number
88
	 * @param string|NULL $to
89
	 * @return string
90
	 */
91
	public function formatVatTo($number, $to)
92
	{
93
		return $this->formatVat($number, NULL, $to);
94
	}
95
}