Completed
Push — master ( 2a804a...3f4c76 )
by Asmir
11s
created

SerializerUtils::getMetadataFactory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.5

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 3
cts 6
cp 0.5
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.5
1
<?php
2
3
namespace GoetasWebservices\SoapServices\SoapClient;
4
5
use JMS\Serializer\Serializer;
6
use Metadata\MetadataFactory;
7
8
class SerializerUtils
9
{
10
    /**
11
     * Get metadata factory from serializer, with any JMS Serializer version.
12
     *
13
     * @param $serializer Serializer
14
     * @return MetadataFactory
15
     */
16 32
    public static function getMetadataFactory($serializer)
17
    {
18 32
        if (method_exists($serializer, "getMetadataFactory")) {
19
            // JMS Serializer 1.x
20 32
            return $serializer->getMetadataFactory();
21
        } else {
22
            // JMS Serializer 2.x & 3.x
23
            $reflectionProperty = new \ReflectionProperty(get_class($serializer), 'factory');
24
            $reflectionProperty->setAccessible(true);
25
            return $reflectionProperty->getValue($serializer);
26
        }
27
    }
28
}