Code Duplication    Length = 45-45 lines in 2 locations

lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php 1 location

@@ 31-75 (lines=45) @@
28
     * @override
29
     * @inheritdoc
30
     */
31
    public function getSql(SqlWalker $sqlWalker)
32
    {
33
        switch (strtolower($this->unit->value)) {
34
            case 'second':
35
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddSecondsExpression(
36
                    $this->firstDateExpression->dispatch($sqlWalker),
37
                    $this->intervalExpression->dispatch($sqlWalker)
38
                );
39
            case 'minute':
40
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddMinutesExpression(
41
                    $this->firstDateExpression->dispatch($sqlWalker),
42
                    $this->intervalExpression->dispatch($sqlWalker)
43
                );
44
            case 'hour':
45
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddHourExpression(
46
                    $this->firstDateExpression->dispatch($sqlWalker),
47
                    $this->intervalExpression->dispatch($sqlWalker)
48
                );
49
            case 'day':
50
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddDaysExpression(
51
                    $this->firstDateExpression->dispatch($sqlWalker),
52
                    $this->intervalExpression->dispatch($sqlWalker)
53
                );
54
            case 'week':
55
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddWeeksExpression(
56
                    $this->firstDateExpression->dispatch($sqlWalker),
57
                    $this->intervalExpression->dispatch($sqlWalker)
58
                );
59
            case 'month':
60
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddMonthExpression(
61
                    $this->firstDateExpression->dispatch($sqlWalker),
62
                    $this->intervalExpression->dispatch($sqlWalker)
63
                );
64
            case 'year':
65
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddYearsExpression(
66
                    $this->firstDateExpression->dispatch($sqlWalker),
67
                    $this->intervalExpression->dispatch($sqlWalker)
68
                );
69
70
            default:
71
                throw QueryException::semanticalError(
72
                    'DATE_ADD() only supports units of type second, minute, hour, day, week, month and year.'
73
                );
74
        }
75
    }
76
77
    /**
78
     * @override

lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php 1 location

@@ 25-69 (lines=45) @@
22
     * @override
23
     * @inheritdoc
24
     */
25
    public function getSql(SqlWalker $sqlWalker)
26
    {
27
        switch (strtolower($this->unit->value)) {
28
            case 'second':
29
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubSecondsExpression(
30
                    $this->firstDateExpression->dispatch($sqlWalker),
31
                    $this->intervalExpression->dispatch($sqlWalker)
32
                );
33
            case 'minute':
34
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubMinutesExpression(
35
                    $this->firstDateExpression->dispatch($sqlWalker),
36
                    $this->intervalExpression->dispatch($sqlWalker)
37
                );
38
            case 'hour':
39
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubHourExpression(
40
                    $this->firstDateExpression->dispatch($sqlWalker),
41
                    $this->intervalExpression->dispatch($sqlWalker)
42
                );
43
            case 'day':
44
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubDaysExpression(
45
                    $this->firstDateExpression->dispatch($sqlWalker),
46
                    $this->intervalExpression->dispatch($sqlWalker)
47
                );
48
            case 'week':
49
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubWeeksExpression(
50
                    $this->firstDateExpression->dispatch($sqlWalker),
51
                    $this->intervalExpression->dispatch($sqlWalker)
52
                );
53
            case 'month':
54
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubMonthExpression(
55
                    $this->firstDateExpression->dispatch($sqlWalker),
56
                    $this->intervalExpression->dispatch($sqlWalker)
57
                );
58
            case 'year':
59
                return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubYearsExpression(
60
                    $this->firstDateExpression->dispatch($sqlWalker),
61
                    $this->intervalExpression->dispatch($sqlWalker)
62
                );
63
64
            default:
65
                throw QueryException::semanticalError(
66
                    'DATE_SUB() only supports units of type second, minute, hour, day, week, month and year.'
67
                );
68
        }
69
    }
70
}
71