Passed
Pull Request — main (#65)
by Thierry
10:34
created

SessionSyncTrait::getPrevSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Siak\Tontine\Service\Planning;
4
5
use Siak\Tontine\Model\Round;
6
use Siak\Tontine\Model\Session;
7
8
trait SessionSyncTrait
9
{
10
    /**
11
     * Find the prev session.
12
     *
13
     * @param Round $round
14
     * @param Session $session
15
     *
16
     * @return Session|null
17
     */
18
    private function getPrevSession(Round $round, Session $session): ?Session
19
    {
20
        return $round->sessions()
21
            ->where('day_date', '<', $session->day_date)
22
            ->orderBy('day_date', 'desc')
23
            ->first();
24
    }
25
26
    /**
27
     * Find the next session.
28
     *
29
     * @param Round $round
30
     * @param Session $session
31
     *
32
     * @return Session|null
33
     */
34
    private function getNextSession(Round $round, Session $session): ?Session
35
    {
36
        return $round->sessions()
37
            ->where('day_date', '>', $session->day_date)
38
            ->orderBy('day_date', 'asc')
39
            ->first();
40
    }
41
}
42