for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace BfwSql\Queries\Parts;
class Order
{
/**
* @var string $expr The expression to use into the order
*/
protected $expr;
* @var string|null $sort The sort order : ASC or DESC
protected $sort;
* Define the expression and the order to sort
*
* @param string $expr The expression to use into the order
* @param string|null $sort The sort order : ASC or DESC
public function __construct(string $expr, $sort = 'ASC')
$this->expr = $expr;
$this->sort = $sort;
}
* Getter accessor to property expr
* @return string
public function getExpr(): string
return $this->expr;
* @return string|null
public function getSort()
return $this->sort;
* Generate the sql query for to this order expression
public function generate(): string
$expr = $this->expr;
if (
strpos($expr, ' ') === false &&
strpos($expr, '(') === false
) {
$expr = '`'.$expr.'`';
if ($this->sort === null) {
return $expr;
return $expr.' '.$this->sort;