diff --git a/mailpoet/lib/Listing/Handler.php b/mailpoet/lib/Listing/Handler.php index 17c63ac94d..a39b385458 100644 --- a/mailpoet/lib/Listing/Handler.php +++ b/mailpoet/lib/Listing/Handler.php @@ -2,75 +2,7 @@ namespace MailPoet\Listing; -use MailPoetVendor\Paris\Model; -use MailPoetVendor\Paris\ORMWrapper; - class Handler { - const DEFAULT_LIMIT_PER_PAGE = 20; - - public function get($modelClass, array $data) { - $data = $this->processData($data); - $tableName = $modelClass::$_table; - $model = Model::factory($modelClass); - // get groups - $groups = []; - $groupsCallback = [$modelClass, 'groups']; - if (method_exists($modelClass, 'groups') && is_callable($groupsCallback)) { - $groups = call_user_func_array( - $groupsCallback, - [$data] - ); - } - - // get filters - $filters = []; - $filtersCallback = [$modelClass, 'filters']; - if (method_exists($modelClass, 'filters') && is_callable($filtersCallback)) { - $filters = call_user_func_array( - $filtersCallback, - [$data] - ); - } - - // get items and total count - $listingCallback = [$modelClass, 'listingQuery']; - if (method_exists($modelClass, 'listingQuery') && is_callable($listingCallback)) { - $customQuery = call_user_func_array( - $listingCallback, - [$data] - ); - - $count = $customQuery->count(); - - $items = $customQuery - ->offset($data['offset']) - ->limit($data['limit']) - ->{'order_by_' . $data['sort_order']}( - $tableName . '.' . $data['sort_by'] - ) - ->findMany(); - } else { - $model = $this->setFilter($model, $data); - $this->setGroup($model, $data); - $this->setSearch($model, $data); - $this->setOrder($model, $data, $tableName); - - $count = $model->count(); - - $items = $model - ->offset($data['offset']) - ->limit($data['limit']) - ->findMany(); - } - - return [ - 'count' => $count, - 'filters' => $filters, - 'groups' => $groups, - 'items' => $items, - ]; - } - public function getListingDefinition(array $data): ListingDefinition { $data = $this->processData($data); return new ListingDefinition( @@ -86,33 +18,6 @@ class Handler { ); } - private function setSearch(ORMWrapper $model, array $data) { - if (empty($data['search'])) { - return; - } - return $model->filter('search', $data['search']); - } - - private function setOrder(ORMWrapper $model, array $data, $tableName) { - return $model - ->{'order_by_' . $data['sort_order']}( - $tableName . '.' . $data['sort_by']); - } - - private function setGroup(ORMWrapper $model, array $data) { - if ($data['group'] === null) { - return; - } - $model->filter('groupBy', $data['group']); - } - - private function setFilter(ORMWrapper $model, array $data) { - if ($data['filter'] === null) { - return $model; - } - return $model->filter('filterBy', $data['filter']); - } - /** * Polyfill for deprecated FILTER_SANITIZE_STRING which was used to sanitize * $data['sort_by']. diff --git a/mailpoet/tasks/phpstan/phpstan-7-baseline.neon b/mailpoet/tasks/phpstan/phpstan-7-baseline.neon index ab98ab7159..4a867404b5 100644 --- a/mailpoet/tasks/phpstan/phpstan-7-baseline.neon +++ b/mailpoet/tasks/phpstan/phpstan-7-baseline.neon @@ -630,16 +630,6 @@ parameters: count: 1 path: ../../lib/Form/Renderer.php - - - message: "#^Cannot call method count\\(\\) on mixed\\.$#" - count: 1 - path: ../../lib/Listing/Handler.php - - - - message: "#^Cannot call method offset\\(\\) on mixed\\.$#" - count: 1 - path: ../../lib/Listing/Handler.php - - message: "#^Cannot cast mixed to int\\.$#" count: 1 diff --git a/mailpoet/tasks/phpstan/phpstan-8-baseline.neon b/mailpoet/tasks/phpstan/phpstan-8-baseline.neon index 5c92fbfca6..17490ed8b4 100644 --- a/mailpoet/tasks/phpstan/phpstan-8-baseline.neon +++ b/mailpoet/tasks/phpstan/phpstan-8-baseline.neon @@ -630,16 +630,6 @@ parameters: count: 1 path: ../../lib/Form/Renderer.php - - - message: "#^Cannot call method count\\(\\) on mixed\\.$#" - count: 1 - path: ../../lib/Listing/Handler.php - - - - message: "#^Cannot call method offset\\(\\) on mixed\\.$#" - count: 1 - path: ../../lib/Listing/Handler.php - - message: "#^Cannot cast mixed to int\\.$#" count: 1 diff --git a/mailpoet/tasks/phpstan/phpstan-8.1-baseline.neon b/mailpoet/tasks/phpstan/phpstan-8.1-baseline.neon index 9bbfafff14..829bb65fde 100644 --- a/mailpoet/tasks/phpstan/phpstan-8.1-baseline.neon +++ b/mailpoet/tasks/phpstan/phpstan-8.1-baseline.neon @@ -630,16 +630,6 @@ parameters: count: 1 path: ../../lib/Form/Renderer.php - - - message: "#^Cannot call method count\\(\\) on mixed\\.$#" - count: 1 - path: ../../lib/Listing/Handler.php - - - - message: "#^Cannot call method offset\\(\\) on mixed\\.$#" - count: 1 - path: ../../lib/Listing/Handler.php - - message: "#^Cannot cast mixed to int\\.$#" count: 1