StringToObjectConverter::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 10
rs 10
cc 3
nc 2
nop 1
1
<?php
2
3
namespace Jackal\Copycat\Converter\ValueConverter;
4
5
/**
6
 * Class StringToObjectConverter
7
 * @package Jackal\Copycat\Converter\ValueConverter
8
 */
9
class StringToObjectConverter extends AbstractConverter
10
{
11
    /**
12
     * @param $value
13
     * @return mixed
14
     */
15
    public function __invoke($value)
16
    {
17
        $object = @unserialize($value[$this->fieldName]);
18
19
        if($object === false and $value[$this->fieldName] !== serialize(false)){
20
            throw new \RuntimeException('Error converting string to object.');
21
        }
22
        $value[$this->fieldName] = $object;
23
24
        return $value;
25
    }
26
}
27