Passed
Pull Request — master (#3)
by Akpé Aurelle Emmanuel Moïse
01:34
created
src/similar_text.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
         private function __construct()
18 18
         {
19 19
         }
20
-        public static function similarText($a, $b, $round = 2, $insensitive = true, &$stats = false, $getParts = false, $checkposition=false)
20
+        public static function similarText($a, $b, $round = 2, $insensitive = true, &$stats = false, $getParts = false, $checkposition = false)
21 21
         {
22 22
             if (!is_string($a) || !is_string($b)) {
23 23
                 return false;
@@ -43,14 +43,14 @@  discard block
 block discarded – undo
43 43
             return $stats['similar'];
44 44
         }
45 45
         
46
-        protected static function _check($a, $b, $getParts, $round, $checkposition=false)
46
+        protected static function _check($a, $b, $getParts, $round, $checkposition = false)
47 47
         {
48 48
             $diff = array();
49 49
             if ($getParts) {
50 50
                 $diff[] = array_diff($a, $b);
51 51
                 $diff[] = array_diff($b, $a);
52 52
             }
53
-            $diff[] = $checkposition?array_intersect_assoc($a, $b):array_intersect($a, $b);
53
+            $diff[] = $checkposition ?array_intersect_assoc($a, $b) : array_intersect($a, $b);
54 54
             $diff[] = round(count(array_intersect(self::getParts($a, $c), self::getParts($b))) / $c * 100, $round);
55 55
             $diff[] = $a === $b;
56 56
             return $diff;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             $tmp = '';
83 83
             $c = 0;
84 84
             foreach ($b as $k=>$v) {
85
-                if (ctype_space($v)||ctype_punct($v)) {
85
+                if (ctype_space($v) || ctype_punct($v)) {
86 86
                     $parts[] = $tmp;
87 87
                     $parts[] = $v;
88 88
                     $c += 2;
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
             if (is_array($split)) {
116 116
                 return
117 117
                     array_map(
118
-                        function ($val) {
118
+                        function($val) {
119 119
                             if (self::is_ascii($val)) {
120 120
                                 return strtolower($val);
121 121
                             }
Please login to merge, or discard this patch.
similar_text.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
         $insensitive = true,
21 21
         &$stats = false,
22 22
         $getParts = false,
23
-        $checkposition=false
23
+        $checkposition = false
24 24
                         ) {
25 25
         return similar_text::similarText(
26 26
             $firstString,
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
         return commonTextSimilarities::haveSameRoot($a, $b);
53 53
     }
54 54
     
55
-    function wordsReorderOccured($a, $b, $considerPunctuation=true)
55
+    function wordsReorderOccured($a, $b, $considerPunctuation = true)
56 56
     {
57 57
         return commonTextSimilarities::wordsReorderOccured($a, $b, $considerPunctuation);
58 58
     }
59 59
     
60
-    function punctuactionChangesOccured($a, $b, $considerSpace=true)
60
+    function punctuactionChangesOccured($a, $b, $considerSpace = true)
61 61
     {
62 62
         return commonTextSimilarities::punctuactionChangesOccured($a, $b, $considerSpace);
63 63
     }
Please login to merge, or discard this patch.
tests/Similar_textTest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace Ezama\tests{
3
-    require($dir=dirname(__DIR__)).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'similar_text.php';
3
+    require($dir = dirname(__DIR__)).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'similar_text.php';
4 4
     require $dir.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'commonTextSimilarities.php';
5 5
     require $dir.DIRECTORY_SEPARATOR.'similar_text.php';
6 6
 
@@ -10,10 +10,10 @@  discard block
 block discarded – undo
10 10
     {
11 11
         public function testSimilarText()
12 12
         {
13
-            $this->assertTrue(100.0===similarText('qwerty', 'ytrewq'));
14
-            $this->assertTrue(similarText('qwerty', 'ytreq')>=80);
13
+            $this->assertTrue(100.0 === similarText('qwerty', 'ytrewq'));
14
+            $this->assertTrue(similarText('qwerty', 'ytreq') >= 80);
15 15
             $this->assertTrue(areAnagrams('qwerty', 'ytrewq'));
16
-            $this->assertTrue(0.0===similarText('qwerty', ';lkjhg'));
16
+            $this->assertTrue(0.0 === similarText('qwerty', ';lkjhg'));
17 17
             $this->assertTrue(haveSameRoot('qwerty', 'qwertyuiop'));
18 18
             $this->assertTrue(wordsReorderOccured('joker is a cloon.', 'a cloon is joker'));
19 19
             $this->assertTrue(similarButNotEqual('qwerty', 'ytrewq'));
Please login to merge, or discard this patch.
src/commonTextSimilarities.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -15,40 +15,40 @@  discard block
 block discarded – undo
15 15
     
16 16
     class commonTextSimilarities extends similar_text
17 17
     {
18
-        const URL_FORMAT_EXTENDED_PATTERN = '/^((https?|ftps?|file):\/\/){0,1}'. // protocol
19
-                                            '(([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+'. // username
20
-                                            '(:([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+)?'. // password
21
-                                            '@)?(?#'. // auth requires @
22
-                                            ')((([a-z0-9]\.|[a-z0-9][a-z0-9-]*[a-z0-9]\.)*'. // domain segments AND
23
-                                            '[a-z][a-z0-9-]*[a-z0-9]'. // top level domain OR
18
+        const URL_FORMAT_EXTENDED_PATTERN = '/^((https?|ftps?|file):\/\/){0,1}'.// protocol
19
+                                            '(([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+'.// username
20
+                                            '(:([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+)?'.// password
21
+                                            '@)?(?#'.// auth requires @
22
+                                            ')((([a-z0-9]\.|[a-z0-9][a-z0-9-]*[a-z0-9]\.)*'.// domain segments AND
23
+                                            '[a-z][a-z0-9-]*[a-z0-9]'.// top level domain OR
24 24
                                             '|((\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5])\.){3}'.
25
-                                            '(\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5])'. // IP address
26
-                                            ')(:\d+)?'. // port
27
-                                            ')(((\/+([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)*'. // path
28
-                                            '(\?([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)'. // query string
29
-                                            '?)?)?'. // path and query string optional
30
-                                            '(#([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)?'. // fragment
25
+                                            '(\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5])'.// IP address
26
+                                            ')(:\d+)?'.// port
27
+                                            ')(((\/+([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)*'.// path
28
+                                            '(\?([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)'.// query string
29
+                                            '?)?)?'.// path and query string optional
30
+                                            '(#([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)?'.// fragment
31 31
                                             '$/i';
32 32
 
33 33
 
34 34
 
35 35
 
36
-        const URL_POSIX_FORMAT='"^(\b(https?|ftps?|file):\/\/)?[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/%=~_|]$"i';
36
+        const URL_POSIX_FORMAT = '"^(\b(https?|ftps?|file):\/\/)?[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/%=~_|]$"i';
37 37
         
38
-        protected static function isUrl($url, &$getDomain='')
38
+        protected static function isUrl($url, &$getDomain = '')
39 39
         {
40
-            $matches=array();
41
-            $bool= is_string($url)&&preg_match(self::URL_POSIX_FORMAT, $url)&&preg_match(self::URL_FORMAT_EXTENDED_PATTERN, $url, $matches)/*?true:false*/;
42
-            $getDomain=rtrim($matches[9], '.');
40
+            $matches = array();
41
+            $bool = is_string($url) && preg_match(self::URL_POSIX_FORMAT, $url) && preg_match(self::URL_FORMAT_EXTENDED_PATTERN, $url, $matches)/*?true:false*/;
42
+            $getDomain = rtrim($matches[9], '.');
43 43
             return $bool;
44 44
         }
45 45
         
46 46
         public static function strippedUrl($a, $b)
47 47
         {
48
-            if (self::isUrl($a, $domain)&&is_string($b)) {
49
-                return $domain===trim($b);
50
-            } elseif (self::isUrl($b, $domain)&&is_string($a)) {
51
-                return $domain===trim($a);
48
+            if (self::isUrl($a, $domain) && is_string($b)) {
49
+                return $domain === trim($b);
50
+            } elseif (self::isUrl($b, $domain) && is_string($a)) {
51
+                return $domain === trim($a);
52 52
             } else {
53 53
                 return false;
54 54
             }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
         
57 57
         public static function areAnagrams($a, $b)
58 58
         {
59
-            return  self::similarText($a, $b, 2, true, $check)&&$check['similar'] === 100.0 && $check['contain'] === true;
59
+            return  self::similarText($a, $b, 2, true, $check) && $check['similar'] === 100.0 && $check['contain'] === true;
60 60
         }
61 61
         
62 62
         public static function similarButNotEqual($a, $b)
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
         
67 67
         public static function aIsSuperStringOfB($a, $b)
68 68
         {
69
-            if (strlen($a)>strlen($b)) {
69
+            if (strlen($a) > strlen($b)) {
70 70
                 return   self::similarText($a, $b, 2, true, $check) && is_array($check) && $check['substr'] === 100.0;
71 71
             } else {
72 72
                 return false;
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         
76 76
         public static function haveSameRoot($a, $b)
77 77
         {
78
-            return self::similarText($a, $b, 2, true, $check, true, true) && is_array($check)&&range(0, count($check['a&b'])-1)===array_keys($check['a&b'])/*?true:false*/;
78
+            return self::similarText($a, $b, 2, true, $check, true, true) && is_array($check) && range(0, count($check['a&b']) - 1) === array_keys($check['a&b'])/*?true:false*/;
79 79
         }
80 80
         
81 81
         public static function areStems($a, $b)
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
             return true;
95 95
         }
96 96
         
97
-        public static function wordsReorderOccured($a, $b, $considerPunctuation=true)
97
+        public static function wordsReorderOccured($a, $b, $considerPunctuation = true)
98 98
         {
99
-            $filter=function ($v) use ($considerPunctuation) {
100
-                return $considerPunctuation?!(ctype_space($v)||ctype_punct($v)):!ctype_space($v);
99
+            $filter = function($v) use ($considerPunctuation) {
100
+                return $considerPunctuation ? !(ctype_space($v) || ctype_punct($v)) : !ctype_space($v);
101 101
             };
102 102
             return
103 103
                     self::similarText($a, $b, 2, true, $check, true) &&
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
                     :false;
111 111
         }
112 112
         
113
-        public static function punctuactionChangesOccured($a, $b, $insensitive=true, $considerSpace=true)
113
+        public static function punctuactionChangesOccured($a, $b, $insensitive = true, $considerSpace = true)
114 114
         {
115
-            $filter=function ($v) use ($considerSpace) {
116
-                return $considerSpace?!(ctype_space($v)||ctype_punct($v)):!ctype_punct($v);
115
+            $filter = function($v) use ($considerSpace) {
116
+                return $considerSpace ? !(ctype_space($v) || ctype_punct($v)) : !ctype_punct($v);
117 117
             };
118 118
             if (!is_string($a) || !is_string($b)) {
119 119
                 return false;
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
             if (!is_string($a) || !is_string($b)) {
129 129
                 return false;
130 130
             }
131
-            $filter=function ($v) {
132
-                return !(ctype_space($v)||ctype_punct($v));
131
+            $filter = function($v) {
132
+                return !(ctype_space($v) || ctype_punct($v));
133 133
             };
134 134
             
135 135
             self::filter($a, $b, $filter, true);
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         private static function aoeStemming($a, $b)
140 140
         {
141 141
             foreach ($a as $index=>$word) {
142
-                if (!self::haveSameRoot($word, $b[$index])||(isset($a[$index][2])&&isset($b[$index][2]))) {
142
+                if (!self::haveSameRoot($word, $b[$index]) || (isset($a[$index][2]) && isset($b[$index][2]))) {
143 143
                     return false;
144 144
                 }
145 145
             }
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
             if (!is_string($a) || !is_string($b)) {
152 152
                 return false;
153 153
             }
154
-            $filter=function ($v) {
154
+            $filter = function($v) {
155 155
                 return !(ctype_space($v));
156 156
             };
157 157
             self::filter($a, $b, $filter, true);
158 158
             return self::waorDiff($a, $b, count($a), count($b));
159 159
         }
160 160
         
161
-        private static function filter(&$a, &$b, $filter, $insensitive=true)
161
+        private static function filter(&$a, &$b, $filter, $insensitive = true)
162 162
         {
163 163
             if ($insensitive) {
164 164
                 $a = array_filter(self::getParts(self::strtolower($a)), $filter);
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         
172 172
         private static function waorDiff($a, $b, $ca, $cb)
173 173
         {
174
-            return (bool)(($ca>$cb)?array_diff_assoc(array_values($a), array_values($b)):array_diff_assoc(array_values($b), array_values($a)));
174
+            return (bool) (($ca > $cb) ?array_diff_assoc(array_values($a), array_values($b)) : array_diff_assoc(array_values($b), array_values($a)));
175 175
         }
176 176
     }
177 177
 }
Please login to merge, or discard this patch.