Completed
Push — master ( 76c0f1...a16dbf )
by Christian
01:43
created

ProfileTransformer::stringToProfile()   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
/*
4
 * This file is part of the XabbuhPandaClient package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
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 Xabbuh\PandaClient\Transformer;
13
14
use Symfony\Component\HttpFoundation\ParameterBag;
15
use Xabbuh\PandaClient\Model\Profile;
16
17
/**
18
 * Transform various data representation formats into profiles and vice versa.
19
 *
20
 * @author Christian Flothmann <[email protected]>
21
 */
22
class ProfileTransformer extends BaseTransformer implements ProfileTransformerInterface
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27 1
    public function stringToProfile($jsonString)
28
    {
29 1
        return $this->serializer->deserialize($jsonString, 'Profile');
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     */
35 1
    public function stringToProfileCollection($jsonString)
36
    {
37 1
        return $this->serializer->deserialize($jsonString, 'Profile');
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    public function toRequestParams(Profile $profile)
44
    {
45
        $params = new ParameterBag();
46
47
        foreach (get_class_methods(get_class($profile)) as $method) {
48
            if ('get' === substr($method, 0, 3)) {
49
                $property = strtolower(preg_replace(
50
                    '/([a-z])([A-Z])/',
51
                    '\$1_\$2',
52
                    substr($method, 3)
53
                ));
54
                $params->set($property, $profile->$method());
55
            }
56
        }
57
58
        return $params;
59
    }
60
}
61