WriteToFile::getGzip()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
cc 1
eloc 1
nc 1
nop 0
crap 1
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 WriteToFile
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\WriteToFile::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\WriteToFile::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\WriteToFile::FORMAT_CSV visibility missing.
Loading history...
15
    const FORMAT_CSVWithNames          = 'CSVWithNames';
0 ignored issues
show
introduced by
Constant \ClickHouseDB\Query\WriteToFile::FORMAT_CSVWithNames visibility missing.
Loading history...
Coding Style introduced by
This class constant is not uppercase (expected FORMAT_CSVWITHNAMES).
Loading history...
16
    const FORMAT_JSONEACHROW           = 'JSONEachRow';
0 ignored issues
show
introduced by
Constant \ClickHouseDB\Query\WriteToFile::FORMAT_JSONEACHROW visibility missing.
Loading history...
17
18
    private $support_format = ['TabSeparated', 'TabSeparatedWithNames', 'CSV', 'CSVWithNames', 'JSONEachRow'];
0 ignored issues
show
introduced by
Property \ClickHouseDB\Query\WriteToFile::$support_format does not have @var annotation for its value.
Loading history...
Coding Style introduced by
Member variable "support_format" is not in valid camel caps format
Loading history...
19
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Query\WriteToFile::$file_name with single line content, use one-line comment instead.
Loading history...
20
     * @var string
21
     */
22
    private $file_name = null;
0 ignored issues
show
Coding Style introduced by
Member variable "file_name" is not in valid camel caps format
Loading history...
23
24
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Query\WriteToFile::$format with single line content, use one-line comment instead.
Loading history...
25
     * @var string
26
     */
27
    private $format = 'CSV';
28
29
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Query\WriteToFile::$gzip with single line content, use one-line comment instead.
Loading history...
30
     * @var bool
31
     */
32
    private $gzip = false;
33
    /**
34
     * WriteToFile constructor.
0 ignored issues
show
introduced by
Documentation comment contains forbidden comment "WriteToFile constructor.".
Loading history...
35
     * @param string $file_name
0 ignored issues
show
introduced by
Expected 1 lines between description and annotations, found 0.
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
36
     * @param bool $overwrite
0 ignored issues
show
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
37
     * @param string|null $format
38
     */
39 1
    public function __construct($file_name, $overwrite = true, $format = null) {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 2 found
Loading history...
introduced by
Method \ClickHouseDB\Query\WriteToFile::__construct() 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\WriteToFile::__construct() does not have native type hint for its parameter $overwrite but it should be possible to add it based on @param annotation "bool".
Loading history...
introduced by
Method \ClickHouseDB\Query\WriteToFile::__construct() does not have native type hint for its parameter $format but it should be possible to add it based on @param annotation "string|null".
Loading history...
Coding Style introduced by
Expected 1 blank line before function; 0 found
Loading history...
Coding Style introduced by
The variable $file_name should be in camel caps format.
Loading history...
40
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
41
42 1
        if (!$file_name)
0 ignored issues
show
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...
43
        {
44
            throw new QueryException('Bad file path');
45
        }
46
47 1
        if (is_file($file_name))
0 ignored issues
show
introduced by
Function is_file() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Expected 1 lines after "if", found 0.
Loading history...
Coding Style introduced by
The variable $file_name should be in camel caps format.
Loading history...
48
        {
49 1
            if (!$overwrite)
0 ignored issues
show
introduced by
Expected 1 lines after "if", found 0.
Loading history...
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
50
            {
51
                throw new QueryException('File exists: ' . $file_name);
0 ignored issues
show
Coding Style introduced by
The variable $file_name should be in camel caps format.
Loading history...
52
            }
53 1
            if (!unlink($file_name))
0 ignored issues
show
introduced by
Function unlink() 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...
54
            {
55
                throw new QueryException('Can`t delete: ' . $file_name);
0 ignored issues
show
Coding Style introduced by
The variable $file_name should be in camel caps format.
Loading history...
56
            }
57
        }
58 1
        $dir = dirname($file_name);
0 ignored issues
show
introduced by
Function dirname() 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...
59 1
        if (!is_writable($dir))
0 ignored issues
show
introduced by
Function is_writable() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Expected 1 lines after "if", found 0.
Loading history...
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
60
        {
61
            throw new QueryException('Can`t writable dir: ' . $dir);
62
        }
63 1
        if (is_string($format))
0 ignored issues
show
introduced by
Function is_string() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Expected 1 lines after "if", found 0.
Loading history...
64
        {
65 1
            $this->setFormat($format);
66
        }
67 1
        $this->file_name = $file_name;
0 ignored issues
show
Coding Style introduced by
The variable $file_name should be in camel caps format.
Loading history...
Coding Style introduced by
Member variable "file_name" is not in valid camel caps format
Loading history...
68 1
    }
69
70
    /**
71
     * @return bool
72
     */
73 1
    public function getGzip()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Query\WriteToFile::getGzip() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
74
    {
75 1
        return $this->gzip;
76
    }
77
78
    /**
79
     * @param bool $flag
80
     */
81
    public function setGzip($flag)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Query\WriteToFile::setGzip() does not have native type hint for its parameter $flag but it should be possible to add it based on @param annotation "bool".
Loading history...
introduced by
Method \ClickHouseDB\Query\WriteToFile::setGzip() does not have void return type hint.
Loading history...
82
    {
83
        $this->gzip = $flag;
84
    }
85
86
    /**
87
     * @param string $format
88
     */
89 1
    public function setFormat($format)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Query\WriteToFile::setFormat() 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\WriteToFile::setFormat() does not have void return type hint.
Loading history...
90
    {
91 1
        if (!in_array($format, $this->support_format))
0 ignored issues
show
introduced by
Function in_array() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Expected 1 lines after "if", found 0.
Loading history...
Coding Style introduced by
Member variable "support_format" is not in valid camel caps format
Loading history...
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
92
        {
93
            throw new QueryException('Unsupport format: ' . $format);
94
        }
95 1
        $this->format = $format;
96 1
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 0 found
Loading history...
97
    /**
98
     * @return int
99
     */
100 1
    public function size()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Query\WriteToFile::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...
101
    {
102 1
        return filesize($this->file_name);
0 ignored issues
show
introduced by
Function filesize() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Member variable "file_name" is not in valid camel caps format
Loading history...
103
    }
104
105
    /**
106
     * @return string
107
     */
108 1
    public function fetchFile()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Query\WriteToFile::fetchFile() 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...
109
    {
110 1
        return $this->file_name;
0 ignored issues
show
Coding Style introduced by
Member variable "file_name" is not in valid camel caps format
Loading history...
111
    }
112
113
    /**
114
     * @return string
115
     */
116 1
    public function fetchFormat()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Query\WriteToFile::fetchFormat() 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...
117
    {
118 1
        return $this->format;
119
    }
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after function; 1 found
Loading history...
120
121
}
0 ignored issues
show
introduced by
There must be exactly 0 empty lines before class closing brace.
Loading history...
122