Issues (12)

src/QueryFactory.php (2 issues)

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
use Latitude\QueryBuilder\Ruler\Visitor;
8
9
class QueryFactory
10
{
11
    /** @var EngineInterface */
12
    protected $engine;
13
14
    /** @var Visitor */
15
    protected $visitor;
16
17 70
    public function __construct(
18
        EngineInterface $engine = null
19
    ) {
20 70
        $this->engine = $engine ?: new Engine\BasicEngine();
21 70
    }
22
23
    /**
24
     * Create a new SELECT query
25
     *
26
     * @param string|StatementInterface ...$columns
27
     */
28 32
    public function select(...$columns): Query\SelectQuery
29
    {
30 32
        $query = $this->engine->makeSelect();
31 32
        if (empty($columns) === false) {
32 12
            $query = $query->columns(...$columns);
33
        }
34 32
        return $query;
35
    }
36
37
    /**
38
     * Create a new SELECT DISTINCT query
39
     *
40
     * @param string|StatementInterface ...$columns
41
     */
42 1
    public function selectDistinct(...$columns): Query\SelectQuery
43
    {
44 1
        return $this->select(...$columns)->distinct();
45
    }
46
47
    /**
48
     * Create a new INSERT query
49
     *
50
     * @param string|StatementInterface $table
51
     */
52 4
    public function insert($table, array $map = []): Query\InsertQuery
53
    {
54 4
        $query = $this->engine->makeInsert()->into($table);
55 4
        if (empty($map) === false) {
56 2
            $query = $query->map($map);
57
        }
58 4
        return $query;
59
    }
60
61
    /**
62
     * Create a new DELETE query
63
     *
64
     * @param string|StatementInterface $table
65
     */
66 3
    public function delete($table): Query\DeleteQuery
67
    {
68 3
        return $this->engine->makeDelete()->from($table);
69
70
    }
0 ignored issues
show
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
71
72
    /**
73
     * Create a new UPDATE query
74
     *
75
     * @param string|StatementInterface $table
76
     */
77 4
    public function update($table, array $map = []): Query\UpdateQuery
78
    {
79 4
        $query = $this->engine->makeUpdate()->table($table);
80 4
        if (empty($map) === false) {
81 3
            $query = $query->set($map);
82
        }
83 4
        return $query;
84
    }
85
86
    /**
87
     * Create a new criteria from an expression
88
     *
89
     * @link https://hoa-project.net/En/Literature/Hack/Ruler.html
90
     */
91 8
    public function criteria(string $expression): CriteriaInterface
92
    {
93 8
        return $this->visitor()->visit(\Hoa\Ruler\Ruler::interpret($expression));
94
    }
95
96 8
    protected function visitor(): Visitor
97
    {
98 8
        if ($this->visitor === null) {
99 8
            $this->visitor = new Visitor();
100
        }
101
102 8
        return $this->visitor;
103
    }
104
}
105