Completed
Push — master ( 33476c...427ebd )
by Bertrand
09:14
created

PageRepositorySql::save()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
4
namespace App\Src\UseCases\Infra\Sql;
5
6
7
use App\Src\UseCases\Domain\Agricultural\Model\Page;
8
use App\Src\UseCases\Domain\Ports\PageRepository;
9
use App\Src\UseCases\Infra\Sql\Model\PageModel;
10
11
class PageRepositorySql implements PageRepository
12
{
13
    public function get(string $pageId): ?Page
14
    {
15
        $pageModel = PageModel::where('page_id', $pageId)->first();
16
        if(!isset($pageModel)){
17
            return null;
18
        }
19
        return new Page($pageModel->page_id, $pageModel->dry);
20
    }
21
22
    public function save(Page $page)
23
    {
24
        $pageModel = PageModel::where('page_id', $page->pageId())->first();
25
        if(!isset($pageModel)){
26
            $pageModel = new PageModel();
27
        }
28
        $pageModel->page_id = $page->pageId();
29
        $pageModel->fill($page->toArray());
30
        $pageModel->save();
31
    }
32
33
}
34