| 1 | <?php |
||
| 2 | namespace Kir\MySQL\Builder\Traits; |
||
| 3 | |||
| 4 | use InvalidArgumentException; |
||
| 5 | use Kir\MySQL\Builder\Internal\Types; |
||
| 6 | use Kir\MySQL\Common\SpecialTable; |
||
| 7 | use Kir\MySQL\Database; |
||
| 8 | use Kir\MySQL\Tools\VirtualTable; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @phpstan-import-type DBTableNameType from Types |
||
| 12 | */ |
||
| 13 | trait TableNameBuilder { |
||
| 14 | use AbstractAliasReplacer; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param string|null $alias |
||
| 18 | * @param DBTableNameType $name |
||
|
0 ignored issues
–
show
|
|||
| 19 | * @return string |
||
| 20 | */ |
||
| 21 | protected function buildTableName(?string $alias, $name): string { |
||
| 22 | if($name instanceof SpecialTable) { |
||
| 23 | $name = $name->asString($this->db()); |
||
| 24 | } elseif(is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
||
| 25 | $name = (string) $name; |
||
| 26 | $lines = explode("\n", $name); |
||
| 27 | $lines = array_map(static fn(string $line) => "\t{$line}", $lines); |
||
| 28 | $name = implode("\n", $lines); |
||
| 29 | $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
||
| 30 | } elseif(is_array($name)) { |
||
| 31 | $parts = []; |
||
| 32 | foreach($name as /*$index => */$bucket) { |
||
| 33 | if(is_scalar($bucket)/* && ctype_digit((string) $index)*/) { |
||
| 34 | $parts[] = "SELECT {$this->db()->quote($bucket)} AS {$this->db()->quoteField('value')}"; |
||
| 35 | } elseif(is_iterable($bucket)) { |
||
| 36 | $values = []; |
||
| 37 | foreach($bucket as $field => $value) { |
||
| 38 | $values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field)); |
||
| 39 | } |
||
| 40 | $parts[] = sprintf("SELECT %s", implode(', ', $values)); |
||
| 41 | } else { |
||
| 42 | throw new InvalidArgumentException('Only scalar values and iterables are supported as table data'); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | $name = '(' . implode("\n\tUNION ALL\n\t", $parts) . ')'; |
||
| 46 | } |
||
| 47 | if((is_string($name) || $name instanceof VirtualTable) && $this->db()->getVirtualTables()->has($name)) { |
||
| 48 | $select = (string) $this->db()->getVirtualTables()->get($name); |
||
| 49 | $name = sprintf('(%s)', implode("\n\t", explode("\n", trim($select)))); |
||
| 50 | } |
||
| 51 | $name = $this->aliasReplacer()->replace((string) $name); |
||
| 52 | if($alias !== null) { |
||
| 53 | return sprintf("%s %s", $name, $alias); |
||
| 54 | } |
||
| 55 | return $name; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return Database |
||
| 60 | */ |
||
| 61 | abstract protected function db(): Database; |
||
| 62 | } |
||
| 63 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths