Completed
Push — master ( 226980...c1625e )
by Hong
02:50
created

PartitionTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A partition() 0 6 1
A buildPartition() 0 12 2
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\Clause\PartitionInterface;
18
19
/**
20
 * PartitionTrait
21
 *
22
 * Implementation of PartitionInterface
23
 *
24
 * @package Phossa2\Query
25
 * @author  Hong Zhang <[email protected]>
26
 * @see     PartitionInterface
27
 * @version 2.0.0
28
 * @since   2.0.0 added
29
 */
30
trait PartitionTrait
31
{
32
    /**
33
     * {@inheritDoc}
34
     */
35
    public function partition($partitionNames)
36
    {
37
        $clause = &$this->getClause('PARTITION');
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...
38
        $clause = (array) $partitionNames;
39
        return $this;
40
    }
41
42
    /**
43
     * Build PARTITION
44
     *
45
     * @param  string $prefix
46
     * @param  array $settings
47
     * @return string
48
     * @access protected
49
     */
50
    protected function buildPartition(
51
        /*# string */ $prefix,
52
        array $settings
53
    )/*# : string */ {
54
        $sepr = $settings['seperator'];
55
        $clause = &$this->getClause('PARTITION');
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...
56
        if (empty($clause)) {
57
            return '';
58
        } else {
59
            return $sepr . $prefix . ' (' . join(', ', $clause) . ')';
60
        }
61
    }
62
}
63