Code Duplication    Length = 45-45 lines in 2 locations

src/Serializer/Zend1Serializer.php 1 location

@@ 15-59 (lines=45) @@
12
 *
13
 * @author Márk Sági-Kazár <[email protected]>
14
 */
15
final class Zend1Serializer implements Serializer
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function serialize($method, array $params = [])
21
    {
22
        $toBeVisited = [&$params];
23
24
        while (isset($toBeVisited[0]) && $value = &$toBeVisited[0]) {
25
            $type = gettype($value);
26
27
            if ($type === 'array') {
28
                // Zend converts non-zero-indexed arrays to structs
29
                if ((array_keys($value) !== range(0, count($value) - 1)) && (array_keys($value) == range(1, count($value)))) {
30
                    $value = array_values($value);
31
                }
32
33
                foreach ($value as &$child) {
34
                    $toBeVisited[] = &$child;
35
                }
36
            } elseif ($type === 'object') {
37
                if ($value instanceof \DateTime) {
38
                    $value = \Zend_XmlRpc_Value::getXmlRpcValue($value->format('Ymd\TH:i:s'), \Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
39
                } elseif ($value instanceof Base64) {
40
                    $value = \Zend_XmlRpc_Value::getXmlRpcValue($value->getDecoded(), \Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64);
41
                } else {
42
                    $value = get_object_vars($value);
43
                }
44
            } elseif ($type === 'resource') {
45
                throw new InvalidTypeException($value);
46
            }
47
48
            array_shift($toBeVisited);
49
        }
50
51
        $request = new \Zend_XmlRpc_Request($method, $params);
52
53
        try {
54
            return $request->saveXml();
55
        } catch (\Exception $e) {
56
            throw new SerializerException($e->getMessage(), $e->getCode(), $e);
57
        }
58
    }
59
}
60

src/Serializer/Zend2Serializer.php 1 location

@@ 17-61 (lines=45) @@
14
 *
15
 * @author Márk Sági-Kazár <[email protected]>
16
 */
17
final class Zend2Serializer implements Serializer
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function serialize($method, array $params = [])
23
    {
24
        $toBeVisited = [&$params];
25
26
        while (isset($toBeVisited[0]) && $value = &$toBeVisited[0]) {
27
            $type = gettype($value);
28
29
            if ($type === 'array') {
30
                // Zend converts non-zero-indexed arrays to structs
31
                if ((array_keys($value) !== range(0, count($value) - 1)) && (array_keys($value) == range(1, count($value)))) {
32
                    $value = array_values($value);
33
                }
34
35
                foreach ($value as &$child) {
36
                    $toBeVisited[] = &$child;
37
                }
38
            } elseif ($type === 'object') {
39
                if ($value instanceof \DateTime) {
40
                    $value = AbstractValue::getXmlRpcValue($value->format('Ymd\TH:i:s'), AbstractValue::XMLRPC_TYPE_DATETIME);
41
                } elseif ($value instanceof Base64) {
42
                    $value = AbstractValue::getXmlRpcValue($value->getDecoded(), AbstractValue::XMLRPC_TYPE_BASE64);
43
                } else {
44
                    $value = get_object_vars($value);
45
                }
46
            } elseif ($type === 'resource') {
47
                throw new InvalidTypeException($value);
48
            }
49
50
            array_shift($toBeVisited);
51
        }
52
53
        $request = new Request($method, $params);
54
55
        try {
56
            return $request->saveXml();
57
        } catch (\Exception $e) {
58
            throw new SerializerException($e->getMessage(), $e->getCode(), $e);
59
        }
60
    }
61
}
62