RepositoryManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 37
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getRules() 0 11 4
1
<?php
2
3
namespace Konsulting\Laravel\RuleRepository;
4
5
use Illuminate\Support\Str;
6
use Konsulting\Laravel\RuleRepository\Contracts\RuleRepository;
7
use Konsulting\Laravel\RuleRepository\Exceptions\NonExistentStateException;
8
9
class RepositoryManager
10
{
11
    /**
12
     * The repository instance.
13
     *
14
     * @var RuleRepository
15
     */
16
    protected $repository;
17
18
    /**
19
     * Set the repository instance.
20
     *
21
     * @param RuleRepository $repository
22
     */
23 12
    public function __construct(RuleRepository $repository)
24
    {
25 12
        $this->repository = $repository;
26 12
    }
27
28
    /**
29
     * Return the rules for the given state. Get the default state if not specified.
30
     *
31
     * @param string $state
32
     * @return array
33
     * @throws NonExistentStateException
34
     */
35 15
    public function getRules($state = null)
36
    {
37 15
        $method = Str::camel($state ?: 'default');
38
39 15
        if ( ! method_exists($this->repository, $method)) {
40 1
            throw new NonExistentStateException($method);
41
        }
42
43 14
        return array_merge(
44 14
            $this->repository->default(),
45 14
            is_array($this->repository->$method()) ? $this->repository->$method() : []
46
        );
47
    }
48
}
49