From 167a482163ae6e5e5692aa28a8edc378eb58ffae Mon Sep 17 00:00:00 2001 From: Matthew Baggett Date: Sun, 22 Jan 2023 20:35:08 +0100 Subject: [PATCH] php-cs-fixer --- src/Abstracts/AbstractModel.php | 9 +++--- src/Abstracts/AbstractTableGateway.php | 13 ++++++--- src/Finder.php | 38 +++++++++++++------------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/Abstracts/AbstractModel.php b/src/Abstracts/AbstractModel.php index 4e791df..10848a4 100644 --- a/src/Abstracts/AbstractModel.php +++ b/src/Abstracts/AbstractModel.php @@ -282,13 +282,12 @@ public function destroyThoroughly(): int return $this->destroyRecursively(); } - protected function getProtectedMethods(): array - { - return ['getPrimaryKeys', 'getProtectedMethods', 'getDIContainer']; - } - abstract public static function find(Finder $finder); abstract public static function findOne(Finder $finder); + protected function getProtectedMethods(): array + { + return ['getPrimaryKeys', 'getProtectedMethods', 'getDIContainer']; + } } diff --git a/src/Abstracts/AbstractTableGateway.php b/src/Abstracts/AbstractTableGateway.php index bade411..b83ea47 100644 --- a/src/Abstracts/AbstractTableGateway.php +++ b/src/Abstracts/AbstractTableGateway.php @@ -611,22 +611,27 @@ public function getByField($field, $value, $orderBy = null, $orderDirection = Se return $row; } - public function getByFinder(Finder $finder){ + public function getByFinder(Finder $finder) + { $select = $this->sql->select(); $select->where($finder); - if($finder->getOrder()) + if ($finder->getOrder()) { $select->order($finder->getOrder()); + } - if($finder->getLimit()) + if ($finder->getLimit()) { $select->limit($finder->getLimit()); + } - if($finder->getOffset()) + if ($finder->getOffset()) { $select->offset($finder->getOffset()); + } return $this->selectWith($select); } + /** * @param Where $where * @param null|int $limit diff --git a/src/Finder.php b/src/Finder.php index f2e3776..e05a822 100644 --- a/src/Finder.php +++ b/src/Finder.php @@ -1,8 +1,8 @@ offset; } - public function offset($offset) { $this->offset = $offset; + return $this; } @@ -39,44 +39,44 @@ public function getLimit() return $this->limit; } - public function limit($limit) { $this->limit = $limit; + return $this; } - public function getOrder() : ?string + public function getOrder(): ?string { - if($this->order) + if ($this->order) { return "{$this->order} {$this->orderDirection}"; - else - return null; - } + } + return null; + } - public function orderBy($order, $direction =null) + public function orderBy($order, $direction = null) { $this->order = $order; - if($direction) + if ($direction) { $this->orderDirection($direction); + } + return $this; } - /** * @param string $orderDirection + * * @return Finder */ public function orderDirection(string $orderDirection): Finder { - if(!in_array($orderDirection, ['desc','asc'])){ + if (!in_array($orderDirection, ['desc', 'asc'], true)) { throw new BenzineOrmException(sprintf("Order direction must be one of 'desc' or 'asc', given '%s'", $orderDirection)); } $this->orderDirection = $orderDirection; + return $this; } - - - -} \ No newline at end of file +}