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

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