Completed
Push — master ( 6a872b...95bb87 )
by f
01:14
created

src/TimeSpeller.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
    public static function spellInterval(DateInterval $interval, $options = 0)
28
    {
29
        $parts = [];
30
        foreach ([
31
            'y' => self::YEAR,
32
            'm' => self::MONTH,
33
            'd' => self::DAY,
34
            'h' => self::HOUR,
35
            'i' => self::MINUTE,
36
            's' => self::SECOND
37
        ] as $interval_field => $unit) {
38
            if ($interval->{$interval_field} > 0) {
39
                $parts[] = static::spellUnit($interval->{$interval_field}, $unit);
0 ignored issues
show
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...
40
            }
41
        }
42
43
        if (empty($parts)) {
44
            return static::JUST_NOW;
45
        }
46
47
        if ($options & self::SEPARATE && count($parts) > 1) {
48
            $last_part = array_pop($parts);
49
            $spelled = implode(', ', $parts).' '.static::AND_WORD.' '.$last_part;
50
        } else {
51
            $spelled = implode(' ', $parts);
52
        }
53
54
        if ($options & self::DIRECTION) {
55
            if ($interval->invert) {
56
                $spelled = static::IN.' '.$spelled;
57
            } else {
58
                $spelled .= ' '.static::AGO;
59
            }
60
        }
61
62
        return $spelled;
63
    }
64
}
65