Completed
Push — master ( 439406...4b2726 )
by Hong
03:09
created

HavingTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 59
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A having() 0 7 1
A havingTpl() 0 6 1
A havingRaw() 0 5 1
A buildHaving() 0 4 1
buildWhere() 0 4 ?
realWhere() 0 9 ?
clauseTpl() 0 1 ?
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\WhereInterface;
18
use Phossa2\Query\Interfaces\Clause\HavingInterface;
19
20
/**
21
 * HavingTrait
22
 *
23
 * Implementation of HavingInterface
24
 *
25
 * @package Phossa2\Query
26
 * @author  Hong Zhang <[email protected]>
27
 * @see     HavingInterface
28
 * @version 2.0.0
29
 * @since   2.0.0 added
30
 */
31
trait HavingTrait
32
{
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function having(
37
        $col,
38
        $operator = WhereInterface::NO_OPERATOR,
39
        $value = WhereInterface::NO_VALUE
40
    ) {
41
        return $this->realWhere($col, $operator, $value, true, false, false, 'HAVING');
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    public function havingTpl(/*# string */ $template, $col)
48
    {
49
        return $this->realWhere($this->clauseTpl($template, $col),
50
            WhereInterface::NO_OPERATOR, WhereInterface::NO_VALUE,
51
            true, false, true, 'HAVING');
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57
    public function havingRaw(/*# string */ $rawString)
58
    {
59
        return $this->realWhere($rawString, WhereInterface::NO_OPERATOR,
60
            WhereInterface::NO_VALUE, true, false, true, 'HAVING');
61
    }
62
63
    /**
64
     * Build HAVING
65
     *
66
     * @param  array $settings
67
     * @return string
68
     * @access protected
69
     */
70
    protected function buildHaving(array $settings)/*# : string */
71
    {
72
        return $this->buildWhere($settings, 'HAVING');
73
    }
74
75
    abstract protected function buildWhere(
76
        array $settings,
77
        /*# string */ $clause = 'WHERE'
78
    )/*# : array */;
79
    abstract protected function realWhere(
80
        $col,
81
        $operator = WhereInterface::NO_OPERATOR,
82
        $value    = WhereInterface::NO_VALUE,
83
        /*# bool */ $logicAnd = true,
84
        /*# bool */ $whereNot = false,
85
        /*# bool */ $rawMode  = false,
86
        /*# string */ $clause = 'WHERE'
87
    );
88
    abstract protected function clauseTpl(/*# string */ $template, $col)/*# : string */;
89
}
90