Completed
Push — master ( ec290c...798422 )
by Peter
05:30
created

MongoAdapter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A count() 0 4 1
A findMany() 0 4 1
A findOne() 0 4 1
1
<?php
2
3
namespace Maslosoft\Mangan\Adapters\Finder;
4
5
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
6
use Maslosoft\Mangan\EntityManager;
7
use Maslosoft\Mangan\Interfaces\Adapters\FinderAdapterInterface;
8
use Maslosoft\Mangan\Interfaces\CriteriaInterface;
9
use Maslosoft\Mangan\Interfaces\EntityManagerInterface;
10
use Maslosoft\Mangan\Mangan;
11
12
/**
13
 *
14
 * @internal This is adapter for mongo finder, do not use directly
15
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
16
 */
17
class MongoAdapter implements FinderAdapterInterface
18
{
19
20
	/**
21
	 * Entity manager instance
22
	 * @var EntityManagerInterface
23
	 */
24
	private $em = null;
25
26 69
	public function __construct(AnnotatedInterface $model, Mangan $mangan, EntityManagerInterface $em = null)
27
	{
28 69
		$this->em = $em ?: EntityManager::create($model, $mangan);
29 69
	}
30
31 19
	public function count(CriteriaInterface $criteria)
32
	{
33 19
		return $this->em->getCollection()->count($criteria->getConditions());
34
	}
35
36 24
	public function findMany(CriteriaInterface $criteria, $fields = [])
37
	{
38 24
		return $this->em->getCollection()->find($criteria->getConditions(), $fields);
39
	}
40
41 52
	public function findOne(CriteriaInterface $criteria, $fields = [])
42
	{
43 52
		return $this->em->getCollection()->findOne($criteria->getConditions(), $fields);
44
	}
45
46
}
47