Completed
Push — master ( 656ae7...a2f7b9 )
by Oscar
02:13
created

SelectAll::orderBy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace SimpleCrud\Queries\Mysql;
4
5
use SimpleCrud\Queries\BaseQuery;
6
use SimpleCrud\Queries\SelectTrait;
7
use SimpleCrud\RowCollection;
8
use SimpleCrud\Entity;
9
10
/**
11
 * Manages a database select query.
12
 */
13
class SelectAll extends BaseQuery
14
{
15
    use SelectTrait;
16
17
    /**
18
     * Run the query and return all values.
19
     *
20
     * @param bool $idAsKey
21
     *
22
     * @return RowCollection
23
     */
24
    public function get($idAsKey = true)
25
    {
26
        $statement = $this->run();
27
        $result = $this->entity->createCollection();
28
29
        $result->idAsKey($idAsKey);
30
31
        while (($row = $statement->fetch())) {
32
            $result[] = $this->entity->create($this->entity->prepareDataFromDatabase($row));
33
        }
34
35
        return $result;
36
    }
37
}
38