Passed
Push — master ( a93e2d...567501 )
by Philippe
03:03
created

  A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
use PhpSpellcheck\MisspellingFinder;
4
use PhpSpellcheck\MisspellingHandler\EchoHandler;
5
use PhpSpellcheck\Source\SourceInterface;
6
use PhpSpellcheck\Spellchecker\Aspell;
7
use PhpSpellcheck\Text;
8
use PhpSpellcheck\TextInterface;
9
use PhpSpellcheck\TextProcessor\TextProcessorInterface;
10
use PhpSpellcheck\Utils\TextEncoding;
11
12
require_once __DIR__ . '/../vendor/autoload.php';
13
14
// My custom text processor that replaces "_" by " "
15
$customTextProcessor = new class implements TextProcessorInterface
16
{
17
    public function process(TextInterface $text): TextInterface
18
    {
19
        $contentProcessed = str_replace('_', ' ', $text->getContent());
20
21
        return $text->replaceContent($contentProcessed);
22
    }
23
};
24
25
$misspellingFinder = new MisspellingFinder(
26
    Aspell::create(), // Creates aspell spellchecker pointing to "aspell" as it's binary path
27
    new EchoHandler(), // Handles all the misspellings found by echoing their information
28
    $customTextProcessor
29
);
30
31
// Using a custom SourceInterface that generates Text
32
$inMemoryTextProvider = new class implements SourceInterface
33
{
34
    public function toTexts(array $context): iterable
35
    {
36
        yield new Text('my_mispell', TextEncoding::UTF8, ['from_source_interface']);
37
        yield Text::utf8('my_other_mispell', ['from_named_constructor']);
38
    }
39
};
40
41
$misspellingFinder->find($inMemoryTextProvider, ['en_US']);
42
//word: mispell | line: 1 | offset: 3 | suggestions: mi spell,mi-spell,misspell,... | context: ["from_source_interface"]
43
//word: mispell | line: 1 | offset: 9 | suggestions: mi spell,mi-spell,misspell,... | context: ["from_named_constructor"]
44