DatesEligibilityChecker::isEligible()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.4222
c 0
b 0
f 0
cc 5
nc 3
nop 1
crap 5
1
<?php
2
3
/*
4
 * This file is part of ibrand/discount.
5
 *
6
 * (c) iBrand <https://www.ibrand.cc>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace iBrand\Component\Discount\Checkers;
13
14
use Carbon\Carbon;
15
use iBrand\Component\Discount\Contracts\DiscountContract;
16
17
class DatesEligibilityChecker
18
{
19
    /**
20
     * @param DiscountContract $discount
21
     *
22
     * @return bool
23
     */
24 6
    public function isEligible(DiscountContract $discount)
25
    {
26 6
        $now = Carbon::now();
27
28 6
        $startsAt = $discount->getStartsAt();
29 6
        if (null !== $startsAt && $now < $startsAt) {
30 2
            return false;
31
        }
32
33 6
        $endsAt = $discount->getEndsAt();
34 6
        if (null !== $endsAt && $now > $endsAt) {
35 3
            return false;
36
        }
37
38 6
        return true;
39
    }
40
}
41