Using   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
dl 0
loc 45
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1
ccs 15
cts 16
cp 0.9375
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toString() 0 14 2
A convertToArray() 0 14 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Puzzle\QueryBuilder\Queries\Snippets;
6
7
use Puzzle\QueryBuilder\Snippet;
8
use Puzzle\Pieces\StringManipulation;
9
10
class Using implements Snippet
11
{
12
    use StringManipulation;
13
14
    private
15
        $columns;
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $columns.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
16
17
    /**
18
     * @param array[string]|string $column
0 ignored issues
show
Documentation introduced by
The doc-type array[string]|string could not be parsed: Expected "]" at position 2, but found "string". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
19
     */
20 14
    public function __construct($column)
21
    {
22 14
        $this->columns = $this->convertToArray($column);
23 14
    }
24
25 14
    public function toString(): string
26
    {
27 14
        $usingColumns = implode(', ', array_filter($this->columns));
28
29 14
        if(empty($usingColumns))
30
        {
31 2
            return '';
32
        }
33
34 12
        return sprintf(
35 12
            'USING (%s)',
36 12
            $usingColumns
37
        );
38
    }
39
40 14
    private function convertToArray($input): array
41
    {
42 14
        if(! is_array($input))
43
        {
44 12
            if(! $this->isConvertibleToString($input))
45
            {
46
                throw new \InvalidArgumentException("Using argument must be a string (or an array of string)");
47
            }
48
49 12
            $input = array($input);
50
        }
51
52 14
        return $input;
53
    }
54
}
55