anonymous//examples/mispelling_finder_aspell_source_echo.php$1   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 5
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A mispelling_finder_aspell_source_echo.php$1 ➔ toTexts() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
use PhpSpellcheck\MisspellingFinder;
6
use PhpSpellcheck\MisspellingHandler\EchoHandler;
7
use PhpSpellcheck\Source\SourceInterface;
8
use PhpSpellcheck\Spellchecker\Aspell;
9
use PhpSpellcheck\TextInterface;
10
use PhpSpellcheck\TextProcessor\TextProcessorInterface;
11
12
use function PhpSpellcheck\t;
13
14
require_once __DIR__ . '/../vendor/autoload.php';
15
16
// My custom text processor that replaces "_" by " "
17
$customTextProcessor = new class () implements TextProcessorInterface {
18
    public function process(TextInterface $text): TextInterface
19
    {
20
        $contentProcessed = str_replace('_', ' ', $text->getContent());
21
22
        return $text->replaceContent($contentProcessed);
23
    }
24
};
25
26
$misspellingFinder = new MisspellingFinder(
27
    Aspell::create(), // Creates aspell spellchecker pointing to "aspell" as it's binary path
28
    new EchoHandler(), // Handles all the misspellings found by echoing their information
29
    $customTextProcessor
30
);
31
32
// Using a custom SourceInterface that generates Text
33
$inMemoryTextProvider = new class () implements SourceInterface {
34
    public function toTexts(array $context): iterable
35
    {
36
        yield t('my_mispell', ['from_source_interface']);
37
        yield t('my_other_mispell', ['from_named_constructor']);
38
    }
39
};
40
41
$misspellingFinder->find($inMemoryTextProvider, ['en_US']);
0 ignored issues
show
Bug introduced by
$inMemoryTextProvider of type anonymous//examples/misp...spell_source_echo.php$1 is incompatible with the type iterable expected by parameter $source of PhpSpellcheck\MisspellingFinder::find(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
$misspellingFinder->find(/** @scrutinizer ignore-type */ $inMemoryTextProvider, ['en_US']);
Loading history...
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