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

ProfileTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
wmc 5
cbo 3
dl 0
loc 39
ccs 4
cts 14
cp 0.2857
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A stringToProfile() 0 4 1
A stringToProfileCollection() 0 4 1
A toRequestParams() 0 17 3
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