Completed
Push — master ( b1e905...5c0927 )
by Asmir
12s queued 10s
created

BaseTypesHandler::base64EncodedFromXml()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 0
cts 8
cp 0
rs 9.9666
c 0
b 0
f 0
cc 3
nc 2
nop 3
crap 12
1
<?php
2
namespace GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler;
3
4
use JMS\Serializer\Context;
5
use JMS\Serializer\GraphNavigator;
6
use JMS\Serializer\Handler\SubscribingHandlerInterface;
7
use JMS\Serializer\XmlDeserializationVisitor;
8
use JMS\Serializer\XmlSerializationVisitor;
9
10
class BaseTypesHandler implements SubscribingHandlerInterface
11
{
12
13
    public static function getSubscribingMethods()
14
    {
15
        return array(
16
            array(
17
                'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
18
                'format' => 'xml',
19
                'type' => 'GoetasWebservices\Xsd\XsdToPhp\Jms\SimpleListOf',
20
                'method' => 'simpleListOfToXml'
21
            ),
22
            array(
23
                'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
24
                'format' => 'xml',
25
                'type' => 'GoetasWebservices\Xsd\XsdToPhp\Jms\SimpleListOf',
26
                'method' => 'simpleListOfFromXML'
27
            ),
28
            array(
29
                'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
30
                'format' => 'xml',
31
                'type' => 'GoetasWebservices\Xsd\XsdToPhp\Jms\Base64Encoded',
32
                'method' => 'base64EncodedToXml'
33
            ),
34
            array(
35
                'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
36
                'format' => 'xml',
37
                'type' => 'GoetasWebservices\Xsd\XsdToPhp\Jms\Base64Encoded',
38
                'method' => 'base64EncodedFromXml'
39
            )
40
        );
41
    }
42
    public function base64EncodedToXml(XmlSerializationVisitor $visitor, $data, array $type, Context $context)
43
    {
44
        return $visitor->visitSimpleString(base64_encode($data), $type, $context);
0 ignored issues
show
Unused Code introduced by
The call to XmlSerializationVisitor::visitSimpleString() has too many arguments starting with $context.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
45
    }
46
47 View Code Duplication
    public function base64EncodedFromXml(XmlDeserializationVisitor $visitor, $data, array $type)
0 ignored issues
show
Unused Code introduced by
The parameter $visitor is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        $attributes = $data->attributes('xsi', true);
50
        if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') {
51
            return null;
52
        }
53
54
        return base64_decode((string)$data);
55
    }
56
57 View Code Duplication
    public function simpleListOfToXml(XmlSerializationVisitor $visitor, $object, array $type, Context $context)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
60
        $newType = array(
61
            'name' => $type["params"][0]["name"],
62
            'params' => array()
63
        );
64
65
        $navigator = $context->getNavigator();
66
        $ret = array();
67
        foreach ($object as $v) {
68
            $ret[] = $navigator->accept($v, $newType, $context)->data;
0 ignored issues
show
Unused Code introduced by
The call to GraphNavigatorInterface::accept() has too many arguments starting with $context.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
69
        }
70
71
        return $visitor->getDocument()->createTextNode(implode(" ", $ret));
72
    }
73
74 View Code Duplication
    public function simpleListOfFromXml(XmlDeserializationVisitor $visitor, $node, array $type, Context $context)
0 ignored issues
show
Unused Code introduced by
The parameter $visitor is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $newType = array(
77
            'name' => $type["params"][0]["name"],
78
            'params' => array()
79
        );
80
        $ret = array();
81
        $navigator = $context->getNavigator();
82
        foreach (explode(" ", (string)$node) as $v) {
83
            $ret[] = $navigator->accept($v, $newType, $context);
0 ignored issues
show
Unused Code introduced by
The call to GraphNavigatorInterface::accept() has too many arguments starting with $context.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
84
        }
85
        return $ret;
86
    }
87
}
88
89