Completed
Push — master ( f56a01...af237a )
by Hong
02:39
created

UnionTrait::unionAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Query
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Query\Traits\Clause;
16
17
use Phossa2\Query\Interfaces\BuilderInterface;
18
use Phossa2\Query\Interfaces\StatementInterface;
19
use Phossa2\Query\Interfaces\Clause\UnionInterface;
20
21
/**
22
 * UnionTrait
23
 *
24
 * Implementation of UnionInterface
25
 *
26
 * @package Phossa2\Query
27
 * @author  Hong Zhang <[email protected]>
28
 * @see     UnionInterface
29
 * @version 2.0.0
30
 * @since   2.0.0 added
31
 */
32
trait UnionTrait
33
{
34
    /**
35
     * {@inheritDoc}
36
     */
37
    public function union()/*# : BuilderInterace */
38
    {
39
        $clause = &$this->getClause('UNION');
0 ignored issues
show
Bug introduced by
It seems like getClause() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
40
        $clause[] = 'UNION';
41
        return $this->getBuilder()->setPrevious($this);
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    public function unionAll()/*# : BuilderInterace */
48
    {
49
        $clause = &$this->getClause('UNION');
0 ignored issues
show
Bug introduced by
It seems like getClause() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
50
        $clause[] = 'UNION ALL';
51
        return $this->getBuilder()->setPrevious($this);
52
    }
53
54
    /**
55
     * Build UNION/UNION ALL
56
     *
57
     * @param  string $prefix
58
     * @param  array $settings
59
     * @return string
60
     * @access protected
61
     */
62
    protected function buildUnion(
63
        /*# string */ $prefix,
0 ignored issues
show
Unused Code introduced by
The parameter $prefix is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
        array $settings
65
    )/*# : string */ {
66
        $clause = &$this->getClause('UNION');
0 ignored issues
show
Bug introduced by
It seems like getClause() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
67
        if (!empty($clause)) {
68
            return $settings['seperator'] . $clause[0];
69
        } else {
70
            return '';
71
        }
72
    }
73
74
    abstract public function setPrevious(StatementInterface $previous = null);
75
    /**
76
     * Return the builder
77
     *
78
     * @return BuilderInterface
79
     * @access public
80
     */
81
    abstract public function getBuilder()/*# : BuilderInterface */;
82
}
83