Indexable   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 12
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConstraint() 0 8 2
1
<?php
2
/**
3
 * Created by enea dhack - 28/12/2019 15:07.
4
 */
5
6
namespace Vaened\Searcher;
7
8
use Illuminate\Support\Arr;
9
use InvalidArgumentException;
10
11
abstract class Indexable
12
{
13
    abstract protected function getAvailableConstraints(): ConstraintCollection;
14
15
    public function getConstraint(string $key, string $q): Constraint
16
    {
17
        $constraints = $this->getAvailableConstraints()->all();
18
        if (! Arr::has($constraints, $key)) {
19
            throw new InvalidArgumentException("The requested index was not found: {$key}");
20
        }
21
22
        return Arr::get($constraints, $key)($q);
23
    }
24
}
25