Code Duplication    Length = 32-32 lines in 2 locations

src/TwitterAds.php 1 location

@@ 651-682 (lines=32) @@
648
    // This function takes a input like a=b&a=c&d=e and returns the parsed
649
    // parameters like this
650
    // array('a' => array('b','c'), 'd' => 'e')
651
    public static function parse_parameters($input)
652
    {
653
        if (!isset($input) || !$input) {
654
            return array();
655
        }
656
657
        $pairs = explode('&', $input);
658
659
        $parsed_parameters = array();
660
        foreach ($pairs as $pair) {
661
            $split = explode('=', $pair, 2);
662
            $parameter = self::urldecode_rfc3986($split[0]);
663
            $value = isset($split[1]) ? self::urldecode_rfc3986($split[1]) : '';
664
665
            if (isset($parsed_parameters[$parameter])) {
666
                // We have already recieved parameter(s) with this name, so add to the list
667
                // of parameters with this name
668
669
                if (is_scalar($parsed_parameters[$parameter])) {
670
                    // This is the first duplicate, so transform scalar (string) into an array
671
                    // so we can add the duplicates
672
                    $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
673
                }
674
675
                $parsed_parameters[$parameter][] = $value;
676
            } else {
677
                $parsed_parameters[$parameter] = $value;
678
            }
679
        }
680
681
        return $parsed_parameters;
682
    }
683
684
    public static function urlencode_rfc3986($input)
685
    {

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