Completed
Push — master ( c1ad5e...1443d8 )
by Peter
08:22
created

CriteriaArray   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 45.45%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 22
ccs 5
cts 11
cp 0.4545
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromModel() 0 7 1
A toModel() 0 8 1
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 https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Transformers;
15
16
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
17
use Maslosoft\Mangan\AspectManager;
18
use Maslosoft\Mangan\Interfaces\Transformators\TransformatorInterface;
19
20
/**
21
 * Criteria array transformer
22
 *
23
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
24
 */
25
class CriteriaArray extends Transformer implements TransformatorInterface
26
{
27
	const AspectCriteriaArrayFromModel = 'AspectCriteriaArrayFromModel';
28
	const AspectCriteriaArrayToModel = 'AspectCriteriaArrayToModel';
29
30 119
	public static function fromModel(AnnotatedInterface $model, $fields = [])
31
	{
32 119
		AspectManager::addAspect($model, self::AspectCriteriaArrayFromModel);
33 119
		$data = parent::fromModel($model, $fields);
34 119
		AspectManager::removeAspect($model, self::AspectCriteriaArrayFromModel);
35 119
		return $data;
36
	}
37
38
	public static function toModel($data, $className = null, AnnotatedInterface $instance = null, AnnotatedInterface $parent = null, $parentField = '')
39
	{
40
		AspectManager::addAspect($instance, self::AspectCriteriaArrayToModel);
41
		$model = parent::toModel($data, $className, $instance, $parent, $parentField);
42
		AspectManager::removeAspect($instance, self::AspectCriteriaArrayToModel);
43
		AspectManager::removeAspect($model, self::AspectCriteriaArrayToModel);
44
		return $model;
45
	}
46
}
47