LaravelFreelancerNL /
laravel-arangodb
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | declare(strict_types=1); |
||||||
| 4 | |||||||
| 5 | namespace LaravelFreelancerNL\Aranguent\Query\Concerns; |
||||||
| 6 | |||||||
| 7 | use Illuminate\Database\Query\Builder as IlluminateBuilder; |
||||||
| 8 | use LaravelFreelancerNL\Aranguent\Query\Builder; |
||||||
| 9 | |||||||
| 10 | trait CompilesAggregates |
||||||
| 11 | { |
||||||
| 12 | /** |
||||||
| 13 | * Compile an aggregated select clause. |
||||||
| 14 | * |
||||||
| 15 | * @param \Illuminate\Database\Query\Builder $query |
||||||
| 16 | * @param array<mixed> $aggregate |
||||||
| 17 | * @return string |
||||||
| 18 | */ |
||||||
| 19 | 82 | protected function compileAggregate(IlluminateBuilder $query, $aggregate) |
|||||
| 20 | { |
||||||
| 21 | 82 | $method = 'compile' . ucfirst($aggregate['function']); |
|||||
| 22 | |||||||
| 23 | 82 | return $this->$method($query, $aggregate); |
|||||
| 24 | } |
||||||
| 25 | |||||||
| 26 | /** |
||||||
| 27 | * Compile AQL for average aggregate. |
||||||
| 28 | * |
||||||
| 29 | * @param array<mixed> $aggregate |
||||||
| 30 | * @return string |
||||||
| 31 | * @throws \Exception |
||||||
| 32 | */ |
||||||
| 33 | 3 | protected function compileAvg(Builder $query, array $aggregate) |
|||||
| 34 | { |
||||||
| 35 | 3 | $column = $this->normalizeColumn($query, $aggregate['columns'][0]); |
|||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 36 | |||||||
| 37 | 3 | return "COLLECT AGGREGATE aggregateResult = AVERAGE($column)"; |
|||||
| 38 | } |
||||||
| 39 | |||||||
| 40 | /** |
||||||
| 41 | * Compile AQL for count aggregate. |
||||||
| 42 | * |
||||||
| 43 | * @SuppressWarnings("PHPMD.UnusedFormalParameter") |
||||||
| 44 | * @param Builder $query |
||||||
| 45 | * @return string |
||||||
| 46 | */ |
||||||
| 47 | 8 | protected function compileCount(Builder $query) |
|||||
| 48 | { |
||||||
| 49 | 8 | return "COLLECT WITH COUNT INTO aggregateResult"; |
|||||
| 50 | } |
||||||
| 51 | |||||||
| 52 | /** |
||||||
| 53 | * Compile an exists statement into AQL. |
||||||
| 54 | * |
||||||
| 55 | * @param IlluminateBuilder $query |
||||||
| 56 | * @return string |
||||||
| 57 | */ |
||||||
| 58 | 18 | public function compileExists(IlluminateBuilder $query) |
|||||
| 59 | { |
||||||
| 60 | 18 | $query->columns = [$query->from]; |
|||||
| 61 | |||||||
| 62 | 18 | $select = $this->compileSelect($query); |
|||||
|
0 ignored issues
–
show
The method
compileSelect() does not exist on LaravelFreelancerNL\Aran...erns\CompilesAggregates. Did you maybe mean compileSum()?
(
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. Loading history...
|
|||||||
| 63 | |||||||
| 64 | 18 | return 'RETURN { exists: LENGTH((' . $select . ')) > 0 ? true : false }'; |
|||||
| 65 | } |
||||||
| 66 | |||||||
| 67 | |||||||
| 68 | /** |
||||||
| 69 | * Compile AQL for max aggregate. |
||||||
| 70 | * |
||||||
| 71 | * @param array<mixed> $aggregate |
||||||
| 72 | * @return string |
||||||
| 73 | * @throws \Exception |
||||||
| 74 | */ |
||||||
| 75 | 65 | protected function compileMax(Builder $query, array $aggregate) |
|||||
| 76 | { |
||||||
| 77 | 65 | $column = $this->normalizeColumn($query, $aggregate['columns'][0]); |
|||||
| 78 | |||||||
| 79 | 65 | return "COLLECT AGGREGATE aggregateResult = MAX($column)"; |
|||||
| 80 | } |
||||||
| 81 | |||||||
| 82 | /** |
||||||
| 83 | * Compile AQL for min aggregate. |
||||||
| 84 | * |
||||||
| 85 | * @param Builder $query |
||||||
| 86 | * @param array<mixed> $aggregate |
||||||
| 87 | * @return string |
||||||
| 88 | * @throws \Exception |
||||||
| 89 | */ |
||||||
| 90 | 3 | protected function compileMin(Builder $query, array $aggregate) |
|||||
| 91 | { |
||||||
| 92 | 3 | $column = $this->normalizeColumn($query, $aggregate['columns'][0]); |
|||||
| 93 | |||||||
| 94 | 3 | return "COLLECT AGGREGATE aggregateResult = MIN($column)"; |
|||||
| 95 | } |
||||||
| 96 | |||||||
| 97 | /** |
||||||
| 98 | * Compile AQL for sum aggregate. |
||||||
| 99 | * |
||||||
| 100 | * @param Builder $query |
||||||
| 101 | * @param array<mixed> $aggregate |
||||||
| 102 | * @return string |
||||||
| 103 | * @throws \Exception |
||||||
| 104 | */ |
||||||
| 105 | 3 | protected function compileSum(Builder $query, array $aggregate) |
|||||
| 106 | { |
||||||
| 107 | 3 | $column = $this->normalizeColumn($query, $aggregate['columns'][0]); |
|||||
| 108 | |||||||
| 109 | 3 | return "COLLECT AGGREGATE aggregateResult = SUM($column)"; |
|||||
| 110 | } |
||||||
| 111 | } |
||||||
| 112 |