WhereInFile::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 1
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types=1).
Loading history...
2
3
namespace ClickHouseDB\Query;
4
5
use ClickHouseDB\Exception\QueryException;
6
7
class WhereInFile
8
{
9
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
10
     *
11
     */
12
    const FORMAT_TabSeparated          = 'TabSeparated';
0 ignored issues
show
introduced by
Constant \ClickHouseDB\Query\WhereInFile::FORMAT_TabSeparated visibility missing.
Loading history...
Coding Style introduced by
This class constant is not uppercase (expected FORMAT_TABSEPARATED).
Loading history...
13
    const FORMAT_TabSeparatedWithNames = 'TabSeparatedWithNames';
0 ignored issues
show
introduced by
Constant \ClickHouseDB\Query\WhereInFile::FORMAT_TabSeparatedWithNames visibility missing.
Loading history...
Coding Style introduced by
This class constant is not uppercase (expected FORMAT_TABSEPARATEDWITHNAMES).
Loading history...
14
    const FORMAT_CSV                   = 'CSV';
0 ignored issues
show
introduced by
Constant \ClickHouseDB\Query\WhereInFile::FORMAT_CSV visibility missing.
Loading history...
15
16
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Query\WhereInFile::$_files with single line content, use one-line comment instead.
Loading history...
17
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Query\WhereInFile::$_files does not specify type hint for its items.
Loading history...
18
     */
19
    private $_files = [];
20
21
22
    /**
23
     * WhereInFile constructor.
0 ignored issues
show
introduced by
Documentation comment contains forbidden comment "WhereInFile constructor.".
Loading history...
24
     */
25 1
    public function __construct() {}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before function; 2 found
Loading history...
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
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
introduced by
Method \ClickHouseDB\Query\WhereInFile::attachFile() does not have native type hint for its parameter $file_name but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Query\WhereInFile::attachFile() does not have native type hint for its parameter $table_name but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Query\WhereInFile::attachFile() does not have native type hint for its parameter $structure but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Query\WhereInFile::attachFile() does not have native type hint for its parameter $format but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Query\WhereInFile::attachFile() does not have void return type hint.
Loading history...
Coding Style introduced by
The variable $file_name should be in camel caps format.
Loading history...
Coding Style introduced by
The variable $table_name should be in camel caps format.
Loading history...
35
    {
36 1
        if (!is_readable($file_name)) {
0 ignored issues
show
introduced by
Function is_readable() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
The variable $file_name should be in camel caps format.
Loading history...
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
37
            throw new QueryException('Can`t read file: ' . $file_name);
0 ignored issues
show
Coding Style introduced by
The variable $file_name should be in camel caps format.
Loading history...
38
        }
39
40 1
        $this->_files[$table_name] = [
0 ignored issues
show
Coding Style introduced by
The variable $table_name should be in camel caps format.
Loading history...
41 1
            'filename'  => $file_name,
0 ignored issues
show
Coding Style introduced by
The variable $file_name should be in camel caps format.
Loading history...
42 1
            'structure' => $structure,
43 1
            'format'    => $format
0 ignored issues
show
introduced by
Multi-line arrays must have a trailing comma after the last element.
Loading history...
44
        ];
45 1
    }
46
47
    /**
48
     * @return int
49
     */
50 1
    public function size()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Query\WhereInFile::size() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "int".
Loading history...
51
    {
52 1
        return sizeof($this->_files);
0 ignored issues
show
introduced by
Function sizeof() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
The use of function sizeof() is forbidden; use count() instead
Loading history...
53
    }
54
55
    /**
56
     * @return array
0 ignored issues
show
introduced by
@return annotation of method \ClickHouseDB\Query\WhereInFile::fetchFiles() does not specify type hint for items of its traversable return value.
Loading history...
57
     */
58 1
    public function fetchFiles()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Query\WhereInFile::fetchFiles() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
59
    {
60 1
        $out = [];
61 1
        foreach ($this->_files as $table => $data) {
62 1
            $out[$table] = realpath($data['filename']);
0 ignored issues
show
introduced by
Function realpath() should not be referenced via a fallback global name, but via a use statement.
Loading history...
63
        }
64
65 1
        return $out;
66
    }
67
68
    /**
69
     * @param string $table
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
70
     * @return string
71
     */
72 1
    public function fetchStructure($table)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Query\WhereInFile::fetchStructure() does not have native type hint for its parameter $table but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Query\WhereInFile::fetchStructure() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "string".
Loading history...
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
introduced by
Function implode() should not be referenced via a fallback global name, but via a use statement.
Loading history...
82
    }
83
84
    /**
85
     * @return array
0 ignored issues
show
introduced by
@return annotation of method \ClickHouseDB\Query\WhereInFile::fetchUrlParams() does not specify type hint for items of its traversable return value.
Loading history...
86
     */
87 1
    public function fetchUrlParams()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Query\WhereInFile::fetchUrlParams() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
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
Coding Style introduced by
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
Coding Style introduced by
Expected 0 blank lines after function; 1 found
Loading history...
97
98
}
0 ignored issues
show
introduced by
There must be exactly 0 empty lines before class closing brace.
Loading history...
99