Completed
Push — development ( b626b0...ff940a )
by Thomas
16s
created

BlockService::fetchBy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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