Code Duplication    Length = 39-44 lines in 2 locations

src/Queries/Parts/OrderList.php 1 location

@@ 5-48 (lines=44) @@
2
3
namespace BfwSql\Queries\Parts;
4
5
class OrderList extends AbstractList
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

src/Queries/Parts/SubQueryList.php 1 location

@@ 5-43 (lines=39) @@
2
3
namespace BfwSql\Queries\Parts;
4
5
class SubQueryList extends AbstractList
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    protected $separator = ',';
11
    
12
    /**
13
     * Magic method __invoke, used when the user call object like a function
14
     * @link http://php.net/manual/en/language.oop5.magic.php#object.invoke
15
     * 
16
     * @param string $shortcut The shortcut to use into the request
17
     * @param string|\BfwSql\Queries\AbstractQuery $subQuery The sub-query
18
     * 
19
     * @return void
20
     */
21
    public function __invoke(string $shortcut, $subQuery)
22
    {
23
        $this->list[] = new SubQuery($shortcut, $subQuery);
24
    }
25
    
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function generate(): string
30
    {
31
        $sqlPart = '';
32
        
33
        foreach ($this->list as $index => $subQuery) {
34
            if ($index > 0) {
35
                $sqlPart .= $this->separator;
36
            }
37
            
38
            $sqlPart .= $subQuery->generate();
39
        }
40
        
41
        return $sqlPart;
42
    }
43
}
44