Passed
Push — master ( 2433d5...5c4556 )
by Akpé Aurelle Emmanuel Moïse
47s queued 10s
created

hammingDistance   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A hamming() 0 15 5
1
<?php
2
3
/**
4
*
5
* @Name : similar-text
6
* @Programmer : Akpé Aurelle Emmanuel Moïse Zinsou
7
* @Date : 2019-04-01
8
* @Released under : https://github.com/manuwhat/similar-text/blob/master/LICENSE
9
* @Repository : https://github.com/manuwhat/similar
10
*
11
**/
12
13
14
namespace EZAMA{
15
    class hammingDistance extends Distance
16
    {
17
        public static function hamming($a, $b)
18
        {
19
            if (!is_string($a) || !is_string($b) || (strlen($a) !== strlen($b))) {
20
                return false;
21
            }
22
            static $distance = 0;
23
            static $previous = array();
24
            if (array($a, $b) === $previous) {
25
                return $distance;
26
            }
27
            $previous = array($a, $b);
28
            $a = self::split($a);
29
            $b = self::split($b);
30
            $distance = count(array_diff_assoc((array) $a, (array) $b));
31
            return $distance;
32
        }
33
    }
34
    
35
    
36
}
37