Completed
Push — master ( ceee37...536973 )
by Enea
02:33
created

Wrap   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A bind() 0 4 2
A condition() 0 3 1
A apply() 0 3 1
1
<?php
2
/**
3
 * Created by enea dhack - 18/07/2020 21:32.
4
 */
5
6
namespace Vaened\Searcher\Constraints;
7
8
use Closure;
9
use Illuminate\Database\Eloquent\Builder;
10
use Vaened\Searcher\Constraint;
11
12
class Wrap implements Constraint
13
{
14
    private array $constraints;
15
16
    public function __construct(array $constraints)
17
    {
18
        $this->constraints = $constraints;
19
    }
20
21
    public function condition(Builder $builder): Builder
22
    {
23
        return $builder->where($this->apply($this->constraints));
24
    }
25
26
    private function apply(array $constraints): Closure
27
    {
28
        return fn(Builder $builder) => $this->bind($builder, $constraints);
29
    }
30
31
    private function bind(Builder $builder, array $constraints): void
32
    {
33
        foreach ($constraints as $constraint) {
34
            $constraint->condition($builder);
35
        }
36
    }
37
}
38