Completed
Push — master ( 1a9d0b...536152 )
by
unknown
30s
created

Security   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 56
Duplicated Lines 80.36 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 16
lcom 0
cbo 0
dl 45
loc 56
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C normalize() 45 45 16

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Zewa;
4
5
class Security
6
{
7
    /**
8
     * Normalizes data
9
     *
10
     * @access public
11
     * @TODO:  expand functionality, set/perform based on configuration
12
     */
13
    //@TODO clean up
14
15 7 View Code Duplication
    public function normalize($data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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