Passed
Pull Request — master (#106)
by Matt
08:38
created

SpellingService::checkString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
namespace App\Service;
4
5
use Mekras\Speller\Source\StringSource;
6
use Mekras\Speller\Aspell\Aspell;
7
8
class SpellingService
9
{
10
    // TODO: Dependency injection
11
    /** @var Aspell */
12
    private $aspell;
13
14
    public function __construct()
15
    {
16
        $this->aspell = new Aspell();
17
    }
18
19
    /**
20
     * Returns simple array of potentially-misspelled words, nothing more for now.
21
     * @param string $input
22
     * @return string[]
23
     */
24
    public function checkString(string $input) : array
25
    {
26
        $misspelledWords = [];
27
        $results =  $this->aspell->checkText(new StringSource($input), ['en_GB', 'en']);
28
        // TODO: Something functional
29
        foreach ($results as $result) {
30
            $misspelledWords[] = $result->word;
31
        }
32
        return $misspelledWords;
33
    }
34
}