UnknownResourceNodeSerializer::serialize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
nc 2
cc 2
eloc 4
nop 1
crap 2
1
<?php
2
3
namespace PPP\DataModel\Serializers;
4
5
use PPP\DataModel\UnknownResourceNode;
6
use Serializers\Exceptions\UnsupportedObjectException;
7
8
/**
9
 * @licence MIT
10
 * @author Thomas Pellissier Tanon
11
 */
12
class UnknownResourceNodeSerializer extends BasicResourceNodeSerializer {
13
14 9
	public function __construct() {
15 9
		parent::__construct('resource', 'type');
0 ignored issues
show
Unused Code introduced by
The call to BasicResourceNodeSerializer::__construct() has too many arguments starting with 'type'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
16 9
	}
17
18
	/**
19
	 * @see DispatchableSerializer::isSerializerFor
20
	 */
21 8
	public function isSerializerFor($object) {
22 8
		return is_object($object) && $object instanceof UnknownResourceNode;
23
	}
24
25
	/**
26
	 * @see Serializer::serialize
27
	 * @param UnknownResourceNode $object
28
	 */
29 4
	public function serialize($object) {
30 4
		if(!$this->isSerializerFor($object)) {
31 3
			throw new UnsupportedObjectException($object, 'UnkownResourceNodeSerializer can only serialize UnknownResourceNode objects.');
32
		}
33
34 1
		return $object->getProperties();
35
	}
36
}
37