Completed
Push — master ( f579b8...c5e777 )
by Thomas
07:12 queued 02:33
created

ModuleSerializerTrait::package()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
namespace keeko\core\serializer\base;
3
4
use keeko\framework\utils\HydrateUtils;
5
6
/**
7
 */
8
trait ModuleSerializerTrait {
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
			'class_name' => $model->ClassName(),
17
			'activated_version' => $model->ActivatedVersion(),
18
			'default_action' => $model->DefaultAction(),
19
			'slug' => $model->Slug(),
20
			'has_api' => $model->Api(),
21
			'id' => $model->Id(),
22
			'name' => $model->Name(),
23
			'title' => $model->Title(),
24
			'description' => $model->Description(),
25
			'installed_version' => $model->InstalledVersion(),
26
		];
27
	}
28
29
	/**
30
	 */
31
	public function getFields() {
32
		return ['class_name', 'activated_version', 'default_action', 'slug', 'has_api', 'id', 'name', 'title', 'description', 'installed_version'];
33
	}
34
35
	/**
36
	 * @param mixed $model
37
	 */
38
	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...
39
		return $model->getId();
40
	}
41
42
	/**
43
	 */
44
	public function getRelationships() {
45
		return [
46
		];
47
	}
48
49
	/**
50
	 */
51
	public function getSortFields() {
52
		return ['class_name', 'activated_version', 'default_action', 'slug', 'has_api', 'id', 'name', 'title', 'description', 'installed_version'];
53
	}
54
55
	/**
56
	 * @param mixed $model
57
	 */
58
	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...
59
		return 'core/module';
60
	}
61
62
	/**
63
	 * @param mixed $model
64
	 * @param mixed $data
65
	 */
66
	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...
67
		// attributes
68
		$attribs = isset($data['attributes']) ? $data['attributes'] : [];
69
70
		$model = HydrateUtils::hydrate($attribs, $model, ['class_name', 'activated_version', 'default_action', 'slug', 'has_api', 'id', 'name', 'title', 'description', 'installed_version']);
71
72
		// relationships
73
		$this->hydrateRelationships($model, $data);
0 ignored issues
show
Bug introduced by
The method hydrateRelationships() does not exist on keeko\core\serializer\base\ModuleSerializerTrait. 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...
74
75
		return $model;
76
	}
77
}
78