Completed
Pull Request — master (#14)
by Mischa ter
01:22
created
src/DamerauLevenshtein.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
     ) {
101 101
         if (!empty($firstString) || !empty($secondString)) {
102 102
             $this->compOne = $firstString;
103
-            $this->compOneLength = (int)mb_strlen($this->compOne, 'UTF-8');
103
+            $this->compOneLength = (int) mb_strlen($this->compOne, 'UTF-8');
104 104
             $this->compTwo = $secondString;
105
-            $this->compTwoLength = (int)mb_strlen($this->compTwo, 'UTF-8');
105
+            $this->compTwoLength = (int) mb_strlen($this->compTwo, 'UTF-8');
106 106
         }
107 107
 
108 108
         $this->insCost = $insCost;
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
             $maxCost += $extraSize * $this->insCost;
240 240
         }
241 241
 
242
-        return (int)$maxCost;
242
+        return (int) $maxCost;
243 243
     }
244 244
 
245 245
     /**
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
             $this->setupMatrix();
254 254
         }
255 255
 
256
-        return (float)(1 - ($this->getSimilarity() / $this->getMaximalDistance()));
256
+        return (float) (1 - ($this->getSimilarity() / $this->getMaximalDistance()));
257 257
     }
258 258
 
259 259
     /**
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
         $oneSize = $this->compOneLength;
283 283
         $twoSize = $this->compTwoLength;
284 284
 
285
-        $out = '  ' . $this->compOne . PHP_EOL;
285
+        $out = '  '.$this->compOne.PHP_EOL;
286 286
         for ($y = 0; $y <= $twoSize; $y += 1) {
287 287
             if ($y - 1 < 0) {
288 288
                 $out .= ' ';
Please login to merge, or discard this patch.
Indentation   +377 added lines, -377 removed lines patch added patch discarded remove patch
@@ -10,381 +10,381 @@
 block discarded – undo
10 10
 class DamerauLevenshtein
11 11
 {
12 12
 
13
-    /**
14
-     * First string.
15
-     *
16
-     * @var String
17
-     */
18
-    private $compOne;
19
-
20
-    /**
21
-     * Second string.
22
-     *
23
-     * @var String
24
-     */
25
-    private $compTwo;
26
-
27
-    /**
28
-     * Length of first string.
29
-     *
30
-     * @var int
31
-     */
32
-    private $compOneLength = 0;
33
-
34
-    /**
35
-     * Length of second string.
36
-     *
37
-     * @var int
38
-     */
39
-    private $compTwoLength = 0;
40
-
41
-    /**
42
-     * Matrix for Damerau Levenshtein distance dynamic programming computation.
43
-     *
44
-     * @var int[][]
45
-     */
46
-    private $matrix;
47
-
48
-    /**
49
-     * Boolean flag determining whether is matrix computed for input strings.
50
-     *
51
-     * @var bool
52
-     */
53
-    private $calculated = false;
54
-
55
-    /**
56
-     * Cost of character insertion (to first string to match second string).
57
-     *
58
-     * @var int
59
-     */
60
-    private $insCost = 1;
61
-
62
-    /**
63
-     * Cost of character deletion (from first string to match second string).
64
-     *
65
-     * @var int
66
-     */
67
-    private $delCost = 1;
68
-
69
-    /**
70
-     * Substitution cost.
71
-     *
72
-     * @var int
73
-     */
74
-    private $subCost = 1;
75
-
76
-    /**
77
-     * Transposition cost.
78
-     *
79
-     * @var int
80
-     */
81
-    private $transCost = 1;
82
-
83
-    /**
84
-     * Constructor.
85
-     *
86
-     * @param string $firstString first string to compute distance
87
-     * @param string $secondString second string to compute distance
88
-     * @param int $insCost Cost of character insertion
89
-     * @param int $delCost Cost of character deletion
90
-     * @param int $subCost Substitution cost
91
-     * @param int $transCost Transposition cost
92
-     */
93
-    public function __construct(
94
-        string $firstString,
95
-        string $secondString,
96
-        int $insCost = 1,
97
-        int $delCost = 1,
98
-        int $subCost = 1,
99
-        int $transCost = 1
100
-    ) {
101
-        if (!empty($firstString) || !empty($secondString)) {
102
-            $this->compOne = $firstString;
103
-            $this->compOneLength = (int)mb_strlen($this->compOne, 'UTF-8');
104
-            $this->compTwo = $secondString;
105
-            $this->compTwoLength = (int)mb_strlen($this->compTwo, 'UTF-8');
106
-        }
107
-
108
-        $this->insCost = $insCost;
109
-        $this->delCost = $delCost;
110
-        $this->subCost = $subCost;
111
-        $this->transCost = $transCost;
112
-    }
113
-
114
-    /**
115
-     * Returns computed matrix for given input strings.
116
-     *
117
-     * @return int[][] matrix
118
-     */
119
-    public function getMatrix(): array
120
-    {
121
-        if (!$this->calculated) {
122
-            $this->setupMatrix();
123
-        }
124
-
125
-        return $this->matrix;
126
-    }
127
-
128
-    /**
129
-     * Returns similarity of strings, absolute number = Damerau Levenshtein distance.
130
-     *
131
-     * @return int
132
-     */
133
-    public function getSimilarity(): int
134
-    {
135
-        if (!$this->calculated) {
136
-            $this->setupMatrix();
137
-        }
138
-
139
-        return $this->matrix[$this->compOneLength][$this->compTwoLength];
140
-    }
141
-
142
-    /**
143
-     * Procedure to compute matrix for given input strings.
144
-     *
145
-     * @return void
146
-     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
147
-     */
148
-    private function setupMatrix(): void
149
-    {
150
-        $this->matrix = [[]];
151
-
152
-        $oneSize = $this->compOneLength;
153
-        $twoSize = $this->compTwoLength;
154
-
155
-        for ($i = 0; $i <= $oneSize; $i += 1) {
156
-            $this->matrix[$i][0] = $i > 0 ? $this->matrix[$i - 1][0] + $this->delCost : 0;
157
-        }
158
-
159
-        for ($i = 0; $i <= $twoSize; $i += 1) {
160
-            // Insertion actualy
161
-            $this->matrix[0][$i] = $i > 0 ? $this->matrix[0][$i - 1] + $this->insCost : 0;
162
-        }
163
-
164
-        for ($i = 1; $i <= $oneSize; $i += 1) {
165
-            // Curchar for the first string
166
-            $cOne = mb_substr($this->compOne, $i - 1, 1, 'UTF-8');
167
-            for ($j = 1; $j <= $twoSize; $j += 1) {
168
-                // Curchar for the second string
169
-                $cTwo = mb_substr($this->compTwo, $j - 1, 1, 'UTF-8');
170
-
171
-                // Compute substitution cost
172
-                if ($this->compare($cOne, $cTwo) === 0) {
173
-                    $cost = 0;
174
-                    $trans = 0;
175
-                } else {
176
-                    $cost = $this->subCost;
177
-                    $trans = $this->transCost;
178
-                }
179
-
180
-                // Deletion cost
181
-                $del = $this->matrix[$i - 1][$j] + $this->delCost;
182
-
183
-                // Insertion cost
184
-                $ins = $this->matrix[$i][$j - 1] + $this->insCost;
185
-
186
-                // Substitution cost, 0 if same
187
-                $sub = $this->matrix[$i - 1][$j - 1] + $cost;
188
-
189
-                // Compute optimal
190
-                $this->matrix[$i][$j] = min($del, $ins, $sub);
191
-
192
-                // Transposition cost
193
-                if ($i > 1 && $j > 1) {
194
-                    // Last two
195
-                    $ccOne = mb_substr($this->compOne, $i - 2, 1, 'UTF-8');
196
-                    $ccTwo = mb_substr($this->compTwo, $j - 2, 1, 'UTF-8');
197
-
198
-                    if ($this->compare($cOne, $ccTwo) === 0 && $this->compare($ccOne, $cTwo) === 0) {
199
-                        // Transposition cost is computed as minimal of two
200
-                        $this->matrix[$i][$j] = min($this->matrix[$i][$j], $this->matrix[$i - 2][$j - 2] + $trans);
201
-                    }
202
-                }
203
-            }
204
-        }
205
-
206
-        $this->calculated = true;
207
-    }
208
-
209
-    /**
210
-     * Returns maximal possible edit Damerau Levenshtein distance between texts.
211
-     *
212
-     * On common substring of same length perform substitution / insert + delete
213
-     * (depends on what is cheaper), then on extra characters perform insertion / deletion
214
-     *
215
-     * @return int
216
-     */
217
-    public function getMaximalDistance(): int
218
-    {
219
-        $oneSize = $this->compOneLength;
220
-        $twoSize = $this->compTwoLength;
221
-
222
-        // Is substitution cheaper that delete + insert?
223
-        $subCost = min($this->subCost, $this->delCost + $this->insCost);
224
-
225
-        // Get common size
226
-        $minSize = min($oneSize, $twoSize);
227
-        $maxSize = max($oneSize, $twoSize);
228
-        $extraSize = $maxSize - $minSize;
229
-
230
-        // On common size perform substitution / delete + insert, what is cheaper
231
-        $maxCost = $subCost * $minSize;
232
-
233
-        // On resulting do insert/delete
234
-        if ($oneSize > $twoSize) {
235
-            // Delete extra characters
236
-            $maxCost += $extraSize * $this->delCost;
237
-        } else {
238
-            // Insert extra characters
239
-            $maxCost += $extraSize * $this->insCost;
240
-        }
241
-
242
-        return (int)$maxCost;
243
-    }
244
-
245
-    /**
246
-     * Returns relative distance of input strings (computed with maximal possible distance).
247
-     *
248
-     * @return float
249
-     */
250
-    public function getRelativeDistance(): float
251
-    {
252
-        if (!$this->calculated) {
253
-            $this->setupMatrix();
254
-        }
255
-
256
-        return (float)(1 - ($this->getSimilarity() / $this->getMaximalDistance()));
257
-    }
258
-
259
-    /**
260
-     * Compares two characters from string (this method may be overridden in child class).
261
-     *
262
-     * @param string $firstCharacter First character
263
-     * @param string $secondCharacter Second character
264
-     * @return int
265
-     */
266
-    protected function compare(string $firstCharacter, string $secondCharacter): int
267
-    {
268
-        return strcmp($firstCharacter, $secondCharacter);
269
-    }
270
-
271
-    /**
272
-     * Returns computed matrix for given input strings (For debugging purposes).
273
-     *
274
-     * @return string
275
-     */
276
-    public function displayMatrix(): string
277
-    {
278
-        if (!$this->calculated) {
279
-            $this->setupMatrix();
280
-        }
281
-
282
-        $oneSize = $this->compOneLength;
283
-        $twoSize = $this->compTwoLength;
284
-
285
-        $out = '  ' . $this->compOne . PHP_EOL;
286
-        for ($y = 0; $y <= $twoSize; $y += 1) {
287
-            if ($y - 1 < 0) {
288
-                $out .= ' ';
289
-            } else {
290
-                $out .= mb_substr($this->compTwo, $y - 1, 1, 'UTF-8');
291
-            }
292
-
293
-            for ($x = 0; $x <= $oneSize; $x += 1) {
294
-                $out .= $this->matrix[$x][$y];
295
-            }
296
-
297
-            $out .= PHP_EOL;
298
-        }
299
-
300
-        return $out;
301
-    }
302
-
303
-    /**
304
-     * Returns current cost of insertion operation.
305
-     *
306
-     * @return int
307
-     */
308
-    public function getInsCost(): int
309
-    {
310
-        return $this->insCost;
311
-    }
312
-
313
-    /**
314
-     * Sets cost of insertion operation (insert characters to first string to match second string).
315
-     *
316
-     * @param int $insCost Cost of character insertion
317
-     * @return void
318
-     */
319
-    public function setInsCost(int $insCost): void
320
-    {
321
-        $this->calculated = $insCost === $this->insCost ? $this->calculated : false;
322
-        $this->insCost = $insCost;
323
-    }
324
-
325
-    /**
326
-     * Returns current cost of deletion operation.
327
-     *
328
-     * @return int
329
-     */
330
-    public function getDelCost(): int
331
-    {
332
-        return $this->delCost;
333
-    }
334
-
335
-    /**
336
-     * Sets cost of deletion operation (delete characters from first string to match second string).
337
-     *
338
-     * @param int $delCost Cost of character deletion
339
-     * @return void
340
-     */
341
-    public function setDelCost(int $delCost): void
342
-    {
343
-        $this->calculated = $delCost === $this->delCost ? $this->calculated : false;
344
-        $this->delCost = $delCost;
345
-    }
346
-
347
-    /**
348
-     * Returns current cost of substitution operation.
349
-     *
350
-     * @return int
351
-     */
352
-    public function getSubCost(): int
353
-    {
354
-        return $this->subCost;
355
-    }
356
-
357
-    /**
358
-     * Sets cost of substitution operation.
359
-     *
360
-     * @param int $subCost Cost of character substitution
361
-     * @return void
362
-     */
363
-    public function setSubCost(int $subCost): void
364
-    {
365
-        $this->calculated = $subCost === $this->subCost ? $this->calculated : false;
366
-        $this->subCost = $subCost;
367
-    }
368
-
369
-    /**
370
-     * Returns current cost of transposition operation.
371
-     *
372
-     * @return int
373
-     */
374
-    public function getTransCost(): int
375
-    {
376
-        return $this->transCost;
377
-    }
378
-
379
-    /**
380
-     * Sets cost of transposition operation.
381
-     *
382
-     * @param int $transCost Cost of character transposition
383
-     * @return void
384
-     */
385
-    public function setTransCost(int $transCost): void
386
-    {
387
-        $this->calculated = $transCost === $this->transCost ? $this->calculated : false;
388
-        $this->transCost = $transCost;
389
-    }
13
+	/**
14
+	 * First string.
15
+	 *
16
+	 * @var String
17
+	 */
18
+	private $compOne;
19
+
20
+	/**
21
+	 * Second string.
22
+	 *
23
+	 * @var String
24
+	 */
25
+	private $compTwo;
26
+
27
+	/**
28
+	 * Length of first string.
29
+	 *
30
+	 * @var int
31
+	 */
32
+	private $compOneLength = 0;
33
+
34
+	/**
35
+	 * Length of second string.
36
+	 *
37
+	 * @var int
38
+	 */
39
+	private $compTwoLength = 0;
40
+
41
+	/**
42
+	 * Matrix for Damerau Levenshtein distance dynamic programming computation.
43
+	 *
44
+	 * @var int[][]
45
+	 */
46
+	private $matrix;
47
+
48
+	/**
49
+	 * Boolean flag determining whether is matrix computed for input strings.
50
+	 *
51
+	 * @var bool
52
+	 */
53
+	private $calculated = false;
54
+
55
+	/**
56
+	 * Cost of character insertion (to first string to match second string).
57
+	 *
58
+	 * @var int
59
+	 */
60
+	private $insCost = 1;
61
+
62
+	/**
63
+	 * Cost of character deletion (from first string to match second string).
64
+	 *
65
+	 * @var int
66
+	 */
67
+	private $delCost = 1;
68
+
69
+	/**
70
+	 * Substitution cost.
71
+	 *
72
+	 * @var int
73
+	 */
74
+	private $subCost = 1;
75
+
76
+	/**
77
+	 * Transposition cost.
78
+	 *
79
+	 * @var int
80
+	 */
81
+	private $transCost = 1;
82
+
83
+	/**
84
+	 * Constructor.
85
+	 *
86
+	 * @param string $firstString first string to compute distance
87
+	 * @param string $secondString second string to compute distance
88
+	 * @param int $insCost Cost of character insertion
89
+	 * @param int $delCost Cost of character deletion
90
+	 * @param int $subCost Substitution cost
91
+	 * @param int $transCost Transposition cost
92
+	 */
93
+	public function __construct(
94
+		string $firstString,
95
+		string $secondString,
96
+		int $insCost = 1,
97
+		int $delCost = 1,
98
+		int $subCost = 1,
99
+		int $transCost = 1
100
+	) {
101
+		if (!empty($firstString) || !empty($secondString)) {
102
+			$this->compOne = $firstString;
103
+			$this->compOneLength = (int)mb_strlen($this->compOne, 'UTF-8');
104
+			$this->compTwo = $secondString;
105
+			$this->compTwoLength = (int)mb_strlen($this->compTwo, 'UTF-8');
106
+		}
107
+
108
+		$this->insCost = $insCost;
109
+		$this->delCost = $delCost;
110
+		$this->subCost = $subCost;
111
+		$this->transCost = $transCost;
112
+	}
113
+
114
+	/**
115
+	 * Returns computed matrix for given input strings.
116
+	 *
117
+	 * @return int[][] matrix
118
+	 */
119
+	public function getMatrix(): array
120
+	{
121
+		if (!$this->calculated) {
122
+			$this->setupMatrix();
123
+		}
124
+
125
+		return $this->matrix;
126
+	}
127
+
128
+	/**
129
+	 * Returns similarity of strings, absolute number = Damerau Levenshtein distance.
130
+	 *
131
+	 * @return int
132
+	 */
133
+	public function getSimilarity(): int
134
+	{
135
+		if (!$this->calculated) {
136
+			$this->setupMatrix();
137
+		}
138
+
139
+		return $this->matrix[$this->compOneLength][$this->compTwoLength];
140
+	}
141
+
142
+	/**
143
+	 * Procedure to compute matrix for given input strings.
144
+	 *
145
+	 * @return void
146
+	 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
147
+	 */
148
+	private function setupMatrix(): void
149
+	{
150
+		$this->matrix = [[]];
151
+
152
+		$oneSize = $this->compOneLength;
153
+		$twoSize = $this->compTwoLength;
154
+
155
+		for ($i = 0; $i <= $oneSize; $i += 1) {
156
+			$this->matrix[$i][0] = $i > 0 ? $this->matrix[$i - 1][0] + $this->delCost : 0;
157
+		}
158
+
159
+		for ($i = 0; $i <= $twoSize; $i += 1) {
160
+			// Insertion actualy
161
+			$this->matrix[0][$i] = $i > 0 ? $this->matrix[0][$i - 1] + $this->insCost : 0;
162
+		}
163
+
164
+		for ($i = 1; $i <= $oneSize; $i += 1) {
165
+			// Curchar for the first string
166
+			$cOne = mb_substr($this->compOne, $i - 1, 1, 'UTF-8');
167
+			for ($j = 1; $j <= $twoSize; $j += 1) {
168
+				// Curchar for the second string
169
+				$cTwo = mb_substr($this->compTwo, $j - 1, 1, 'UTF-8');
170
+
171
+				// Compute substitution cost
172
+				if ($this->compare($cOne, $cTwo) === 0) {
173
+					$cost = 0;
174
+					$trans = 0;
175
+				} else {
176
+					$cost = $this->subCost;
177
+					$trans = $this->transCost;
178
+				}
179
+
180
+				// Deletion cost
181
+				$del = $this->matrix[$i - 1][$j] + $this->delCost;
182
+
183
+				// Insertion cost
184
+				$ins = $this->matrix[$i][$j - 1] + $this->insCost;
185
+
186
+				// Substitution cost, 0 if same
187
+				$sub = $this->matrix[$i - 1][$j - 1] + $cost;
188
+
189
+				// Compute optimal
190
+				$this->matrix[$i][$j] = min($del, $ins, $sub);
191
+
192
+				// Transposition cost
193
+				if ($i > 1 && $j > 1) {
194
+					// Last two
195
+					$ccOne = mb_substr($this->compOne, $i - 2, 1, 'UTF-8');
196
+					$ccTwo = mb_substr($this->compTwo, $j - 2, 1, 'UTF-8');
197
+
198
+					if ($this->compare($cOne, $ccTwo) === 0 && $this->compare($ccOne, $cTwo) === 0) {
199
+						// Transposition cost is computed as minimal of two
200
+						$this->matrix[$i][$j] = min($this->matrix[$i][$j], $this->matrix[$i - 2][$j - 2] + $trans);
201
+					}
202
+				}
203
+			}
204
+		}
205
+
206
+		$this->calculated = true;
207
+	}
208
+
209
+	/**
210
+	 * Returns maximal possible edit Damerau Levenshtein distance between texts.
211
+	 *
212
+	 * On common substring of same length perform substitution / insert + delete
213
+	 * (depends on what is cheaper), then on extra characters perform insertion / deletion
214
+	 *
215
+	 * @return int
216
+	 */
217
+	public function getMaximalDistance(): int
218
+	{
219
+		$oneSize = $this->compOneLength;
220
+		$twoSize = $this->compTwoLength;
221
+
222
+		// Is substitution cheaper that delete + insert?
223
+		$subCost = min($this->subCost, $this->delCost + $this->insCost);
224
+
225
+		// Get common size
226
+		$minSize = min($oneSize, $twoSize);
227
+		$maxSize = max($oneSize, $twoSize);
228
+		$extraSize = $maxSize - $minSize;
229
+
230
+		// On common size perform substitution / delete + insert, what is cheaper
231
+		$maxCost = $subCost * $minSize;
232
+
233
+		// On resulting do insert/delete
234
+		if ($oneSize > $twoSize) {
235
+			// Delete extra characters
236
+			$maxCost += $extraSize * $this->delCost;
237
+		} else {
238
+			// Insert extra characters
239
+			$maxCost += $extraSize * $this->insCost;
240
+		}
241
+
242
+		return (int)$maxCost;
243
+	}
244
+
245
+	/**
246
+	 * Returns relative distance of input strings (computed with maximal possible distance).
247
+	 *
248
+	 * @return float
249
+	 */
250
+	public function getRelativeDistance(): float
251
+	{
252
+		if (!$this->calculated) {
253
+			$this->setupMatrix();
254
+		}
255
+
256
+		return (float)(1 - ($this->getSimilarity() / $this->getMaximalDistance()));
257
+	}
258
+
259
+	/**
260
+	 * Compares two characters from string (this method may be overridden in child class).
261
+	 *
262
+	 * @param string $firstCharacter First character
263
+	 * @param string $secondCharacter Second character
264
+	 * @return int
265
+	 */
266
+	protected function compare(string $firstCharacter, string $secondCharacter): int
267
+	{
268
+		return strcmp($firstCharacter, $secondCharacter);
269
+	}
270
+
271
+	/**
272
+	 * Returns computed matrix for given input strings (For debugging purposes).
273
+	 *
274
+	 * @return string
275
+	 */
276
+	public function displayMatrix(): string
277
+	{
278
+		if (!$this->calculated) {
279
+			$this->setupMatrix();
280
+		}
281
+
282
+		$oneSize = $this->compOneLength;
283
+		$twoSize = $this->compTwoLength;
284
+
285
+		$out = '  ' . $this->compOne . PHP_EOL;
286
+		for ($y = 0; $y <= $twoSize; $y += 1) {
287
+			if ($y - 1 < 0) {
288
+				$out .= ' ';
289
+			} else {
290
+				$out .= mb_substr($this->compTwo, $y - 1, 1, 'UTF-8');
291
+			}
292
+
293
+			for ($x = 0; $x <= $oneSize; $x += 1) {
294
+				$out .= $this->matrix[$x][$y];
295
+			}
296
+
297
+			$out .= PHP_EOL;
298
+		}
299
+
300
+		return $out;
301
+	}
302
+
303
+	/**
304
+	 * Returns current cost of insertion operation.
305
+	 *
306
+	 * @return int
307
+	 */
308
+	public function getInsCost(): int
309
+	{
310
+		return $this->insCost;
311
+	}
312
+
313
+	/**
314
+	 * Sets cost of insertion operation (insert characters to first string to match second string).
315
+	 *
316
+	 * @param int $insCost Cost of character insertion
317
+	 * @return void
318
+	 */
319
+	public function setInsCost(int $insCost): void
320
+	{
321
+		$this->calculated = $insCost === $this->insCost ? $this->calculated : false;
322
+		$this->insCost = $insCost;
323
+	}
324
+
325
+	/**
326
+	 * Returns current cost of deletion operation.
327
+	 *
328
+	 * @return int
329
+	 */
330
+	public function getDelCost(): int
331
+	{
332
+		return $this->delCost;
333
+	}
334
+
335
+	/**
336
+	 * Sets cost of deletion operation (delete characters from first string to match second string).
337
+	 *
338
+	 * @param int $delCost Cost of character deletion
339
+	 * @return void
340
+	 */
341
+	public function setDelCost(int $delCost): void
342
+	{
343
+		$this->calculated = $delCost === $this->delCost ? $this->calculated : false;
344
+		$this->delCost = $delCost;
345
+	}
346
+
347
+	/**
348
+	 * Returns current cost of substitution operation.
349
+	 *
350
+	 * @return int
351
+	 */
352
+	public function getSubCost(): int
353
+	{
354
+		return $this->subCost;
355
+	}
356
+
357
+	/**
358
+	 * Sets cost of substitution operation.
359
+	 *
360
+	 * @param int $subCost Cost of character substitution
361
+	 * @return void
362
+	 */
363
+	public function setSubCost(int $subCost): void
364
+	{
365
+		$this->calculated = $subCost === $this->subCost ? $this->calculated : false;
366
+		$this->subCost = $subCost;
367
+	}
368
+
369
+	/**
370
+	 * Returns current cost of transposition operation.
371
+	 *
372
+	 * @return int
373
+	 */
374
+	public function getTransCost(): int
375
+	{
376
+		return $this->transCost;
377
+	}
378
+
379
+	/**
380
+	 * Sets cost of transposition operation.
381
+	 *
382
+	 * @param int $transCost Cost of character transposition
383
+	 * @return void
384
+	 */
385
+	public function setTransCost(int $transCost): void
386
+	{
387
+		$this->calculated = $transCost === $this->transCost ? $this->calculated : false;
388
+		$this->transCost = $transCost;
389
+	}
390 390
 }
Please login to merge, or discard this patch.