Failed Conditions
Push — master ( 01d6ae...9ca6d9 )
by Philippe
534:14 queued 469:10
created

IspellOutputParser::parseMisspellings()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 34
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 26
nc 5
nop 2
dl 0
loc 34
rs 9.1928
c 0
b 0
f 0
ccs 28
cts 28
cp 1
crap 5
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
The expression yield new PhpSpellcheck\...ber, array(), $context) returns the type Generator which is incompatible with the documented return type PhpSpellcheck\Misspelling[].
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