Code Duplication    Length = 32-32 lines in 2 locations

src/Util.php 1 location

@@ 46-77 (lines=32) @@
43
     *
44
     * @return array
45
     */
46
    public static function parseParameters($input)
47
    {
48
        if (!isset($input) || !$input) {
49
            return [];
50
        }
51
52
        $pairs = explode('&', $input);
53
54
        $parameters = [];
55
        foreach ($pairs as $pair) {
56
            $split = explode('=', $pair, 2);
57
            $parameter = self::urldecodeRfc3986($split[0]);
58
            $value = isset($split[1]) ? self::urldecodeRfc3986($split[1]) : '';
59
60
            if (isset($parameters[$parameter])) {
61
                // We have already recieved parameter(s) with this name, so add to the list
62
                // of parameters with this name
63
64
                if (is_scalar($parameters[$parameter])) {
65
                    // This is the first duplicate, so transform scalar (string) into an array
66
                    // so we can add the duplicates
67
                    $parameters[$parameter] = [$parameters[$parameter]];
68
                }
69
70
                $parameters[$parameter][] = $value;
71
            } else {
72
                $parameters[$parameter] = $value;
73
            }
74
        }
75
76
        return $parameters;
77
    }
78
79
    /**
80
     * @param $params

src/TwitterAds.php 1 location

@@ 733-764 (lines=32) @@
730
    // This function takes a input like a=b&a=c&d=e and returns the parsed
731
    // parameters like this
732
    // array('a' => array('b','c'), 'd' => 'e')
733
    public static function parse_parameters($input)
734
    {
735
        if (!isset($input) || !$input) {
736
            return array();
737
        }
738
739
        $pairs = explode('&', $input);
740
741
        $parsed_parameters = array();
742
        foreach ($pairs as $pair) {
743
            $split = explode('=', $pair, 2);
744
            $parameter = self::urldecode_rfc3986($split[0]);
745
            $value = isset($split[1]) ? self::urldecode_rfc3986($split[1]) : '';
746
747
            if (isset($parsed_parameters[$parameter])) {
748
                // We have already recieved parameter(s) with this name, so add to the list
749
                // of parameters with this name
750
751
                if (is_scalar($parsed_parameters[$parameter])) {
752
                    // This is the first duplicate, so transform scalar (string) into an array
753
                    // so we can add the duplicates
754
                    $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
755
                }
756
757
                $parsed_parameters[$parameter][] = $value;
758
            } else {
759
                $parsed_parameters[$parameter] = $value;
760
            }
761
        }
762
763
        return $parsed_parameters;
764
    }
765
766
    public static function urlencode_rfc3986($input)
767
    {