Passed
Push — main ( a04c10...ce0e6f )
by Pranjal
01:52
created

QueryBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Scrawler\Arca;
4
5
class QueryBuilder extends \Doctrine\DBAL\Query\QueryBuilder
6
{
7
    private string $table;
8
    private Database $db;
9
10
    public function __construct(Database $db){
11
        $this->db = $db;
12
        parent::__construct($this->db->connection);
13
14
    }
15
16
    public function from($from, $alias = null) : QueryBuilder
17
    {
18
        $this->table = $from;
19
        return $this->add('from', [
20
            'table' => $from,
21
            'alias' => $alias,
22
        ], true);
23
    }
24
25
26
    public function get() : Collection
27
    {
28
        $table = $this->table;
29
        $query = $this->getSQL();
0 ignored issues
show
Unused Code introduced by
The assignment to $query is dead and can be removed.
Loading history...
30
        $model = $this->db->create($table);
31
        return Collection::fromIterable($this->fetchAllAssociative())
32
        ->map(static fn ($value): Model => ($model)->setProperties($value)->setLoaded());
33
    }
34
35
    public function first() : Model
36
    {
37
        $table = $this->table;
38
        $result = $this->fetchAssociative() ? $this->fetchAssociative() : [];
39
        return ($this->db->create($table))->setProperties($result)->setLoaded();
40
    }
41
}
42