CountryService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 74
ccs 15
cts 15
cp 1
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createCountry() 0 5 1
A deleteCountry() 0 3 1
A __construct() 0 4 1
A getById() 0 3 1
A getCountries() 0 3 1
A updateCountry() 0 5 1
1
<?php
2
3
namespace App\Services;
4
5
use App\Http\Requests\CountryStoreRequest;
6
use App\Models\Country;
7
use App\Repositories\CountryRepository;
8
use Illuminate\Support\Collection;
9
10
class CountryService
11
{
12
    private CountryRepository $countryRepository;
13
14
    /**
15
     * CountryService constructor.
16
     *
17
     * @param \App\Repositories\CountryRepository $countryRepository
18
     */
19 5
    public function __construct(
20
        CountryRepository $countryRepository
21
    ) {
22 5
        $this->countryRepository = $countryRepository;
23 5
    }
24
25
    /**
26
     * Create a country
27
     *
28
     * @param \App\Http\Requests\CountryStoreRequest $request
29
     *
30
     * @return \App\Models\Country
31
     */
32 1
    public function createCountry(CountryStoreRequest $request): Country
33
    {
34 1
        $country = $this->countryRepository->store($request->all());
35
36 1
        return $country;
37
    }
38
39
    /**
40
     * Update the country
41
     *
42
     * @param \App\Http\Requests\CountryStoreRequest $request
43
     * @param int $countryId
44
     *
45
     * @return \App\Models\Country
46
     */
47 1
    public function updateCountry(CountryStoreRequest $request, int $countryId): Country
48
    {
49 1
        $country = $this->countryRepository->update($request->all(), $countryId);
50
51 1
        return $country;
52
    }
53
54
    /**
55
     * Return the country from the database
56
     *
57
     * @param int $countryId
58
     *
59
     * @return \App\Models\Country
60
     */
61 1
    public function getById(int $countryId): Country
62
    {
63 1
        return $this->countryRepository->getById($countryId);
64
    }
65
66
    /**
67
     * Get all the countries
68
     *
69
     * @return \Illuminate\Support\Collection
70
     */
71 1
    public function getCountries(): Collection
72
    {
73 1
        return $this->countryRepository->getAll();
74
    }
75
76
    /**
77
     * Delete the country from the database
78
     *
79
     * @param int $countryId
80
     */
81 1
    public function deleteCountry(int $countryId): void
82
    {
83 1
        $this->countryRepository->delete($countryId);
84 1
    }
85
}
86