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

NullSerializer::unserialize()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 2
crap 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