Passed
Push — master ( 8807b4...37e483 )
by Wilmer
03:08
created

BaseQueryBuilderProvider::buildFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 57
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 38
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 57
rs 9.312

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\Provider;
6
7
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
8
use Yiisoft\Db\Expression\Expression;
9
use Yiisoft\Db\Tests\Support\DbHelper;
10
11
final class BaseQueryBuilderProvider
12
{
13
    public function buildFrom(ConnectionPDOInterface $db): array
14
    {
15
        return [
16
            [
17
                'table1',
18
                DbHelper::replaceQuotes(
19
                    <<<SQL
20
                    SELECT * FROM [[table1]]
21
                    SQL,
22
                    $db->getname(),
23
                ),
24
            ],
25
            [
26
                ['table1'],
27
                DbHelper::replaceQuotes(
28
                    <<<SQL
29
                    SELECT * FROM [[table1]]
30
                    SQL,
31
                    $db->getname(),
32
                ),
33
            ],
34
            [
35
                new Expression('table2'),
36
                <<<SQL
37
                SELECT * FROM table2
38
                SQL,
39
            ],
40
            [
41
                [new Expression('table2')],
42
                <<<SQL
43
                SELECT * FROM table2
44
                SQL,
45
            ],
46
            [
47
                ['alias' => 'table3'],
48
                DbHelper::replaceQuotes(
49
                    <<<SQL
50
                    SELECT * FROM [[table3]] [[alias]]
51
                    SQL,
52
                    $db->getname(),
53
                ),
54
            ],
55
            [
56
                ['alias' => new Expression('table4')],
57
                <<<SQL
58
                SELECT * FROM table4 [alias]
59
                SQL,
60
            ],
61
            [
62
                ['alias' => new Expression('func(:param1, :param2)', ['param1' => 'A', 'param2' => 'B'])],
63
                DbHelper::replaceQuotes(
64
                    <<<SQL
65
                    SELECT * FROM func(:param1, :param2) [[alias]]
66
                    SQL,
67
                    $db->getname(),
68
                ),
69
                ['param1' => 'A', 'param2' => 'B'],
70
            ],
71
        ];
72
    }
73
}
74