Completed
Push — master ( 8fbfe7...114d8e )
by Tomasz
03:40
created

NullSerializer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 24
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 4 1
A unserialize() 0 7 3
1
<?php
2
3
namespace Gendoria\CommandQueue\Serializer;
4
5
use Gendoria\CommandQueue\Command\CommandInterface;
6
use InvalidArgumentException;
7
8
/**
9
 * This class creates command data with no serialization at all.
10
 *
11
 * @author Tomasz Struczyński <[email protected]>
12
 */
13
class NullSerializer implements SerializerInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 1
    public function serialize(CommandInterface $command)
19
    {
20 1
        return new SerializedCommandData($command, get_class($command));
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     * 
26
     * @throws InvalidArgumentException Thrown, when "serialized" data is not an instance of correct command class.
27
     */
28 3
    public function unserialize($serializedCommandData, $commandClass)
29
    {
30 3
        if (!is_object($serializedCommandData) || !$serializedCommandData instanceof $commandClass) {
31 2
            throw new InvalidArgumentException("Null serializer accepts only commands as serialized command data.");
32
        }
33 1
        return $serializedCommandData;
34
    }
35
36
}
37