Completed
Pull Request — master (#10)
by Akpé Aurelle Emmanuel Moïse
02:01
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($a, $b));
0 ignored issues
show
Bug introduced by
It seems like $a can also be of type false; however, parameter $array1 of array_diff_assoc() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
            $distance=count(array_diff_assoc(/** @scrutinizer ignore-type */ $a, $b));
Loading history...
Bug introduced by
It seems like $b can also be of type false; however, parameter $array2 of array_diff_assoc() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
            $distance=count(array_diff_assoc($a, /** @scrutinizer ignore-type */ $b));
Loading history...
31
            return $distance;
32
        }
33
    }
34
    
35
    
36
}
37