13
13
*
14
14
* @package jblond\Diff
15
15
* @author Chris Boulton <chris.boulton@interspire.com>
16
- * @author Mario Brandt <leet31337@web.de>
17
16
* @author Ferry Cools <info@DigiLive.nl>
18
- * @copyright (c) 2020 Mario Brandt
17
+ * @copyright (c) 2020 Ferry Cools
19
18
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
20
19
* @version 2.3.0
21
20
* @link https://github.com/JBlond/php-diff
@@ -62,6 +61,7 @@ public function setSeq2($version2)
62
61
* @param int $type Calculation method.
63
62
*
64
63
* @return float The calculated ratio.
64
+ *
65
65
*/
66
66
public function getSimilarity (int $ type = self ::CALC_DEFAULT ): float
67
67
{
@@ -71,7 +71,13 @@ public function getSimilarity(int $type = self::CALC_DEFAULT): float
71
71
case self ::CALC_FASTEST :
72
72
return $ this ->getRatioFastest ();
73
73
default :
74
- $ matches = array_reduce ($ this ->getMatchingBlocks (), [$ this , 'ratioReduce ' ], 0 );
74
+ $ matches = array_reduce (
75
+ $ this ->getMatchingBlocks (),
76
+ function ($ carry , $ item ) {
77
+ return $ this ->ratioReduce ($ carry , $ item );
78
+ },
79
+ 0
80
+ );
75
81
76
82
return $ this ->calculateRatio ($ matches , count ($ this ->old ) + count ($ this ->new ));
77
83
}
@@ -99,12 +105,8 @@ private function getRatioFast(): float
99
105
$ matches = 0 ;
100
106
$ aLength = count ($ this ->old );
101
107
for ($ iterator = 0 ; $ iterator < $ aLength ; ++$ iterator ) {
102
- $ char = $ this ->old [$ iterator ];
103
- if (isset ($ avail [$ char ])) {
104
- $ numb = $ avail [$ char ];
105
- } else {
106
- $ numb = $ this ->uniqueCount2 [$ char ] ?? 0 ;
107
- }
108
+ $ char = $ this ->old [$ iterator ];
109
+ $ numb = isset ($ avail [$ char ]) ? $ avail [$ char ] : $ this ->uniqueCount2 [$ char ] ?? 0 ;
108
110
$ avail [$ char ] = $ numb - 1 ;
109
111
if ($ numb > 0 ) {
110
112
++$ matches ;
0 commit comments