mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-13 07:18:39 +00:00
Reduce complexity
This commit is contained in:
parent
7413b65375
commit
b57bbcfdc7
|
|
@ -114,27 +114,10 @@ class Grammar extends GrammarAbstract
|
|||
protected function compileComponents(BuilderAbstract $query) : array
|
||||
{
|
||||
$sql = [];
|
||||
$components = $this->getComponents($query->getType());
|
||||
|
||||
switch ($query->getType()) {
|
||||
case QueryType::SELECT:
|
||||
$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.');
|
||||
if($query->getType() === QueryType::RAW) {
|
||||
return $components;
|
||||
}
|
||||
|
||||
/* Loop all possible query components and if they exist compile them. */
|
||||
|
|
@ -147,6 +130,26 @@ class Grammar extends GrammarAbstract
|
|||
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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user