Completed
Push — master ( 971f99...10707b )
by Peter
07:20 queued 02:39
created

Datamatrix   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 31
ccs 3
cts 6
cp 0.5
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromModel() 0 5 1
A toModel() 0 5 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 http://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Transformers;
15
16
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
17
use Maslosoft\Mangan\Exceptions\TransformatorException;
18
use Maslosoft\Mangan\Interfaces\Transformators\TransformatorInterface;
19
20
/**
21
 * Datamatrix
22
 *
23
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
24
 */
25
class Datamatrix implements TransformatorInterface
26
{
27
28
	/**
29
	 * Returns the given object as an associative array
30
	 * @param AnnotatedInterface|object $model
31
	 * @param string[] $fields Fields to transform
32
	 * @return array an associative array of the contents of this object
33
	 */
34 2
	public static function fromModel(AnnotatedInterface $model, $fields = [])
35
	{
36 2
		$data = YamlString::fromModel($model, $fields, 1, 1);
37 2
		return (new \Dmtx\Writer())->encode($data)->dump();
38
	}
39
40
	/**
41
	 * Create document from array
42
	 *
43
	 * @param mixed[] $data
44
	 * @param string|object $className
45
	 * @param AnnotatedInterface $instance
46
	 * @return AnnotatedInterface
47
	 * @throws TransformatorException
48
	 */
49
	public static function toModel($data, $className = null, AnnotatedInterface $instance = null)
50
	{
51
		$data = (new \Dmtx\Reader())->decode($data);
52
		return YamlString::toModel($data, $className, $instance);
53
	}
54
55
}
56