Code Duplication    Length = 41-45 lines in 2 locations

Zewa/Request.php 1 location

@@ 297-337 (lines=41) @@
294
     * @access public
295
     * @TODO:  expand functionality, set/perform based on configuration
296
     */
297
    public function normalize($data)
298
    {
299
        if (is_array($data)) {
300
            foreach ($data as $key => $value) {
301
                unset($data[$key]);
302
                $data[$this->normalize($key)] = $this->normalize($value);
303
            }
304
        } elseif (is_object($data)) {
305
            $new = new \stdClass();
306
            foreach ($data as $k => $v) {
307
                $key = $this->normalize($k);
308
                $new->{$key} = $this->normalize($v);
309
            }
310
            $data = $new;
311
        } else {
312
            $data = trim($data);
313
            //we need to review this.
314
            if (function_exists('iconv') && function_exists('mb_detect_encoding')) {
315
                $current_encoding = mb_detect_encoding($data);
316
317
                if ($current_encoding != 'UTF-8' && $current_encoding != 'UTF-16') {
318
                    $data = iconv($current_encoding, 'UTF-8', $data);
319
                }
320
            }
321
322
            if (is_numeric($data)) {
323
                $int = intval($data);
324
                $float = floatval($data);
325
                $re = "~^-?[0-9]+(\.[0-9]+)?$~xD";
326
                //@TODO this will not accept all float values, this validates /against/ syntax
327
328
                if (($int === (int)trim($data, '-')) && strlen((string)(int)$data) === strlen($data)) {
329
                    $data = (int) $data;
330
                } elseif ($int !== $float && preg_match($re, $data) === 1 && strlen($data) === strlen($float)) {
331
                    $data = $float;
332
                }
333
            }
334
        }
335
336
        return $data;
337
    }
338
339
    public function __call($name, $arguments)
340
    {

Zewa/Security.php 1 location

@@ 15-59 (lines=45) @@
12
     */
13
    //@TODO clean up
14
15
    public function normalize($data)
16
    {
17
        if (!isset($data)) {
18
            return null;
19
        }
20
21
        if (is_array($data)) {
22
            foreach ($data as $key => $value) {
23
                unset($data[$key]);
24
                $data[$this->normalize($key)] = $this->normalize($value);
25
            }
26
        } elseif (is_object($data)) {
27
            $new = new \stdClass();
28
            foreach ($data as $k => $v) {
29
                $key = $this->normalize($k);
30
                $new->{$key} = $this->normalize($v);
31
            }
32
            $data = $new;
33
        } else {
34
            $data = trim($data);
35
            //we need to review this.
36
            if (function_exists('iconv') && function_exists('mb_detect_encoding')) {
37
                $current_encoding = mb_detect_encoding($data);
38
39
                if ($current_encoding != 'UTF-8' && $current_encoding != 'UTF-16') {
40
                    $data = iconv($current_encoding, 'UTF-8', $data);
41
                }
42
            }
43
44
            if (is_numeric($data)) {
45
                $int = intval($data);
46
                $float = floatval($data);
47
                $re = "~^-?[0-9]+(\.[0-9]+)?$~xD";
48
                //@TODO this will not accept all float values, this validates /against/ syntax
49
50
                if (($int === (int)trim($data, '-')) && strlen((string)(int)$data) === strlen($data)) {
51
                    $data = (int) $data;
52
                } elseif ($int !== $float && preg_match($re, $data) === 1 && strlen($data) === strlen($float)) {
53
                    $data = $float;
54
                }
55
            }
56
        }
57
58
        return $data;
59
    }
60
}
61