StreamInsert   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 23
c 4
b 0
f 0
dl 0
loc 58
ccs 18
cts 19
cp 0.9474
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A insert() 0 16 2
A __construct() 0 13 3
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types=1).
Loading history...
2
3
namespace ClickHouseDB\Transport;
4
5
use ClickHouseDB\Statement;
6
7
/**
8
 * Class StreamInsert
0 ignored issues
show
introduced by
Documentation comment contains forbidden comment "Class StreamInsert".
Loading history...
9
 * @deprecated
0 ignored issues
show
introduced by
Expected 1 lines between description and annotations, found 0.
Loading history...
introduced by
Incorrect annotations group.
Loading history...
10
 * @package ClickHouseDB\Transport
0 ignored issues
show
introduced by
Use of annotation @package is forbidden.
Loading history...
11
 */
12
class StreamInsert
13
{
14
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\StreamInsert::$source with single line content, use one-line comment instead.
Loading history...
15
     * @var resource
16
     */
17
    private $source;
18
19
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\StreamInsert::$request with single line content, use one-line comment instead.
Loading history...
20
     * @var CurlerRequest
21
     */
22
    private $request;
23
24
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\StreamInsert::$curlerRolling with single line content, use one-line comment instead.
Loading history...
25
     * @var CurlerRolling
26
     */
27
    private $curlerRolling;
28
29
    /**
30
     * @param resource $source
0 ignored issues
show
Coding Style introduced by
Expected 11 spaces after parameter type; 1 found
Loading history...
31
     * @param CurlerRequest $request
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
introduced by
Method \ClickHouseDB\Transport\StreamInsert::__construct() has useless @param annotation for parameter $request.
Loading history...
32
     * @param CurlerRolling|null $curlerRolling
33
     */
34 4
    public function __construct($source, CurlerRequest $request, $curlerRolling=null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$curlerRolling" and equals sign; expected 1 but found 0
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$curlerRolling"; expected 1 but found 0
Loading history...
introduced by
Method \ClickHouseDB\Transport\StreamInsert::__construct() does not have native type hint for its parameter $curlerRolling but it should be possible to add it based on @param annotation "CurlerRolling|null".
Loading history...
35
    {
36 4
        if (!is_resource($source)) {
0 ignored issues
show
introduced by
Function is_resource() 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...
37
            throw new \InvalidArgumentException('Argument $source must be resource');
0 ignored issues
show
introduced by
Class \InvalidArgumentException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
38
        }
39 4
        if ($curlerRolling instanceof CurlerRolling)
0 ignored issues
show
introduced by
Expected 1 lines after "if", found 0.
Loading history...
40
        {
41 3
            $this->curlerRolling = $curlerRolling;
42
        } else {
43 1
            $this->curlerRolling = new CurlerRolling();
44
        }
45 4
        $this->source = $source;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
46 4
        $this->request = $request;
47 4
    }
48
49
    /**
50
     * @param callable $callback function for stream read data
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
51
     * @return \ClickHouseDB\Statement
0 ignored issues
show
introduced by
Class \ClickHouseDB\Statement should not be referenced via a fully qualified name, but via a use statement.
Loading history...
52
     * @throws \Exception
0 ignored issues
show
introduced by
Class \Exception should not be referenced via a fully qualified name, but via a use statement.
Loading history...
53
     */
54 4
    public function insert($callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\StreamInsert::insert() does not have native type hint for its parameter $callback but it should be possible to add it based on @param annotation "callable".
Loading history...
introduced by
Method \ClickHouseDB\Transport\StreamInsert::insert() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "\ClickHouseDB\Statement".
Loading history...
55
    {
56
        try {
57 4
            if (!is_callable($callback)) {
0 ignored issues
show
introduced by
Function is_callable() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
58 2
                throw new \InvalidArgumentException('Argument $callback can not be called as a function');
0 ignored issues
show
introduced by
Class \InvalidArgumentException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
59
            }
60
61
            //
0 ignored issues
show
introduced by
Empty comment
Loading history...
62 2
            $this->request->header('Transfer-Encoding', 'chunked');
63 2
            $this->request->setReadFunction($callback);
64 2
            $this->curlerRolling->execOne($this->request, true);
65 2
            $statement = new Statement($this->request);
66 2
            $statement->error();
67 2
            return $statement;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
68
        } finally {
69 4
            fclose($this->source);
0 ignored issues
show
introduced by
Function fclose() should not be referenced via a fallback global name, but via a use statement.
Loading history...
70
        }
71
    }
72
}
73