Indexable::getConstraint()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 8
rs 10
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