1 | <?php |
||||||||||
2 | |||||||||||
3 | namespace Bdf\Prime\Query\Extension; |
||||||||||
4 | |||||||||||
5 | use Bdf\Prime\Exception\PrimeException; |
||||||||||
6 | use Bdf\Prime\Query\Compiler\CompilerState; |
||||||||||
7 | use Bdf\Prime\Query\Compiler\DeleteCompilerInterface; |
||||||||||
8 | use Bdf\Prime\Query\Compiler\InsertCompilerInterface; |
||||||||||
9 | use Bdf\Prime\Query\Compiler\SelectCompilerInterface; |
||||||||||
10 | use Bdf\Prime\Query\Compiler\UpdateCompilerInterface; |
||||||||||
11 | use Bdf\Prime\Query\Contract\Compilable; |
||||||||||
12 | |||||||||||
13 | /** |
||||||||||
14 | * Simple implementation for @see Compilable |
||||||||||
15 | * |
||||||||||
16 | * @property CompilerState $compilerState |
||||||||||
17 | * @property object $compiler |
||||||||||
18 | * |
||||||||||
19 | * @psalm-require-implements Compilable |
||||||||||
20 | */ |
||||||||||
21 | trait CompilableTrait |
||||||||||
22 | { |
||||||||||
23 | /** |
||||||||||
24 | * @var Compilable::TYPE_* |
||||||||||
25 | */ |
||||||||||
26 | protected $type = Compilable::TYPE_SELECT; |
||||||||||
27 | |||||||||||
28 | /** |
||||||||||
29 | * {@inheritdoc} |
||||||||||
30 | */ |
||||||||||
31 | 955 | public function compile(bool $forceRecompile = false) |
|||||||||
32 | { |
||||||||||
33 | 955 | if ($forceRecompile) { |
|||||||||
34 | 4 | $this->compilerState->invalidate('prepared'); |
|||||||||
35 | 955 | } elseif ($this->compilerState->compiled) { |
|||||||||
36 | 174 | return $this->compilerState->compiled; |
|||||||||
37 | } |
||||||||||
38 | |||||||||||
39 | 948 | return $this->compilerState->compiled = $this->doCompilation($this->type, $this->compiler); |
|||||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||||||
40 | } |
||||||||||
41 | |||||||||||
42 | /** |
||||||||||
43 | * {@inheritdoc} |
||||||||||
44 | */ |
||||||||||
45 | public function getBindings(): array |
||||||||||
46 | { |
||||||||||
47 | return $this->compiler->getBindings($this); |
||||||||||
48 | } |
||||||||||
49 | |||||||||||
50 | /** |
||||||||||
51 | * {@inheritdoc} |
||||||||||
52 | * |
||||||||||
53 | * @return Compilable::TYPE_* |
||||||||||
54 | */ |
||||||||||
55 | 852 | public function type(): string |
|||||||||
56 | { |
||||||||||
57 | 852 | return $this->type; |
|||||||||
0 ignored issues
–
show
|
|||||||||||
58 | } |
||||||||||
59 | |||||||||||
60 | /** |
||||||||||
61 | * Change the query type |
||||||||||
62 | * This action will invalidate the current query |
||||||||||
63 | * |
||||||||||
64 | * @param Compilable::TYPE_* $type One of the Compilable::TYPE_* constant |
||||||||||
65 | * |
||||||||||
66 | * @return void |
||||||||||
67 | */ |
||||||||||
68 | 842 | protected function setType(string $type): void |
|||||||||
69 | { |
||||||||||
70 | 842 | if ($this->type !== $type) { |
|||||||||
0 ignored issues
–
show
|
|||||||||||
71 | 709 | $this->compilerState->invalidate(); |
|||||||||
72 | 709 | $this->type = $type; |
|||||||||
0 ignored issues
–
show
It seems like
$type of type string is incompatible with the declared type Bdf\Prime\Query\Contract\Compilable of property $type .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() |
|||||||||||
73 | } |
||||||||||
74 | } |
||||||||||
75 | |||||||||||
76 | /** |
||||||||||
77 | * Perform the query compilation |
||||||||||
78 | * Can be overridden for perform custom compilation process |
||||||||||
79 | * |
||||||||||
80 | * @param Compilable::TYPE_* $type The query type |
||||||||||
81 | * @param object $compiler The related compiler |
||||||||||
82 | * |
||||||||||
83 | * @return mixed The compiled query |
||||||||||
84 | * |
||||||||||
85 | * @throws PrimeException When the compilation fail |
||||||||||
86 | * @throws \LogicException If type is not supported by the query or the compiler |
||||||||||
87 | */ |
||||||||||
88 | 948 | protected function doCompilation(string $type, object $compiler) |
|||||||||
89 | { |
||||||||||
90 | switch (true) { |
||||||||||
91 | 948 | case $type === Compilable::TYPE_SELECT && $compiler instanceof SelectCompilerInterface: |
|||||||||
92 | 902 | return $compiler->compileSelect($this); |
|||||||||
0 ignored issues
–
show
$this of type Bdf\Prime\Query\Extension\CompilableTrait is incompatible with the type Bdf\Prime\Query\CompilableClause expected by parameter $query of Bdf\Prime\Query\Compiler...erface::compileSelect() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||||
93 | |||||||||||
94 | 713 | case $type === Compilable::TYPE_UPDATE && $compiler instanceof UpdateCompilerInterface: |
|||||||||
95 | 91 | return $compiler->compileUpdate($this); |
|||||||||
0 ignored issues
–
show
The method
compileUpdate() does not exist on Bdf\Prime\Query\Compiler\SelectCompilerInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to Bdf\Prime\Query\Compiler\SelectCompilerInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() $this of type Bdf\Prime\Query\Extension\CompilableTrait is incompatible with the type Bdf\Prime\Query\CompilableClause expected by parameter $query of Bdf\Prime\Query\Compiler...erface::compileUpdate() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||||
96 | |||||||||||
97 | 680 | case $type === Compilable::TYPE_INSERT && $compiler instanceof InsertCompilerInterface: |
|||||||||
98 | 662 | return $compiler->compileInsert($this); |
|||||||||
0 ignored issues
–
show
$this of type Bdf\Prime\Query\Extension\CompilableTrait is incompatible with the type Bdf\Prime\Query\CompilableClause expected by parameter $query of Bdf\Prime\Query\Compiler...erface::compileInsert() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The method
compileInsert() does not exist on Bdf\Prime\Query\Compiler\SelectCompilerInterface . Did you maybe mean compileSelect() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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. ![]() The method
compileInsert() does not exist on Bdf\Prime\Query\Compiler\UpdateCompilerInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to Bdf\Prime\Query\Compiler\UpdateCompilerInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||||
99 | |||||||||||
100 | 81 | case $type === Compilable::TYPE_DELETE && $compiler instanceof DeleteCompilerInterface: |
|||||||||
101 | 79 | return $compiler->compileDelete($this); |
|||||||||
0 ignored issues
–
show
The method
compileDelete() does not exist on Bdf\Prime\Query\Compiler\SelectCompilerInterface . Did you maybe mean compileSelect() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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. ![]() The method
compileDelete() does not exist on Bdf\Prime\Query\Compiler\InsertCompilerInterface . Did you maybe mean compileInsert() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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. ![]() The method
compileDelete() does not exist on Bdf\Prime\Query\Compiler\UpdateCompilerInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to Bdf\Prime\Query\Compiler\UpdateCompilerInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() $this of type Bdf\Prime\Query\Extension\CompilableTrait is incompatible with the type Bdf\Prime\Query\CompilableClause expected by parameter $query of Bdf\Prime\Query\Compiler...erface::compileDelete() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||||
102 | |||||||||||
103 | default: |
||||||||||
104 | 2 | throw new \LogicException('The query ' . static::class . ' do not supports type ' . $type); |
|||||||||
105 | } |
||||||||||
106 | } |
||||||||||
107 | } |
||||||||||
108 |