Passed
Push — develop ( 8ccef8...5801e1 )
by Francisco
06:48
created

EloquentExchangeRegistry::truncate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Judite\Registry;
4
5
use App\Judite\Models\Enrollment;
6
use App\Judite\Models\ExchangeRegistryEntry;
7
use App\Judite\Contracts\Registry\ExchangeRegistry;
8
9
class EloquentExchangeRegistry implements ExchangeRegistry
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function record(Enrollment $fromEnrollment, Enrollment $toEnrollment)
15
    {
16
        $logExchange = ExchangeRegistryEntry::make();
17
        $logExchange->fromShiftRelation()->associate($fromEnrollment->shift);
18
        $logExchange->toShiftRelation()->associate($toEnrollment->shift);
19
        $logExchange->fromStudentRelation()->associate($fromEnrollment->student);
20
        $logExchange->toStudentRelation()->associate($toEnrollment->student);
21
        $logExchange->save();
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function paginate()
28
    {
29
        return ExchangeRegistryEntry::latest('id')->paginate();
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function truncate()
36
    {
37
        ExchangeRegistryEntry::getQuery()->delete();
38
    }
39
}
40