| Total Complexity | 10 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 12 | abstract class Queryable |
||
| 13 | { |
||
| 14 | private ?Query $query = null; |
||
| 15 | |||
| 16 | abstract protected function builder(): Builder; |
||
| 17 | |||
| 18 | protected function apply(Constraint $constraint): void |
||
| 19 | { |
||
| 20 | $this->getQuery()->push($constraint); |
||
| 21 | } |
||
| 22 | |||
| 23 | protected function removeNamedBinding(string $name): void |
||
| 24 | { |
||
| 25 | $this->getQuery()->attach(fn(Builder $builder) => $builder->withoutGlobalScope($name)); |
||
| 26 | } |
||
| 27 | |||
| 28 | protected function getQuery(): Query |
||
| 31 | } |
||
| 32 | |||
| 33 | private function createQueryBuilder(): Query |
||
| 34 | { |
||
| 35 | $bindings = $this->getBootableTraitsBindings(); |
||
| 36 | return new Query($this->builder(), $bindings->merge($this->defaultBindings())->toArray()); |
||
|
|
|||
| 37 | } |
||
| 38 | |||
| 39 | private function getBootableTraitsBindings(): Collection |
||
| 40 | { |
||
| 41 | $methods = $this->filterBootableTraits(static::class, fn(string $name) => "get{$name}DefaultBindings"); |
||
| 42 | return collect($methods)->map(fn(string $method): array => call_user_func([$this, $method]))->flatten(); |
||
| 43 | } |
||
| 44 | |||
| 45 | private function filterBootableTraits(string $class, Closure $buildFunctionName): array |
||
| 57 | } |
||
| 58 | |||
| 59 | protected function defaultBindings(): array |
||
| 62 | } |
||
| 63 | } |
||
| 64 |