Skip to content

Commit

Permalink
php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewbaggett committed Jan 22, 2023
1 parent f7d2431 commit 167a482
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
9 changes: 4 additions & 5 deletions src/Abstracts/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
13 changes: 9 additions & 4 deletions src/Abstracts/AbstractTableGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions src/Finder.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Benzine\ORM;

use Benzine\ORM\Exception\BenzineOrmException;
use Laminas\Db\Sql\Predicate\PredicateSet;

class Finder extends \Laminas\Db\Sql\Where
{
Expand All @@ -13,24 +13,24 @@ public function __construct(
private ?int $limit = null,
private ?string $order = null,
private string $orderDirection = 'ASC',
){
) {
parent::__construct($predicates, $defaultCombination);
}

public static function Where(){
public static function Where()
{
return new self();
}


public function getOffset()
{
return $this->offset;
}


public function offset($offset)
{
$this->offset = $offset;

return $this;
}

Expand All @@ -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;
}



}
}

0 comments on commit 167a482

Please sign in to comment.