SimpleFormatter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 22
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 4 1
A formatQuantity() 0 6 1
1
<?php
2
3
namespace hiqdev\php\units\formatters;
4
5
use hiqdev\php\units\FormatterInterface;
6
use hiqdev\php\units\Quantity;
7
8
/**
9
 * Class SimpleFormatter
10
 *
11
 * @author Dmytro Naumenko <[email protected]>
12
 */
13
class SimpleFormatter implements FormatterInterface
14
{
15
    /**
16
     * @param Quantity $quantity
17
     * @return string
18
     */
19
    public function format(Quantity $quantity): string
20
    {
21
        return $this->formatQuantity($quantity) . ' ' . $quantity->getUnit()->getName();
22
    }
23
24
    /**
25
     * @param Quantity $quantity
26
     * @return string
27 5
     */
28
    private function formatQuantity(Quantity $quantity): string
29 5
    {
30
        $value = (float)$quantity->getQuantity();
31
32
        return rtrim(rtrim(number_format($value, 6, '.', ' '), '0'), '.');
33
    }
34
}
35