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

DateTimeTrait::addTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 2
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
}