Completed
Pull Request — development (#546)
by Nick
06:21
created

PageService::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Oc\Page;
4
5
use Oc\Repository\Exception\RecordNotFoundException;
6
7
/**
8
 * Class PageService
9
 *
10
 * @package Oc\Page
11
 */
12
class PageService
13
{
14
    /**
15
     * @var PageRepository
16
     */
17
    private $pageRepository;
18
19
    /**
20
     * PageService constructor.
21
     *
22
     * @param PageRepository $pageRepository
23
     */
24
    public function __construct(PageRepository $pageRepository)
25
    {
26
        $this->pageRepository = $pageRepository;
27
    }
28
29
    /**
30
     * Fetches a page by slug.
31
     *
32
     * @param array $where
33
     *
34
     * @return null|PageEntity
35
     */
36
    public function fetchOneBy(array $where = [])
37
    {
38
        try {
39
            $result = $this->pageRepository->fetchOneBy($where);
40
        } catch (RecordNotFoundException $e) {
41
            $result = null;
42
        }
43
44
        return $result;
45
    }
46
47
    /**
48
     * Creates a page in the database.
49
     *
50
     * @param PageEntity $entity
51
     *
52
     * @return PageEntity
53
     */
54
    public function create(PageEntity $entity)
55
    {
56
        return $this->pageRepository->create($entity);
57
    }
58
59
    /**
60
     * Update a page in the database.
61
     *
62
     * @param PageEntity $entity
63
     *
64
     * @return PageEntity
65
     */
66
    public function update(PageEntity $entity)
67
    {
68
        return $this->pageRepository->update($entity);
69
    }
70
71
    /**
72
     * Removes a page from the database.
73
     *
74
     * @param PageEntity $entity
75
     *
76
     * @return PageEntity
77
     */
78
    public function remove(PageEntity $entity)
79
    {
80
        return $this->pageRepository->remove($entity);
81
    }
82
}
83