From 233fcb228a7cb71c52de5563fe777c1a44e251c6 Mon Sep 17 00:00:00 2001 From: mehdi-fathi Date: Wed, 14 Aug 2024 23:45:53 +0330 Subject: [PATCH] Update:refactor the core code --- .../Core/FilterBuilder/MainQueryFilterBuilder.php | 12 ++++++++++-- src/QueryFilter/Core/ResolverDetections.php | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/QueryFilter/Core/FilterBuilder/MainQueryFilterBuilder.php b/src/QueryFilter/Core/FilterBuilder/MainQueryFilterBuilder.php index b9be66e..2900c3e 100644 --- a/src/QueryFilter/Core/FilterBuilder/MainQueryFilterBuilder.php +++ b/src/QueryFilter/Core/FilterBuilder/MainQueryFilterBuilder.php @@ -62,7 +62,7 @@ public function apply($builder, array $request = null, array $ignore_request = n /** * @return string */ - public function getNameDriver(): string + public function getNameBuilder(): string { $MainBuilderConditions = $this->queryFilterCore->getMainBuilderConditions(); @@ -88,7 +88,7 @@ private function checkEnableEloquentFilter(): bool */ private function buildQuery($builder, ?array $ignore_request, ?array $accept_request, ?array $detections_injected, ?array $black_list_detections): mixed { - if ($this->getNameDriver() == DBBuilderQueryByCondition::NAME) { + if ($this->isDbBuilder()) { return $this->buildDbQuery($builder, $ignore_request, $accept_request, $detections_injected, $black_list_detections); } @@ -148,4 +148,12 @@ private function buildEloquentQuery($builder, ?array $ignore_request, ?array $ac ); } + /** + * @return bool + */ + private function isDbBuilder(): bool + { + return $this->getNameBuilder() == DBBuilderQueryByCondition::NAME; + } + } diff --git a/src/QueryFilter/Core/ResolverDetections.php b/src/QueryFilter/Core/ResolverDetections.php index e991488..26975ad 100644 --- a/src/QueryFilter/Core/ResolverDetections.php +++ b/src/QueryFilter/Core/ResolverDetections.php @@ -87,7 +87,10 @@ private function resolve($filterName, $values, $model) */ private function getFiltersDetection(): array { - if (app('eloquentFilter')->getNameDriver() != DBBuilderQueryByCondition::NAME) { + /** @var MainQueryFilterBuilder $eloquentFilter */ + $eloquentFilter = app('eloquentFilter'); + + if ($eloquentFilter->getNameBuilder() != DBBuilderQueryByCondition::NAME) { $model = $this->builder->getModel(); } else { $model = $this->builder->from;