| 1 | <?php |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 2 | |||
| 3 | namespace ClickHouseDB\Query; |
||
| 4 | |||
| 5 | use ClickHouseDB\Exception\QueryException; |
||
| 6 | |||
| 7 | class WhereInFile |
||
| 8 | { |
||
| 9 | /** |
||
|
0 ignored issues
–
show
|
|||
| 10 | * |
||
| 11 | */ |
||
| 12 | const FORMAT_TabSeparated = 'TabSeparated'; |
||
|
0 ignored issues
–
show
|
|||
| 13 | const FORMAT_TabSeparatedWithNames = 'TabSeparatedWithNames'; |
||
|
0 ignored issues
–
show
|
|||
| 14 | const FORMAT_CSV = 'CSV'; |
||
|
0 ignored issues
–
show
|
|||
| 15 | |||
| 16 | /** |
||
|
0 ignored issues
–
show
|
|||
| 17 | * @var array |
||
|
0 ignored issues
–
show
|
|||
| 18 | */ |
||
| 19 | private $_files = []; |
||
| 20 | |||
| 21 | |||
| 22 | /** |
||
| 23 | * WhereInFile constructor. |
||
|
0 ignored issues
–
show
|
|||
| 24 | */ |
||
| 25 | 1 | public function __construct() {} |
|
|
0 ignored issues
–
show
|
|||
| 26 | |||
| 27 | |||
| 28 | /** |
||
| 29 | * @param string $file_name |
||
| 30 | * @param string $table_name |
||
| 31 | * @param string $structure |
||
| 32 | * @param string $format |
||
| 33 | */ |
||
| 34 | 1 | public function attachFile($file_name, $table_name, $structure, $format = 'CSV') |
|
|
0 ignored issues
–
show
|
|||
| 35 | { |
||
| 36 | 1 | if (!is_readable($file_name)) { |
|
|
0 ignored issues
–
show
|
|||
| 37 | throw new QueryException('Can`t read file: ' . $file_name); |
||
|
0 ignored issues
–
show
|
|||
| 38 | } |
||
| 39 | |||
| 40 | 1 | $this->_files[$table_name] = [ |
|
|
0 ignored issues
–
show
|
|||
| 41 | 1 | 'filename' => $file_name, |
|
|
0 ignored issues
–
show
|
|||
| 42 | 1 | 'structure' => $structure, |
|
| 43 | 1 | 'format' => $format |
|
|
0 ignored issues
–
show
|
|||
| 44 | ]; |
||
| 45 | 1 | } |
|
| 46 | |||
| 47 | /** |
||
| 48 | * @return int |
||
| 49 | */ |
||
| 50 | 1 | public function size() |
|
|
0 ignored issues
–
show
|
|||
| 51 | { |
||
| 52 | 1 | return sizeof($this->_files); |
|
|
0 ignored issues
–
show
|
|||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return array |
||
|
0 ignored issues
–
show
|
|||
| 57 | */ |
||
| 58 | 1 | public function fetchFiles() |
|
|
0 ignored issues
–
show
|
|||
| 59 | { |
||
| 60 | 1 | $out = []; |
|
| 61 | 1 | foreach ($this->_files as $table => $data) { |
|
| 62 | 1 | $out[$table] = realpath($data['filename']); |
|
|
0 ignored issues
–
show
|
|||
| 63 | } |
||
| 64 | |||
| 65 | 1 | return $out; |
|
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param string $table |
||
|
0 ignored issues
–
show
|
|||
| 70 | * @return string |
||
| 71 | */ |
||
| 72 | 1 | public function fetchStructure($table) |
|
|
0 ignored issues
–
show
|
|||
| 73 | { |
||
| 74 | 1 | $structure = $this->_files[$table]['structure']; |
|
| 75 | |||
| 76 | 1 | $out = []; |
|
| 77 | 1 | foreach ($structure as $name => $type) { |
|
| 78 | 1 | $out[] = $name . ' ' . $type; |
|
| 79 | } |
||
| 80 | |||
| 81 | 1 | return implode(',', $out); |
|
|
0 ignored issues
–
show
|
|||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @return array |
||
|
0 ignored issues
–
show
|
|||
| 86 | */ |
||
| 87 | 1 | public function fetchUrlParams() |
|
|
0 ignored issues
–
show
|
|||
| 88 | { |
||
| 89 | 1 | $out = []; |
|
| 90 | 1 | foreach ($this->_files as $table => $data) { |
|
| 91 | 1 | $out[$table . '_structure'] = $this->fetchStructure($table); |
|
| 92 | 1 | $out[$table . '_format'] = $data['format']; |
|
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||
| 93 | } |
||
| 94 | |||
| 95 | 1 | return $out; |
|
| 96 | } |
||
|
0 ignored issues
–
show
|
|||
| 97 | |||
| 98 | } |
||
|
0 ignored issues
–
show
|
|||
| 99 |