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

NullSerializer::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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