TimeDifference   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 14
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 18 4
A __construct() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Copyright Andrea Heigl <[email protected]>
7
 *
8
 * Licenses under the MIT-license. For details see the included file LICENSE.md
9
 */
10
11
namespace Org_Heigl\CaptainHook\Hooks\AddTime\Formatter;
12
13
14
use DateInterval;
15
use Org_Heigl\CaptainHook\Hooks\AddTime\Fuzzier\Exact;
16
use Org_Heigl\CaptainHook\Hooks\AddTime\Fuzzier\Fuzzier;
17
18
class TimeDifference
19
{
20
    private $fuzzier;
21
22
    public function __construct(Fuzzier $fuzzier = null)
23
    {
24
        if (null === $fuzzier) {
25
            $fuzzier = new Exact();
26
        }
27
        $this->fuzzier = $fuzzier;
28
    }
29
30
    public function format(DateInterval $interval)
31
    {
32
        $interval = $this->fuzzier->fuzzy($interval);
33
34
        $string = '';
35
        if ($interval->h > 0) {
36
            $string .= $interval->h . 'h';
37
        }
38
39
        if ($interval->i > 0) {
40
            $string .= $interval->i . 'm';
41
        }
42
43
        if ($interval->s > 0) {
44
            $string .= $interval->s . 's';
45
        }
46
47
        return $string;
48
    }
49
}