Passed
Push — master ( 9d98a5...f0881b )
by Stephen
303:42 queued 288:28
created

Carbonate::yearsHence()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Sfneal\Helpers\Time;
4
5
use Carbon\Carbon;
6
use Sfneal\Actions\AbstractService;
7
8
class Carbonate extends AbstractService
9
{
10
    // todo: add year, month & week methods
11
12
    /**
13
     * Create a Carbon datetime objects $x days forward/backward in the past or future.
14
     *
15
     *  - a positive(+) integer $days value correlates to days FORWARD
16
     *  - a negative(-) integer $days value correlates to days BACKWARD
17
     *
18
     * @param int $days
19
     * @return Carbon
20
     */
21
    public static function days(int $days): Carbon
22
    {
23
        return ($days < 0) ? self::daysAgo(abs($days)) : self::daysHence($days);
0 ignored issues
show
Bug introduced by
It seems like abs($days) can also be of type double; however, parameter $days of Sfneal\Helpers\Time\Carbonate::daysAgo() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        return ($days < 0) ? self::daysAgo(/** @scrutinizer ignore-type */ abs($days)) : self::daysHence($days);
Loading history...
24
    }
25
26
    /**
27
     * Create a Carbon datetime objects $x months forward/backward in the past or future.
28
     *
29
     *  - a positive(+) integer $months value correlates to days FORWARD
30
     *  - a negative(-) integer $months value correlates to days BACKWARD
31
     *
32
     * @param int $months
33
     * @return Carbon
34
     */
35
    public static function months(int $months): Carbon
36
    {
37
        return ($months < 0) ? self::monthsAgo(abs($months)) : self::monthsHence($months);
0 ignored issues
show
Bug introduced by
It seems like abs($months) can also be of type double; however, parameter $months of Sfneal\Helpers\Time\Carbonate::monthsAgo() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        return ($months < 0) ? self::monthsAgo(/** @scrutinizer ignore-type */ abs($months)) : self::monthsHence($months);
Loading history...
38
    }
39
40
    /**
41
     * Create a Carbon datetime objects $x years forward/backward in the past or future.
42
     *
43
     *  - a positive(+) integer $years value correlates to days FORWARD
44
     *  - a negative(-) integer $years value correlates to days BACKWARD
45
     *
46
     * @param int $years
47
     * @return Carbon
48
     */
49
    public static function years(int $years): Carbon
50
    {
51
        return ($years < 0) ? self::yearsAgo(abs($years)) : self::yearsHence($years);
0 ignored issues
show
Bug introduced by
It seems like abs($years) can also be of type double; however, parameter $years of Sfneal\Helpers\Time\Carbonate::yearsAgo() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
        return ($years < 0) ? self::yearsAgo(/** @scrutinizer ignore-type */ abs($years)) : self::yearsHence($years);
Loading history...
52
    }
53
54
    /**
55
     * Create a Carbon datetime object representing $x days ago.
56
     *
57
     * @param int $days
58
     * @return Carbon
59
     */
60
    public static function daysAgo(int $days): Carbon
61
    {
62
        return Carbon::now()->subDays($days);
63
    }
64
65
    /**
66
     * Create a Carbon datetime object representing $x days from now.
67
     *
68
     * @param int $days
69
     * @return Carbon
70
     */
71
    public static function daysHence(int $days): Carbon
72
    {
73
        return Carbon::now()->addDays($days);
74
    }
75
76
    /**
77
     * Create a Carbon datetime object representing $x months ago.
78
     *
79
     * @param int $months
80
     * @return Carbon
81
     */
82
    public static function monthsAgo(int $months): Carbon
83
    {
84
        return Carbon::now()->subMonths($months);
85
    }
86
87
    /**
88
     * Create a Carbon datetime object representing $x months from now.
89
     *
90
     * @param int $months
91
     * @return Carbon
92
     */
93
    public static function monthsHence(int $months): Carbon
94
    {
95
        return Carbon::now()->addMonths($months);
96
    }
97
98
    /**
99
     * Create a Carbon datetime object representing $x days ago.
100
     *
101
     * @param int $years
102
     * @return Carbon
103
     */
104
    public static function yearsAgo(int $years): Carbon
105
    {
106
        return Carbon::now()->subYears($years);
107
    }
108
109
    /**
110
     * Create a Carbon datetime object representing $x days from now.
111
     *
112
     * @param int $years
113
     * @return Carbon
114
     */
115
    public static function yearsHence(int $years): Carbon
116
    {
117
        return Carbon::now()->addYears($years);
118
    }
119
}
120