tigitz /
php-spellchecker
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace PhpSpellcheck\Utils; |
||
| 6 | |||
| 7 | use PhpSpellcheck\Misspelling; |
||
| 8 | |||
| 9 | class IspellOutputParser |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @return Misspelling[] |
||
| 13 | */ |
||
| 14 | 7 | public static function parseMisspellings(string $output, array $context): iterable |
|
| 15 | { |
||
| 16 | 7 | $lines = explode(PHP_EOL, $output); |
|
| 17 | 7 | $lineNumber = 1; |
|
| 18 | 7 | foreach ($lines as $line) { |
|
| 19 | 7 | $line = trim($line); |
|
| 20 | 7 | if ('' === $line) { |
|
| 21 | 7 | $lineNumber++; |
|
| 22 | // Go to the next line |
||
| 23 | 7 | continue; |
|
| 24 | } |
||
| 25 | |||
| 26 | 7 | switch ($line[0]) { |
|
| 27 | 7 | case '#': |
|
| 28 | 1 | list(, $word, $offset) = explode(' ', $line); |
|
| 29 | 1 | yield new Misspelling( |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 30 | 1 | $word, |
|
| 31 | 1 | (int) trim($offset), |
|
| 32 | 1 | $lineNumber, |
|
| 33 | 1 | [], |
|
| 34 | 1 | $context |
|
| 35 | ); |
||
| 36 | 1 | break; |
|
| 37 | 7 | case '&': |
|
| 38 | 7 | $parts = explode(':', $line); |
|
| 39 | 7 | list(, $word, , $offset) = explode(' ', $parts[0]); |
|
| 40 | 7 | yield new Misspelling( |
|
| 41 | 7 | $word, |
|
| 42 | 7 | (int) trim($offset), |
|
| 43 | 7 | $lineNumber, |
|
| 44 | 7 | explode(', ', trim($parts[1])), |
|
| 45 | 7 | $context |
|
| 46 | ); |
||
| 47 | 7 | break; |
|
| 48 | } |
||
| 49 | } |
||
| 50 | 7 | } |
|
| 51 | } |
||
| 52 |