CollectionCriteria::asMongoObject()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6667
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the SmartGecko(c) business platform.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Governor\Framework\EventStore\Mongo\Criteria;
10
11
12
/**
13
 * Implementation of Collection operators for the Mongo Criteria, such as "In" and "NotIn".
14
 *
15
 * @author Allard Buijze
16
 * @since 2.0
17
 */
18
class CollectionCriteria extends MongoCriteria
19
{
20
21
    /**
22
     * @var MongoProperty
23
     */
24
    private $property;
25
    /**
26
     * @var mixed
27
     */
28
    private $expression;
29
    /**
30
     * @var string
31
     */
32
    private $operator;
33
34
    /**
35
     * Returns a criterion that requires the given <code>property</code> value to be present in the given
36
     * <code>expression</code> to evaluate to <code>true</code>.
37
     *
38
     * @param MongoProperty $property The property to match
39
     * @param string $operator The collection operator to use
40
     * @param mixed $expression The expression to that expresses the collection to match against the property
41
     */
42 3
    public function __construct(MongoProperty $property, $operator, $expression)
43
    {
44 3
        $this->property = $property;
45 3
        $this->expression = $expression;
46 3
        $this->operator = $operator;
47 3
    }
48
49
50 3
    public function asMongoObject()
51
    {
52
        return [
53 3
            $this->property->getName() => [
54 3
                $this->operator => $this->expression
55 3
            ]
56 3
        ];
57
58
    }
59
}