Completed
Push — master ( 25abba...3dbe2e )
by Peter
06:50
created

RawFinder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 90%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 38
ccs 9
cts 10
cp 0.9
rs 10
c 2
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A create() 0 4 1
A populateRecord() 0 4 1
A createModel() 0 8 2
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link http://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Helpers;
15
16
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
17
use Maslosoft\Mangan\Exceptions\ManganException;
18
use Maslosoft\Mangan\Finder;
19
use Maslosoft\Mangan\Interfaces\EntityManagerInterface;
20
use Maslosoft\Mangan\Interfaces\FinderInterface;
21
use Maslosoft\Mangan\Mangan;
22
23
/**
24
 * Finder variant which returns raw arrays.
25
 * For internal or special cases use.
26
 *
27
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
28
 */
29
class RawFinder extends Finder
30
{
31
32 5
	public function __construct($model, $em = null)
33
	{
34 5
		parent::__construct($model, $em);
35
		// Cannot use cursors in raw finder, as it will clash with PkManager
36 5
		$this->withCursor(false);
37 5
	}
38
39
	/**
40
	 * Create raw finder instance.
41
	 *
42
	 * @param AnnotatedInterface $model
43
	 * @param EntityManagerInterface $em
44
	 * @param Mangan $mangan
45
	 * @return FinderInterface
46
	 */
47
	public static function create(AnnotatedInterface $model, $em = null, Mangan $mangan = null)
48
	{
49
		return new static($model, $em, $mangan);
0 ignored issues
show
Unused Code introduced by
The call to RawFinder::__construct() has too many arguments starting with $mangan.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
50
	}
51
52 5
	protected function populateRecord($data)
53
	{
54 5
		return $this->createModel($data);
55
	}
56
57 5
	protected function createModel($data)
58
	{
59 5
		if (!empty($data['$err']))
60
		{
61
			throw new ManganException(sprintf("There is an error in query: %s", $data['$err']));
62
		}
63 5
		return $data;
64
	}
65
66
}
67