AbstractSerializer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ensureType() 0 14 4
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Core\Serializer;
13
14
/**
15
 * AbstractSerializer class.
16
 *
17
 * @author Ivannis Suárez Jerez <[email protected]>
18
 */
19
abstract class AbstractSerializer implements SerializerInterface
20
{
21
    /**
22
     * @param string $value
23
     *
24
     * @throws \InvalidArgumentException
25
     */
26
    public function ensureType($value)
27
    {
28
        if (is_object($value)) {
29
            if (!$value instanceof SerializableInterface) {
30
                throw new \InvalidArgumentException(
31
                    sprintf(
32
                        'The object must be an instance of %s. Instance of %s given',
33
                        SerializableInterface::class,
34
                        is_object($value) ? get_class($value) : gettype($value)
35
                    )
36
                );
37
            }
38
        }
39
    }
40
}
41