Skip to content

Commit b9b89b4

Browse files
committed
CS
1 parent 3d8ce56 commit b9b89b4

6 files changed

+37
-37
lines changed

src/DataStore/DataStoreInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ interface DataStoreInterface
66
{
77
public function add(int $state, string $string): void;
88

9-
public function remove(int $state, string $string): void;
10-
119
/**
1210
* Returns the matching strings per state. Key is the state and the value is an array of matching strings
1311
* for that state.
1412
*
1513
* @return array<int,array<string>>
1614
*/
1715
public function getForStates(array $states = []): array;
16+
17+
public function remove(int $state, string $string): void;
1818
}

src/DataStore/InMemoryDataStore.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ public function add(int $state, string $string): void
1414
$this->data[$state][] = $string;
1515
}
1616

17+
public function all(): array
18+
{
19+
return $this->data;
20+
}
21+
22+
public function getForStates(array $states = []): array
23+
{
24+
return array_intersect_key($this->data, array_flip($states));
25+
}
26+
1727
public function remove(int $state, string $string): void
1828
{
1929
$updated = array_values(array_diff($this->data[$state] ?? [], [$string]));
@@ -24,14 +34,4 @@ public function remove(int $state, string $string): void
2434
unset($this->data[$state]);
2535
}
2636
}
27-
28-
public function all(): array
29-
{
30-
return $this->data;
31-
}
32-
33-
public function getForStates(array $states = []): array
34-
{
35-
return array_intersect_key($this->data, array_flip($states));
36-
}
3737
}

src/DataStore/NullDataStore.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ public function add(int $state, string $string): void
99
// noop
1010
}
1111

12-
public function remove(int $state, string $string): void
12+
public function getForStates(array $states = []): array
1313
{
14-
// noop
14+
return [];
1515
}
1616

17-
public function getForStates(array $states = []): array
17+
public function remove(int $state, string $string): void
1818
{
19-
return [];
19+
// noop
2020
}
2121
}

src/StateSet/InMemoryStateSet.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ public function add(int $state): void
1717
$this->states[$state] = true;
1818
}
1919

20-
public function remove(int $state): void
21-
{
22-
unset($this->states[$state]);
23-
}
24-
2520
public function all(): array
2621
{
2722
return array_keys($this->states);
@@ -31,4 +26,9 @@ public function has(int $state): bool
3126
{
3227
return isset($this->states[$state]);
3328
}
29+
30+
public function remove(int $state): void
31+
{
32+
unset($this->states[$state]);
33+
}
3434
}

src/StateSet/StateSetInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ interface StateSetInterface
66
{
77
public function add(int $state): void;
88

9-
public function remove(int $state): void;
10-
119
/**
1210
* @return array<int>
1311
*/
1412
public function all(): array;
1513

1614
public function has(int $state): bool;
15+
16+
public function remove(int $state): void;
1717
}

src/StateSetIndex.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,6 @@ public function removeFromIndex(array $strings): void
218218
}
219219
}
220220

221-
/**
222-
* Returns true if a state exists that follows the given state
223-
*/
224-
private function hasNextState(int $state): bool
225-
{
226-
for ($c = 1; $c <= $this->config->getAlphabetSize(); ++$c) {
227-
if ($this->stateSet->has($state * $this->config->getAlphabetSize() + $c)) {
228-
return true;
229-
}
230-
}
231-
232-
return false;
233-
}
234-
235221
private function getReachableStates(int $startState, int $editDistance, int $currentDistance = 0): CostAnnotatedStateSet
236222
{
237223
$reachable = new CostAnnotatedStateSet();
@@ -257,6 +243,20 @@ private function getReachableStates(int $startState, int $editDistance, int $cur
257243
return $reachable;
258244
}
259245

246+
/**
247+
* Returns true if a state exists that follows the given state
248+
*/
249+
private function hasNextState(int $state): bool
250+
{
251+
for ($c = 1; $c <= $this->config->getAlphabetSize(); ++$c) {
252+
if ($this->stateSet->has($state * $this->config->getAlphabetSize() + $c)) {
253+
return true;
254+
}
255+
}
256+
257+
return false;
258+
}
259+
260260
/**
261261
* @param \Closure(int) $closure
262262
*/

0 commit comments

Comments
 (0)