Test Setup Failed
Push — master ( 6863da...811519 )
by guillaume
27:05 queued 21:33
created

InvitationRepositorySql::getByHash()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 10
rs 10
c 1
b 0
f 0
1
<?php
2
3
4
namespace App\Src\UseCases\Infra\Sql;
5
6
7
use App\Src\UseCases\Domain\Invitation;
8
use App\Src\UseCases\Domain\Ports\InvitationRepository;
9
use Illuminate\Support\Facades\DB;
10
11
class InvitationRepositorySql implements InvitationRepository
12
{
13
    public function add(Invitation $i)
14
    {
15
        list($organizationId, $email, $firstname, $lastname) = $i->data();
16
        DB::table('invitations')->insert([
17
            'organization_id' => $organizationId,
18
            'email' => $email,
19
            'firstname' => $firstname,
20
            'lastname' => $lastname,
21
            'send_at' => (new \DateTime())->format('Y-m-d H:i:s'),
22
            'hash' => $i->hash()
23
        ]);
24
    }
25
26
    public function getByHash(string $hash): ?Invitation
27
    {
28
        $record = DB::table('invitations')
29
            ->select()
30
            ->where('hash', $hash)
31
            ->first();
32
        if(!isset($record)){
33
            return null;
34
        }
35
        return new Invitation($record->organization_id, $record->email, $record->firstname, $record->lastname);
36
    }
37
}
38