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

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