Issues (6)

src/QueryFactory.php (1 issue)

Labels
Severity
1
<?php
2
declare(strict_types=1);
3
4
namespace Latitude\QueryBuilder;
5
6
use Latitude\QueryBuilder\Ruler\Context;
0 ignored issues
show
The type Latitude\QueryBuilder\Ruler\Context was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class QueryFactory
9
{
10
    /** @var EngineInterface */
11
    protected $engine;
12
13 63
    public function __construct(
14
        EngineInterface $engine = null
15
    ) {
16 63
        $this->engine = $engine ?: new Engine\BasicEngine();
17 63
    }
18
19
    /**
20
     * Create a new SELECT query
21
     *
22
     * @param string|StatementInterface ...$columns
23
     */
24 33
    public function select(...$columns): Query\SelectQuery
25
    {
26 33
        $query = $this->engine->makeSelect();
27 33
        if (empty($columns) === false) {
28 13
            $query = $query->columns(...$columns);
29
        }
30 33
        return $query;
31
    }
32
33
    /**
34
     * Create a new SELECT DISTINCT query
35
     *
36
     * @param string|StatementInterface ...$columns
37
     */
38 1
    public function selectDistinct(...$columns): Query\SelectQuery
39
    {
40 1
        return $this->select(...$columns)->distinct();
41
    }
42
43
    /**
44
     * Create a new INSERT query
45
     *
46
     * @param string|StatementInterface $table
47
     */
48 4
    public function insert($table, array $map = []): Query\InsertQuery
49
    {
50 4
        $query = $this->engine->makeInsert()->into($table);
51 4
        if (empty($map) === false) {
52 2
            $query = $query->map($map);
53
        }
54 4
        return $query;
55
    }
56
57
    /**
58
     * Create a new DELETE query
59
     *
60
     * @param string|StatementInterface $table
61
     */
62 3
    public function delete($table): Query\DeleteQuery
63
    {
64 3
        return $this->engine->makeDelete()->from($table);
65
    }
66
67
    /**
68
     * Create a new UPDATE query
69
     *
70
     * @param string|StatementInterface $table
71
     */
72 4
    public function update($table, array $map = []): Query\UpdateQuery
73
    {
74 4
        $query = $this->engine->makeUpdate()->table($table);
75 4
        if (empty($map) === false) {
76 3
            $query = $query->set($map);
77
        }
78 4
        return $query;
79
    }
80
}
81