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

DatesHelper   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 14
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A daysAgo() 0 6 1
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