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

CountryService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fetchAll() 0 10 2
A create() 0 4 1
A update() 0 4 1
A remove() 0 4 1
1
<?php
2
3
namespace Oc\Country;
4
5
use Oc\Repository\Exception\RecordNotFoundException;
6
use Oc\Repository\Exception\RecordsNotFoundException;
7
8
/**
9
 * Class CountryService
10
 *
11
 * @package Oc\Country
12
 */
13
class CountryService
14
{
15
    /**
16
     * @var CountryRepository
17
     */
18
    private $countryRepository;
19
20
    /**
21
     * CountryService constructor.
22
     *
23
     * @param CountryRepository $countryRepository
24
     */
25
    public function __construct(CountryRepository $countryRepository)
26
    {
27
        $this->countryRepository = $countryRepository;
28
    }
29
30
    /**
31
     * Fetches all countries.
32
     *
33
     * @return CountryEntity[]
34
     */
35
    public function fetchAll()
36
    {
37
        try {
38
            $result = $this->countryRepository->fetchAll();
39
        } catch (RecordsNotFoundException $e) {
40
            $result = [];
41
        }
42
43
        return $result;
44
    }
45
46
    /**
47
     * Creates a country in the database.
48
     *
49
     * @param CountryEntity $entity
50
     *
51
     * @return CountryEntity
52
     */
53
    public function create(CountryEntity $entity)
54
    {
55
        return $this->countryRepository->create($entity);
56
    }
57
58
    /**
59
     * Update a country in the database.
60
     *
61
     * @param CountryEntity $entity
62
     *
63
     * @return CountryEntity
64
     */
65
    public function update(CountryEntity $entity)
66
    {
67
        return $this->countryRepository->update($entity);
68
    }
69
70
    /**
71
     * Removes a country from the database.
72
     *
73
     * @param CountryEntity $entity
74
     *
75
     * @return CountryEntity
76
     */
77
    public function remove(CountryEntity $entity)
78
    {
79
        return $this->countryRepository->remove($entity);
80
    }
81
}
82