MetricCurrency::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace LlewellynThomas\Coins\Currency;
4
5
/**
6
 * Class MetricCurrency
7
 * @package LlewellynThomas\Coins\Currency
8
 */
9
class MetricCurrency implements CurrencyInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    private $coins = [];
15
16
    /**
17
     * @var string
18
     */
19
    private $name;
20
21
    /**
22
     * MetricCurrency constructor.
23
     * @param string $name
24
     * @param array $coins
25
     */
26
    public function __construct($name, array $coins)
27
    {
28
        $this->name = $name;
29
        $this->coins = $coins;
30
    }
31
32
    /**
33
     * @param $amount
34
     * @return array
35
     */
36
    public function countCoins($amount)
37
    {
38
        $collection = [];
39
        \array_walk($this->coins, function($coin) use (&$amount, &$collection) {
40
               $collection[$coin] = (int)\floor($amount/$coin);
41
                $amount = $amount % $coin;
42
        });
43
44
        return \array_filter($collection);
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getName()
51
    {
52
        return $this->name;
53
    }
54
}