Completed
Push — master ( a7ae23...b30b3b )
by Thomas
09:53
created

PreferenceSerializerTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 63
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttributes() 0 7 1
A getFields() 0 3 1
A getId() 0 3 1
A getRelationships() 0 4 1
A getSortFields() 0 3 1
A getType() 0 3 1
A hydrate() 0 11 2
1
<?php
2
namespace keeko\core\serializer\base;
3
4
use keeko\framework\utils\HydrateUtils;
5
6
/**
7
 */
8
trait PreferenceSerializerTrait {
9
10
	/**
11
	 * @param mixed $model
12
	 * @param array $fields
13
	 */
14
	public function getAttributes($model, array $fields = null) {
1 ignored issue
show
Unused Code introduced by
The parameter $fields is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
15
		return [
16
			'key' => $model->Key(),
17
			'value' => $model->Value(),
18
			'module_id' => $model->ModuleId(),
19
		];
20
	}
21
22
	/**
23
	 */
24
	public function getFields() {
25
		return ['key', 'value', 'module_id'];
26
	}
27
28
	/**
29
	 * @param mixed $model
30
	 */
31
	public function getId($model) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
32
		return $model->getId();
33
	}
34
35
	/**
36
	 */
37
	public function getRelationships() {
38
		return [
39
		];
40
	}
41
42
	/**
43
	 */
44
	public function getSortFields() {
45
		return ['key', 'value', 'module_id'];
46
	}
47
48
	/**
49
	 * @param mixed $model
50
	 */
51
	public function getType($model) {
1 ignored issue
show
Unused Code introduced by
The parameter $model is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
		return 'core/preference';
53
	}
54
55
	/**
56
	 * @param mixed $model
57
	 * @param mixed $data
58
	 */
59
	public function hydrate($model, $data) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
60
		// attributes
61
		$attribs = isset($data['attributes']) ? $data['attributes'] : [];
62
63
		$model = HydrateUtils::hydrate($attribs, $model, ['key', 'value', 'module_id']);
64
65
		// relationships
66
		$this->hydrateRelationships($model, $data);
0 ignored issues
show
Bug introduced by
The method hydrateRelationships() does not exist on keeko\core\serializer\ba...eferenceSerializerTrait. Did you maybe mean hydrate()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
67
68
		return $model;
69
	}
70
}
71