Test Failed
Push — main ( 92d586...908f29 )
by Davide
12:57
created

RegionService::getById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Services;
4
5
use App\Http\Requests\RegionStoreRequest;
6
use App\Models\Region;
7
use App\Repositories\RegionRepository;
8
use Illuminate\Support\Collection;
9
10
class RegionService
11
{
12
    private RegionRepository $regionRepository;
13
14
    /**
15
     * RegionService constructor.
16
     *
17
     * @param \App\Repositories\RegionRepository $regionRepository
18
     */
19
    public function __construct(
20
        RegionRepository $regionRepository
21
    ) {
22
        $this->regionRepository = $regionRepository;
23
    }
24
25
    /**
26
     * Create a region
27
     *
28
     * @param \App\Http\Requests\RegionStoreRequest $request
29
     *
30
     * @return \App\Models\Region
31
     */
32
    public function createRegion(RegionStoreRequest $request): Region
33
    {
34
        $region = $this->regionRepository->store($request->all());
35
36
        return $region;
37
    }
38
39
    /**
40
     * Update the region
41
     *
42
     * @param \App\Http\Requests\RegionStoreRequest $request
43
     * @param int $regionId
44
     *
45
     * @return \App\Models\Region
46
     */
47
    public function updateRegion(RegionStoreRequest $request, int $regionId): Region
48
    {
49
        $region = $this->regionRepository->update($request->all(), $regionId);
50
51
        return $region;
52
    }
53
54
    /**
55
     * Return the region from the database
56
     *
57
     * @param int $regionId
58
     *
59
     * @return \App\Models\Region
60
     */
61
    public function getById(int $regionId): Region
62
    {
63
        return $this->regionRepository->getById($regionId);
64
    }
65
66
    /**
67
     * Get all the regions
68
     *
69
     * @return \Illuminate\Support\Collection
70
     */
71
    public function getRegions(): Collection
72
    {
73
        return $this->regionRepository->getAll();
74
    }
75
76
    /**
77
     * Delete the region from the database
78
     *
79
     * @param int $regionId
80
     */
81
    public function deleteRegion(int $regionId): void
82
    {
83
        $this->regionRepository->delete($regionId);
84
    }
85
}
86