Completed
Push — master ( 14d1d8...f3cdf4 )
by Beniamin
03:22
created

InExpression   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 84.62%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
c 2
b 0
f 2
lcom 1
cbo 3
dl 0
loc 40
ccs 11
cts 13
cp 0.8462
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A compile() 0 14 3
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\Expression;
13
14
use Phuria\QueryBuilder\ExprBuilder;
15
16
/**
17
 * @author Beniamin Jonatan Šimko <[email protected]>
18
 */
19
class InExpression implements ExpressionInterface
20
{
21
    /**
22
     * @var ExpressionInterface $wrappedExpression
23
     */
24
    private $wrappedExpression;
25
26
    /**
27
     * @var ExpressionInterface $arguments
28
     */
29
    private $arguments;
30
31
    /**
32
     * @param ExpressionInterface $expression
33
     * @param ExpressionInterface $arguments
34
     */
35 1
    public function __construct(ExpressionInterface $expression, ExpressionInterface $arguments)
36
    {
37 1
        $this->wrappedExpression = $expression;
38 1
        $this->arguments = $arguments;
39 1
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44 1
    public function compile()
45
    {
46 1
        $expression = $this->arguments;
47
48 1
        if ($expression instanceof ExprBuilder) {
49
            $expression = $expression->getWrappedExpression();
50
        }
51
52 1
        if ($expression instanceof ExpressionCollection) {
53 1
            $expression = $expression->changeSeparator(', ');
54 1
        }
55
56 1
        return $this->wrappedExpression->compile() . ' IN (' . $expression->compile() . ')';
57
    }
58
}