Completed
Push — master ( 63d3cc...fb2a6e )
by Peter
06:57
created

SimpleTermDecorator::useWith()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
crap 3
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/manganel
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 * @link https://maslosoft.com/manganel/
11
 */
12
13
namespace Maslosoft\Manganel\Decorators\QueryBuilder\Operators;
14
15
use Maslosoft\Manganel\Interfaces\QueryBuilder\OperatorDecoratorInterface;
16
use MongoId;
17
18
/**
19
 * SimpleTermDecorator
20
 * TODO Should return `term`
21
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
22
 */
23
class SimpleTermDecorator implements OperatorDecoratorInterface
24
{
25
26 31
	public function useWith($key, $value)
27
	{
28
		// Do not use with $* operators
29 31
		if (strpos($key, '$') === 0)
30
		{
31 5
			return false;
32
		}
33
		// Special case for mongo id...
34 27
		if ($value instanceof MongoId)
35
		{
36 6
			return true;
37
		}
38
		// Use only with simple values
39 24
		return is_scalar($value);
40
	}
41
42 19
	public function decorate(&$condition, $name, $value)
43
	{
44
		$condition = [
45
			'term' => [
46 19
				$name => $value
47
			]
48
		];
49 19
	}
50
51
}
52