Passed
Push — master ( 1ecb60...18a205 )
by Dante
01:51
created

DatesHelper::daysAgo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace App\View\Helper;
5
6
use Cake\View\Helper;
7
use DateTime;
8
9
/**
10
 * Dates helper
11
 */
12
class DatesHelper extends Helper
13
{
14
    /**
15
     * Get the number of days between the current date and the given date.
16
     *
17
     * @param string $then The date to compare with the current date.
18
     * @return int The number of days between the two dates.
19
     */
20
    public function daysAgo(string $then): int
21
    {
22
        $now = new DateTime();
23
        $diff = $now->diff(new DateTime($then));
24
25
        return $diff->days;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $diff->days could return the type boolean which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
26
    }
27
}
28