Passed
Push — ref ( 45b89b )
by Asmir
02:50
created

SerializerUtils   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 7
c 1
b 0
f 0
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMetadataFactory() 0 10 2
1
<?php
2
3
namespace GoetasWebservices\SoapServices\Metadata;
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
    public static function getMetadataFactory($serializer)
17
    {
18
        if (method_exists($serializer, "getMetadataFactory")) {
19
            // JMS Serializer 1.x
20
            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
}
29