FinalizingManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 31
ccs 8
cts 12
cp 0.6667
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromModel() 0 15 3
A toModel() 0 10 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 https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Helpers\Finalizer;
15
16
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
17
use Maslosoft\Gazebo\PluginFactory;
18
use Maslosoft\Mangan\Interfaces\ArrayFinalizerInterface;
19
use Maslosoft\Mangan\Interfaces\ModelFinalizerInterface;
20
use Maslosoft\Mangan\Mangan;
21
22
/**
23
 * FinalizingManager
24
 *
25
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
26
 */
27
class FinalizingManager
28
{
29
30 165
	public static function fromModel($data, $transformerClass, AnnotatedInterface $model)
31
	{
32 165
		$finalizers = Mangan::fromModel($model)->finalizers;
33
34 165
		if (!empty($finalizers))
35
		{
36
			$plugins = PluginFactory::fly()->instance($finalizers, $transformerClass, ModelFinalizerInterface::class);
37
			foreach ($plugins as $finalizer)
38
			{
39
				/* @var $finalizer ModelFinalizerInterface */
40
				$finalizer->fromModel($data);
41
			}
42
		}
43 165
		return $data;
44
	}
45
46 116
	public static function toModel($transformerClass, AnnotatedInterface $model)
47
	{
48 116
		$plugins = PluginFactory::fly()->instance(Mangan::fromModel($model)->finalizers, $transformerClass, ModelFinalizerInterface::class);
49 116
		foreach ($plugins as $finalizer)
50
		{
51
			/* @var $finalizer ArrayFinalizerInterface */
52
			$finalizer->toModel($model);
53
		}
54 116
		return $model;
55
	}
56
57
}
58