StringQuerySerializer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 27
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isSerializerFor() 0 3 2
A getSerialized() 0 3 1
A serialize() 0 10 2
1
<?php
2
3
namespace WikidataQueryApi\Query\Serializers;
4
5
use Serializers\DispatchableSerializer;
6
use Serializers\Exceptions\UnsupportedObjectException;
7
use WikidataQueryApi\Query\StringQuery;
8
9
/**
10
 * @licence GPLv2+
11
 * @author Thomas Pellissier Tanon
12
 */
13
class StringQuerySerializer implements DispatchableSerializer {
14
15
	/**
16
	 * @see DispatchableSerializer::isSerializerFor
17
	 */
18 8
	public function isSerializerFor( $object ) {
19 8
		return is_object( $object ) && $object instanceof StringQuery;
20
	}
21
22
	/**
23
	 * @see Serializer::serialize
24
	 */
25 4
	public function serialize( $object ) {
26 4
		if ( !$this->isSerializerFor( $object ) ) {
27 3
			throw new UnsupportedObjectException(
28 3
				$object,
29
				'StringQuerySerializer can only serialize StringQuery objects'
30 3
			);
31
		}
32
33 1
		return $this->getSerialized( $object );
34
	}
35
36 1
	private function getSerialized( StringQuery $query ) {
37 1
		return 'string[' . $query->getPropertyId()->getNumericId() . ':"' . $query->getStringValue()->getValue() . '"]';
38
	}
39
}
40