Issues (9)

src/View/Helper/DatesHelper.php (1 issue)

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