| Conditions | 3 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | protected function compile(string $statement): string |
||
| 17 | { |
||
| 18 | $path = $this->getPath($statement); |
||
| 19 | $attribute = $this->getAttribute($statement); |
||
| 20 | $fullPath = $this->getField($statement); |
||
| 21 | if (!empty($path)) { |
||
| 22 | $fullPath .= '->' . $path; |
||
| 23 | } |
||
| 24 | |||
| 25 | if (!\filter_var($attribute, FILTER_VALIDATE_INT)) { |
||
| 26 | return \sprintf('coalesce((%s)::jsonb ?? %s, false)', $fullPath, $attribute); |
||
| 27 | } |
||
| 28 | |||
| 29 | return \vsprintf('CASE WHEN %s THEN %s ELSE false END', [ |
||
| 30 | \sprintf('jsonb_typeof((%s)::jsonb) = \'array\'', $fullPath), |
||
| 31 | \sprintf('jsonb_array_length((%s)::jsonb) >= %s', $fullPath, $attribute + 1), |
||
| 32 | ]); |
||
| 35 |