Code Duplication    Length = 32-32 lines in 2 locations

src/Util.php 1 location

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

src/TwitterAds.php 1 location

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