Completed
Push — master ( 1cbd4f...6f70d1 )
by Beniamin
07:58
created

DateTimeTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 16.66%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 49
ccs 2
cts 12
cp 0.1666
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
func() 0 1 ?
getWrappedExpression() 0 1 ?
A addDate() 0 7 1
A addTime() 0 7 1
A year() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\QueryBuilder\ExprBuilder;
13
14
use Phuria\QueryBuilder\ExprBuilder;
15
use Phuria\QueryBuilder\Expression\ExpressionInterface;
16
use Phuria\QueryBuilder\Expression\FunctionCallContext;
17
use Phuria\QueryBuilder\Expression\FunctionExpression;
18
use Phuria\QueryBuilder\ExprNormalizer;
19
20
/**
21
 * @author Beniamin Jonatan Šimko <[email protected]>
22
 */
23
trait DateTimeTrait
24
{
25
    /**
26
     * @param string                   $functionName
27
     * @param FunctionCallContext|null $context
28
     *
29
     * @return ExprBuilder
30
     */
31
    abstract public function func($functionName, FunctionCallContext $context = null);
32
33
    /**
34
     * @return ExpressionInterface
35
     */
36
    abstract public function getWrappedExpression();
37
38
    /**
39
     * @param mixed $expression
40
     *
41
     * @return ExprBuilder
42
     */
43
    public function addDate($expression)
44
    {
45
        return new ExprBuilder(new FunctionExpression(
46
            FunctionExpression::FUNC_ADDDATE,
47
            ExprNormalizer::normalizeExpression([$this->getWrappedExpression(), $expression])
48
        ));
49
    }
50
51
    /**
52
     * @param mixed $expression
53
     *
54
     * @return ExprBuilder
55
     */
56
    public function addTime($expression)
57
    {
58
        return new ExprBuilder(new FunctionExpression(
59
            FunctionExpression::FUNC_ADDTIME,
60
            ExprNormalizer::normalizeExpression([$this->getWrappedExpression(), $expression])
61
        ));
62
    }
63
64
    /**
65
     * @return ExprBuilder
66
     */
67 1
    public function year()
68
    {
69 1
        return $this->func(FunctionExpression::FUNC_YEAR);
70
    }
71
}