Issues (590)

bench/Query/CompilerBench.php (5 issues)

Labels
1
<?php
2
3
namespace Bdf\Prime\Query;
4
5
require_once __DIR__ . '/../_files/BenchData.php';
6
7
use Bdf\Prime\Bench\BenchData;
8
use Bdf\Prime\Bench\User;
9
use Bdf\Prime\Cache\ArrayCache;
10
use Bdf\Prime\Connection\ConnectionConfig;
0 ignored issues
show
The type Bdf\Prime\Connection\ConnectionConfig 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...
11
use Bdf\Prime\ConnectionManager;
12
use Bdf\Prime\Locatorizable;
13
use Bdf\Prime\Query\Compiler\Preprocessor\OrmPreprocessor;
14
use Bdf\Prime\Query\Compiler\SqlCompiler;
15
use Bdf\Prime\Query\Custom\KeyValue\KeyValueQuery;
16
use Bdf\Prime\Query\Custom\KeyValue\KeyValueSqlCompiler;
17
use Bdf\Prime\Repository\EntityRepository;
18
use Bdf\Prime\ServiceLocator;
19
use Bdf\Prime\Types\ArrayType;
20
use BenchCaseAdapter;
21
22
/**
23
 * @Revs(100)
24
 * @Warmup(1)
25
 */
26
class CompilerBench extends BenchCaseAdapter
27
{
28
    /**
29
     * @var ServiceLocator
30
     */
31
    protected $prime;
32
33
    /**
34
     * @var BenchData
35
     */
36
    protected $data;
37
38
    /**
39
     * @var ArrayCache
40
     */
41
    protected $cache;
42
43
    /**
44
     * @var EntityRepository
45
     */
46
    protected $repository;
47
48
    /**
49
     * @var KeyValueSqlCompiler
50
     */
51
    protected $keyValueCompiler;
52
53
    /**
54
     * @var SqlCompiler
55
     */
56
    protected $sqlCompiler;
57
58
59
60
    public function setUp()
61
    {
62
        $this->cache = new ArrayCache();
63
        $this->prime = new ServiceLocator();
64
        $this->prime->connections()->declareConnection('test', BENCH_CONNECTION);
65
        $this->prime->connection('test')->getConfiguration()->getTypes()->register(ArrayType::class, 'array');
0 ignored issues
show
The method getConfiguration() does not exist on Bdf\Prime\Connection\ConnectionInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Bdf\Prime\Connection\ConnectionInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        $this->prime->connection('test')->/** @scrutinizer ignore-call */ getConfiguration()->getTypes()->register(ArrayType::class, 'array');
Loading history...
66
        Locatorizable::configure($this->prime);
0 ignored issues
show
$this->prime of type Bdf\Prime\ServiceLocator is incompatible with the type Closure expected by parameter $locator of Bdf\Prime\Locatorizable::configure(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
        Locatorizable::configure(/** @scrutinizer ignore-type */ $this->prime);
Loading history...
67
68
        $this->data = new BenchData($this->prime);
69
        $this->data->register([User::class]);
70
71
        $this->repository = $this->prime->repository(User::class);
72
73
        $this->keyValueCompiler = new KeyValueSqlCompiler($this->repository->connection());
0 ignored issues
show
The method connection() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $this->keyValueCompiler = new KeyValueSqlCompiler($this->repository->/** @scrutinizer ignore-call */ connection());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
74
        $this->sqlCompiler = new SqlCompiler($this->repository->connection());
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function tearDown()
81
    {
82
        $this->data->clear();
83
    }
84
85
    /**
86
     * @Groups({"select"})
87
     */
88
    public function bench_compileSelect_KeyValue()
89
    {
90
        $query = $this->repository->connection()->make(KeyValueQuery::class, new OrmPreprocessor($this->repository));
91
        $query->from($this->repository->metadata()->table);
92
        (new QueryRepositoryExtension($this->repository))->apply($query);
93
94
        $query->where(['name' => 'John', 'customer.id' => 5]);
0 ignored issues
show
The method where() does not exist on Bdf\Prime\Query\CommandInterface. It seems like you code against a sub-type of Bdf\Prime\Query\CommandInterface such as Bdf\Prime\Query\Contract...\KeyValueQueryInterface or Bdf\Prime\Query\QueryInterface or Bdf\Prime\Query\AbstractReadCommand. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

94
        $query->/** @scrutinizer ignore-call */ 
95
                where(['name' => 'John', 'customer.id' => 5]);
Loading history...
95
96
        $this->keyValueCompiler->compileSelect($query);
97
    }
98
99
    /**
100
     * @Groups({"delete"})
101
     */
102
    public function bench_compileDelete_KeyValue()
103
    {
104
        $query = $this->repository->connection()->make(KeyValueQuery::class, new OrmPreprocessor($this->repository));
105
        $query->from($this->repository->metadata()->table);
106
        (new QueryRepositoryExtension($this->repository))->apply($query);
107
108
        $query->where(['name' => 'John', 'customer.id' => 5]);
109
110
        $this->keyValueCompiler->compileDelete($query);
111
    }
112
113
    /**
114
     * @Groups({"select"})
115
     */
116
    public function bench_compileSelect_default()
117
    {
118
        $query = $this->repository->builder();
119
        $query->where(['name' => 'John', 'customer.id' => 5]);
120
121
        $this->sqlCompiler->compileSelect($query);
122
    }
123
124
    /**
125
     * @Groups({"delete"})
126
     */
127
    public function bench_compileDelete_default()
128
    {
129
        $query = $this->repository->builder();
130
        $query->where(['name' => 'John', 'customer.id' => 5]);
131
132
        $this->sqlCompiler->compileDelete($query);
133
    }
134
}
135