Completed
Pull Request — master (#27)
by
unknown
03:00
created

TimeSpeller   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 88%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 64
ccs 22
cts 25
cp 0.88
rs 10
wmc 11
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A spellUnit() 0 1 1
D spellInterval() 0 42 10
1
<?php
2
namespace morphos;
3
4
use DateInterval;
5
6
abstract class TimeSpeller
7
{
8
    const YEAR = 'year';
9
    const MONTH = 'month';
10
    const DAY = 'day';
11
    const HOUR = 'hour';
12
    const MINUTE = 'minute';
13
    const SECOND = 'second';
14
15
    const AGO = 'ago';
16
    const IN = 'in';
17
18
    const AND_WORD = 'and';
19
20
    const JUST_NOW = 'just now';
21
22
    const DIRECTION = 1;
23
    const SEPARATE = 2;
24
25
    public static function spellUnit($count, $unit) {}
26
27 16
    public static function spellInterval(DateInterval $interval, $options = 0, $limit = 0)
28
    {
29 16
        $parts = [];
30 16
        $k = 0;
31
        foreach ([
32 16
            'y' => self::YEAR,
33 16
            'm' => self::MONTH,
34 16
            'd' => self::DAY,
35 16
            'h' => self::HOUR,
36 16
            'i' => self::MINUTE,
37 16
            's' => self::SECOND
38
        ] as $interval_field => $unit) {
39 16
            if ($interval->{$interval_field} > 0) {
40 16
                if($limit > 0 && $k >= $limit) {
41
                    break;
42
                }
43 16
                $parts[] = static::spellUnit($interval->{$interval_field}, $unit);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $parts[] is correct as static::spellUnit($inter...interval_field}, $unit) (which targets morphos\TimeSpeller::spellUnit()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
44 16
                $k++;
45
            }
46
        }
47
48 16
        if (empty($parts)) {
49
            return static::JUST_NOW;
50
        }
51
52 16
        if ($options & self::SEPARATE && count($parts) > 1) {
53 6
            $last_part = array_pop($parts);
54 6
            $spelled = implode(', ', $parts).' '.static::AND_WORD.' '.$last_part;
55
        } else {
56 10
            $spelled = implode(' ', $parts);
57
        }
58
59 16
        if ($options & self::DIRECTION) {
60 4
            if ($interval->invert) {
61
                $spelled = static::IN.' '.$spelled;
62
            } else {
63 4
                $spelled .= ' '.static::AGO;
64
            }
65
        }
66
67 16
        return $spelled;
68
    }
69
}
70