anonymous//examples/mispelling_finder_aspell_string_echo.php$0   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 6
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A mispelling_finder_aspell_string_echo.php$0 ➔ process() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
use PhpSpellcheck\MisspellingFinder;
6
use PhpSpellcheck\MisspellingHandler\EchoHandler;
7
use PhpSpellcheck\Spellchecker\Aspell;
8
use PhpSpellcheck\TextInterface;
9
use PhpSpellcheck\TextProcessor\TextProcessorInterface;
10
11
require_once __DIR__ . '/../vendor/autoload.php';
12
13
// My custom text processor that replaces "_" by " "
14
$customTextProcessor = new class () implements TextProcessorInterface {
15
    public function process(TextInterface $text): TextInterface
16
    {
17
        $contentProcessed = str_replace('_', ' ', $text->getContent());
18
19
        return $text->replaceContent($contentProcessed);
20
    }
21
};
22
23
$misspellingFinder = new MisspellingFinder(
24
    Aspell::create(), // Creates aspell spellchecker pointing to "aspell" as it's binary path
25
    new EchoHandler(), // Handles all the misspellings found by echoing their information
26
    $customTextProcessor
27
);
28
29
// using a string
30
$misspellingFinder->find('It\'s_a_mispelling', ['en_US']);
0 ignored issues
show
Bug introduced by
'It's_a_mispelling' of type string 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

30
$misspellingFinder->find(/** @scrutinizer ignore-type */ 'It\'s_a_mispelling', ['en_US']);
Loading history...
31
// word: mispelling | line: 1 | offset: 7 | suggestions: mi spelling,mi-spelling,misspelling | context: []
32