Completed
Push — 2.0 ( 1160ec...acba87 )
by Vermeulen
05:15
created

OrderList   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 44
loc 44
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 4 4 1
A generate() 14 14 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace BfwSql\Queries\Parts;
4
5 View Code Duplication
class OrderList extends AbstractList
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    protected $partPrefix = 'ORDER BY';
11
    
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected $separator = ',';
16
    
17
    /**
18
     * Magic method __invoke, used when the user call object like a function
19
     * @link http://php.net/manual/en/language.oop5.magic.php#object.invoke
20
     * 
21
     * @param string $expr The expression to use into the order
22
     * @param string $sort The sort order : ASC or DESC
23
     * 
24
     * @return void
25
     */
26
    public function __invoke(string $expr, $sort = 'ASC')
27
    {
28
        $this->list[] = new Order($expr, $sort);
29
    }
30
    
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function generate(): string
35
    {
36
        $sqlPart = '';
37
        
38
        foreach ($this->list as $index => $order) {
39
            if ($index > 0) {
40
                $sqlPart .= $this->separator;
41
            }
42
            
43
            $sqlPart .= $order->generate();
44
        }
45
        
46
        return $sqlPart;
47
    }
48
}
49