Reduce complexity

This commit is contained in:
Dennis Eichhorn 2017-11-11 13:23:07 +01:00
parent 7413b65375
commit b57bbcfdc7

View File

@ -114,27 +114,10 @@ class Grammar extends GrammarAbstract
protected function compileComponents(BuilderAbstract $query) : array protected function compileComponents(BuilderAbstract $query) : array
{ {
$sql = []; $sql = [];
$components = $this->getComponents($query->getType());
switch ($query->getType()) { if($query->getType() === QueryType::RAW) {
case QueryType::SELECT: return $components;
$components = $this->selectComponents;
break;
case QueryType::INSERT:
$components = $this->insertComponents;
break;
case QueryType::UPDATE:
$components = $this->updateComponents;
break;
case QueryType::DELETE:
$components = $this->deleteComponents;
break;
case QueryType::RANDOM:
$components = $this->selectComponents;
break;
case QueryType::RAW:
return [$query->raw];
default:
throw new \InvalidArgumentException('Unknown query type.');
} }
/* Loop all possible query components and if they exist compile them. */ /* Loop all possible query components and if they exist compile them. */
@ -147,6 +130,26 @@ class Grammar extends GrammarAbstract
return $sql; return $sql;
} }
private function getComponents(int $type) : array
{
switch ($type) {
case QueryType::SELECT:
return $components = $this->selectComponents;
case QueryType::INSERT:
return $components = $this->insertComponents;
case QueryType::UPDATE:
return $components = $this->updateComponents;
case QueryType::DELETE:
return $components = $this->deleteComponents;
case QueryType::RANDOM:
return $components = $this->selectComponents;
case QueryType::RAW:
return [$query->raw];
default:
throw new \InvalidArgumentException('Unknown query type.');
}
}
/** /**
* Compile select. * Compile select.
* *