Skip to content

Commit 79d989d

Browse files
committed
Refactor callbacks and if/else expressions.
1 parent 7ec484c commit 79d989d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/jblond/Diff/Similarity.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
*
1414
* @package jblond\Diff
1515
* @author Chris Boulton <chris.boulton@interspire.com>
16-
* @author Mario Brandt <leet31337@web.de>
1716
* @author Ferry Cools <info@DigiLive.nl>
18-
* @copyright (c) 2020 Mario Brandt
17+
* @copyright (c) 2020 Ferry Cools
1918
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
2019
* @version 2.3.0
2120
* @link https://github.com/JBlond/php-diff
@@ -62,6 +61,7 @@ public function setSeq2($version2)
6261
* @param int $type Calculation method.
6362
*
6463
* @return float The calculated ratio.
64+
*
6565
*/
6666
public function getSimilarity(int $type = self::CALC_DEFAULT): float
6767
{
@@ -71,7 +71,13 @@ public function getSimilarity(int $type = self::CALC_DEFAULT): float
7171
case self::CALC_FASTEST:
7272
return $this->getRatioFastest();
7373
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+
);
7581

7682
return $this->calculateRatio($matches, count($this->old) + count($this->new));
7783
}
@@ -99,12 +105,8 @@ private function getRatioFast(): float
99105
$matches = 0;
100106
$aLength = count($this->old);
101107
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;
108110
$avail[$char] = $numb - 1;
109111
if ($numb > 0) {
110112
++$matches;

0 commit comments

Comments
 (0)