Skip to content

Commit

Permalink
Revue de code.
Browse files Browse the repository at this point in the history
  • Loading branch information
noelma committed Nov 28, 2018
1 parent c0a3b2d commit e116358
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class Request
'rightJoin' => [],
'setUpdate' => [],
'union' => [],
'unionAll' => [],
'values' => [],
];

Expand Down Expand Up @@ -155,33 +154,33 @@ public function __toString()
}
if ($this->table) {
$output .= "FROM $this->table ";
$output .= 'FROM ' . $this->table . ' ';
}
foreach ($this->request[ 'leftJoin' ] as $value) {
$output .= 'LEFT JOIN ' . $value[ 'table' ] . ' ON ';
$output .= "LEFT JOIN {$value[ 'table' ]} ON ";
}
if ($this->where) {
$output .= 'WHERE ';
}
foreach ($this->request[ 'union' ] as $union) {
$output .= $union['type'] === 'simple'
? 'UNION '
: 'UNION ALL';
$output .="({$union[ 'request' ]}) ";
}
if ($this->orderBy) {
foreach ($this->orderBy as $table => $order) {
$output .= 'ORDER BY ' . $table . ' ' . $order . ' ';
$output .= "ORDER BY $table $order ";
}
}
if ($this->limit) {
$output .= 'LIMIT ' . $this->limit . ' ';
}
if ($this->offset != 0) {
$output .= 'OFFSET ' . $this->offset . ' ';
}
foreach ($this->request[ 'union' ] as $union) {
$output .= 'UNION (' . $union[ 'request' ] . ')';
$output .= "LIMIT $this->limit ";
}
foreach ($this->request[ 'unionAll' ] as $union) {
$output .= 'UNION ALL (' . $union . ')';
if ($this->offset) {
$output .= "OFFSET $this->offset ";
}
$output = substr($output, 0, -1) . ';';

return $output;
return htmlspecialchars($output);
}

/**
Expand Down Expand Up @@ -532,7 +531,7 @@ public function fetchAll()
/* Le pointeur en cas de limite de résultat. */
$i = 0;

/*
/*
* Exécution des jointures.
* La réunion et l'intersection des ensembles sont soumis à la loi interne * et donc commutative.
*/
Expand All @@ -550,7 +549,6 @@ public function fetchAll()
if ($this->where && !$this->where->execute($row)) {
continue;
}
$rowEval = $row;

/* LIMITE */
if ($this->limit && !$limitHandel) {
Expand All @@ -564,14 +562,13 @@ public function fetchAll()

/* SELECT */
if ($this->lists !== null) {
$return[] = $rowEval[ $this->lists ];
$return[] = $row[ $this->lists ];
} elseif ($this->request[ 'columns' ]) {
$column = array_flip($this->request[ 'columns' ]);
$return[] = array_intersect_key($rowEval, $column);
$return[] = array_intersect_key($row, $column);
} else {
$return[] = $rowEval;
$return[] = $row;
}
unset($rowEval);
}

/* UNION */
Expand Down Expand Up @@ -980,7 +977,7 @@ private function loadAllColumnsSchema()
private function fetchPrepareFrom()
{
if ($this->table === '') {
throw new TableNotFoundException('La table est absente : ' . $this);
throw new TableNotFoundException("Table $this->table is missing.");
}
}

Expand Down

0 comments on commit e116358

Please sign in to comment.