SerializerFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A bySerializedContentType() 0 18 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
}