SimpleTermDecorator::useWith()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 4
cts 6
cp 0.6667
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3.3332
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL-3.0-only, proprietary` license[s].
5
 *
6
 * @package maslosoft/manganel
7
 * @license AGPL-3.0-only, proprietary
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 3
	public function useWith($key, $value)
27
	{
28
		// Do not use with $* operators
29 3
		if (strpos($key, '$') === 0)
30
		{
31
			return false;
32
		}
33
		// Special case for mongo id...
34 3
		if ($value instanceof MongoId)
35
		{
36
			return true;
37
		}
38
		// Use only with simple values
39 3
		return is_scalar($value);
40
	}
41
42 3
	public function decorate(&$condition, $name, $value)
43
	{
44
		$condition = [
45
			'term' => [
46 3
				$name => $value
47
			]
48
		];
49 3
	}
50
51
}
52