for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types = 1);
namespace Puzzle\QueryBuilder\Queries\Snippets;
use Puzzle\QueryBuilder\Snippet;
use Puzzle\QueryBuilder\Condition;
use Puzzle\QueryBuilder\Traits\EscaperAware;
class Where implements Snippet
{
use EscaperAware;
private
$conditions;
$conditions
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
class A { var $property; }
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.
public function __construct(Condition $condition = null)
$this->conditions = array();
if($condition instanceof Condition)
$this->addCondition($condition);
}
public function where(Condition $condition): self
return $this;
public function toString(): string
$conditionString = $this->buildConditionString();
if(empty($conditionString))
return '';
return sprintf('WHERE %s', $conditionString);
private function buildConditionString(): string
$whereConditions = array();
foreach($this->conditions as $condition)
$conditionString = $condition->toString($this->escaper);
if(! empty($conditionString))
$whereConditions[] = $conditionString;
return implode(' AND ', $whereConditions);
private function addCondition(Condition $condition): void
$this->conditions[] = $condition;
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.