SerializerFactory::bySerializedContentType()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 18
ccs 14
cts 14
cp 1
rs 9.2
cc 4
eloc 14
nc 4
nop 1
crap 4
1
<?php
2
3
4
namespace Retrinko\Serializer;
5
6
use Retrinko\Serializer\Exceptions\Exception;
7
use Retrinko\Serializer\Interfaces\SerializerInterface;
8
use Retrinko\Serializer\Serializers\JsonSerializer;
9
use Retrinko\Serializer\Serializers\NullSerializer;
10
use Retrinko\Serializer\Serializers\PhpSerializer;
11
12
class SerializerFactory
13
{
14
15
    /**
16
     * Creates a Serializer for the given content type.
17
     * 
18
     * @param string $contentType
19
     * @return SerializerInterface
20
     * @throws \Exception
21
     */
22 4
    public static function bySerializedContentType($contentType)
23
    {
24
        switch($contentType)
25
        {
26 4
            case PhpSerializer::SERIALIZED_CONTENT_TYPE:
27 1
                $serializer = new PhpSerializer();
28 1
                break;
29 3
            case JsonSerializer::SERIALIZED_CONTENT_TYPE:
30 1
                $serializer = new JsonSerializer();
31 1
                break;
32 2
            case NullSerializer::SERIALIZED_CONTENT_TYPE:
33 1
                $serializer = new NullSerializer();
34 1
                break;
35 1
            default:
36 1
                throw new Exception('Not supported content type!');
37 1
        }
38 3
        return $serializer;
39
    }
40
41
42
}