Code Duplication    Length = 24-24 lines in 2 locations

src/Traits/OpeningHoursScopes.php 2 locations

@@ 34-57 (lines=24) @@
31
     * @throws InvalidDayName
32
     * @throws InvalidTimeString
33
     */
34
    public function scopeOpen(Builder $query, $time = null, string $day = null)
35
    {
36
        $now = Carbon::now();
37
        if ($time == null) {
38
            $time = Time::fromDateTime($now);
39
        } else if (is_string($time)) {
40
            $time = Time::fromString($time);
41
        }
42
43
        if ($day == null) {
44
            $day = Day::onDateTime($now);
45
        } else {
46
            if (! Day::isValid($day)) {
47
                throw new InvalidDayName();
48
            }
49
        }
50
51
        return $query->whereHas($this->openingHoursRelationName, function(Builder $subquery) use ($day, $time) {
52
            $subquery
53
                ->where('day', $day)
54
                ->where('start', '<=', $time)
55
                ->where('end', '>=', $time);
56
        });
57
    }
58
59
    /**
60
     * Get only closed models.
@@ 71-94 (lines=24) @@
68
     * @throws InvalidDayName
69
     * @throws InvalidTimeString
70
     */
71
    public function scopeClosed(Builder $query, $time = null, string $day = null)
72
    {
73
        $now = Carbon::now();
74
        if ($time == null) {
75
            $time = Time::fromDateTime($now);
76
        } else if (is_string($time)) {
77
            $time = Time::fromString($time);
78
        }
79
80
        if ($day == null) {
81
            $day = Day::onDateTime($now);
82
        } else {
83
            if (! Day::isValid($day)) {
84
                throw new InvalidDayName();
85
            }
86
        }
87
88
        return $query->whereDoesntHave($this->openingHoursRelationName, function(Builder $subquery) use ($day, $time) {
89
            $subquery
90
                ->where('day', $day)
91
                ->where('start', '<=', $time)
92
                ->where('end', '>=', $time);
93
        });
94
    }
95
96
    /**
97
     * Get all models open at the specified day at random time