Completed
Push — master ( 5a99d5...4a640b )
by Jeff
14:01
created

RoleRepository::__construct()   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
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace App\Shop\Roles\Repositories;
3
use App\Shop\Base\BaseRepository;
4
use App\Shop\Roles\Exceptions\CreateRoleErrorException;
5
use App\Shop\Roles\Role;
6
use Illuminate\Database\QueryException;
7
use Illuminate\Support\Collection;
8
class RoleRepository extends BaseRepository implements RoleRepositoryInterface
9
{
10
    /**
11
     * @var Role
12
     */
13
    protected $model;
14
    /**
15
     * RoleRepository constructor.
16
     * @param Role $role
17
     */
18
    public function __construct(Role $role)
19
    {
20
        parent::__construct($role);
21
        $this->model = $role;
22
    }
23
    /**
24
     * List all Roles
25
     *
26
     * @param string $order
27
     * @param string $sort
28
     * @return Collection
29
     */
30
     public function listRoles(string $order = 'id', string $sort = 'desc') : Collection
31
     {
32
          return $this->all(['*'], $order, $sort);
33
     }
34
    /**
35
     * @param array $data
36
     * @return Role
37
     * @throws CreateRoleErrorException
38
     */
39
    public function createRole(array $data) : Role
40
    {
41
        try {
42
            $role = new Role($data);
43
            $role->save();
44
            return $role;
45
        } catch (QueryException $e) {
46
            throw new CreateRoleErrorException($e);
47
        }
48
    }
49
}
50